Changeset 15142 for stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear
- Timestamp:
- 07/06/17 11:12:18 (7 years ago)
- Location:
- stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r15131 r15142 73 73 var doubleVariableNames = allowedInputVariables.Where(dataset.VariableHasType<double>).ToArray(); 74 74 var factorVariableNames = allowedInputVariables.Where(dataset.VariableHasType<string>).ToArray(); 75 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset,doubleVariableNames.Concat(new string[] { targetVariable }), rows);75 double[,] inputMatrix = dataset.ToArray(doubleVariableNames.Concat(new string[] { targetVariable }), rows); 76 76 77 var factorVariables = AlglibUtil.GetFactorVariableValues(dataset,factorVariableNames, rows);78 double[,] factorMatrix = AlglibUtil.PrepareInputMatrix(dataset,factorVariables, rows);77 var factorVariables = dataset.GetFactorVariableValues(factorVariableNames, rows); 78 var factorMatrix = dataset.ToArray(factorVariables, rows); 79 79 80 80 inputMatrix = factorMatrix.HorzCat(inputMatrix); … … 94 94 if (info < 1) throw new ArgumentException("Error in calculation of linear discriminant analysis solution"); 95 95 96 ISymbolicExpressionTree tree = new SymbolicExpressionTree(new ProgramRootSymbol().CreateTreeNode()); 97 ISymbolicExpressionTreeNode startNode = new StartSymbol().CreateTreeNode(); 98 tree.Root.AddSubtree(startNode); 99 ISymbolicExpressionTreeNode addition = new Addition().CreateTreeNode(); 100 startNode.AddSubtree(addition); 101 102 int col = 0; 103 foreach (var kvp in factorVariables) { 104 var varName = kvp.Key; 105 foreach (var cat in kvp.Value) { 106 BinaryFactorVariableTreeNode vNode = 107 (BinaryFactorVariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.BinaryFactorVariable().CreateTreeNode(); 108 vNode.VariableName = varName; 109 vNode.VariableValue = cat; 110 vNode.Weight = w[col]; 111 addition.AddSubtree(vNode); 112 col++; 113 } 114 } 115 foreach (string column in doubleVariableNames) { 116 VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode(); 117 vNode.VariableName = column; 118 vNode.Weight = w[col]; 119 addition.AddSubtree(vNode); 120 col++; 121 } 96 var nFactorCoeff = factorMatrix.GetLength(1); 97 var tree = LinearModelToTreeConverter.CreateTree(factorVariables, w.Take(nFactorCoeff).ToArray(), 98 doubleVariableNames, w.Skip(nFactorCoeff).Take(doubleVariableNames.Length).ToArray()); 122 99 123 100 var model = CreateDiscriminantFunctionModel(tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), problemData, rows); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r15131 r15142 76 76 var doubleVariables = allowedInputVariables.Where(dataset.VariableHasType<double>); 77 77 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); 81 81 var inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix); 82 82 … … 98 98 alglib.lrunpack(lm, out coefficients, out nFeatures); 99 99 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 131 106 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter()), (IRegressionProblemData)problemData.Clone()); 132 107 solution.Model.Name = "Linear Regression Model"; -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs
r15131 r15142 72 72 var factorVariableNames = problemData.AllowedInputVariables.Where(dataset.VariableHasType<string>); 73 73 IEnumerable<int> rows = problemData.TrainingIndices; 74 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset,doubleVariableNames.Concat(new string[] { targetVariable }), rows);74 double[,] inputMatrix = dataset.ToArray(doubleVariableNames.Concat(new string[] { targetVariable }), rows); 75 75 76 var factorVariableValues = AlglibUtil.GetFactorVariableValues(dataset,factorVariableNames, rows);77 var factorMatrix = AlglibUtil.PrepareInputMatrix(dataset,factorVariableValues, rows);76 var factorVariableValues = dataset.GetFactorVariableValues(factorVariableNames, rows); 77 var factorMatrix = dataset.ToArray(factorVariableValues, rows); 78 78 inputMatrix = factorMatrix.HorzCat(inputMatrix); 79 79 -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitModel.cs
r15131 r15142 97 97 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 98 98 99 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset,allowedInputVariables, rows);100 double[,] factorData = AlglibUtil.PrepareInputMatrix(dataset,factorVariables, rows);99 double[,] inputData = dataset.ToArray(allowedInputVariables, rows); 100 double[,] factorData = dataset.ToArray(factorVariables, rows); 101 101 102 102 inputData = factorData.HorzCat(inputData); -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/Scaling.cs
r14186 r15142 29 29 30 30 namespace HeuristicLab.Algorithms.DataAnalysis { 31 [Obsolete("Use transformation classes in Problems.DataAnalysis instead")] 31 32 [StorableClass] 32 33 [Item(Name = "Scaling", Description = "Contains information about scaling of variables for data-analysis algorithms.")]
Note: See TracChangeset
for help on using the changeset viewer.