Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/11/17 15:55:44 (7 years ago)
Author:
gkronber
Message:

#2697: applied r14390, r14391, r14393, r14394, r14396 again (resolving conflicts)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r14826 r14843  
    7676      var doubleVariables = allowedInputVariables.Where(dataset.VariableHasType<double>);
    7777      var factorVariableNames = allowedInputVariables.Where(dataset.VariableHasType<string>);
    78       var factorVariables = AlglibUtil.GetFactorVariableValues(dataset, factorVariableNames, rows);
    79       double[,] binaryMatrix = AlglibUtil.PrepareInputMatrix(dataset, factorVariables, rows);
    80       double[,] doubleVarMatrix = AlglibUtil.PrepareInputMatrix(dataset, doubleVariables.Concat(new string[] { targetVariable }), rows);
     78      var factorVariables = dataset.GetFactorVariableValues(factorVariableNames, rows);
     79      double[,] binaryMatrix = dataset.ToArray(factorVariables, rows);
     80      double[,] doubleVarMatrix = dataset.ToArray(doubleVariables.Concat(new string[] { targetVariable }), rows);
    8181      var inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix);
    8282
     
    9898      alglib.lrunpack(lm, out coefficients, out nFeatures);
    9999
    100       ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode());
    101       ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode();
    102       tree.Root.AddSubtree(startNode);
    103       ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode();
    104       startNode.AddSubtree(addition);
    105 
    106       int col = 0;
    107       foreach (var kvp in factorVariables) {
    108         var varName = kvp.Key;
    109         foreach (var cat in kvp.Value) {
    110           BinaryFactorVariableTreeNode vNode =
    111             (BinaryFactorVariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.BinaryFactorVariable().CreateTreeNode();
    112           vNode.VariableName = varName;
    113           vNode.VariableValue = cat;
    114           vNode.Weight = coefficients[col];
    115           addition.AddSubtree(vNode);
    116           col++;
    117         }
    118       }
    119       foreach (string column in doubleVariables) {
    120         VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode();
    121         vNode.VariableName = column;
    122         vNode.Weight = coefficients[col];
    123         addition.AddSubtree(vNode);
    124         col++;
    125       }
    126 
    127       ConstantTreeNode cNode = (ConstantTreeNode)new Constant().CreateTreeNode();
    128       cNode.Value = coefficients[coefficients.Length - 1];
    129       addition.AddSubtree(cNode);
    130 
     100      int nFactorCoeff = binaryMatrix.GetLength(1);
     101      int nVarCoeff = doubleVariables.Count();
     102      var tree = LinearModelToTreeConverter.CreateTree(factorVariables, coefficients.Take(nFactorCoeff).ToArray(),
     103        doubleVariables.ToArray(), coefficients.Skip(nFactorCoeff).Take(nVarCoeff).ToArray(),
     104        @const: coefficients[nFeatures]);
     105     
    131106      SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter()), (IRegressionProblemData)problemData.Clone());
    132107      solution.Model.Name = "Linear Regression Model";
Note: See TracChangeset for help on using the changeset viewer.