Changeset 15131 for stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
- Timestamp:
- 07/06/17 10:19:37 (7 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r15061 r15131 37 37 /// Linear discriminant analysis classification algorithm. 38 38 /// </summary> 39 [Item("Linear Discriminant Analysis ", "Linear discriminant analysis classification algorithm (wrapper for ALGLIB).")]39 [Item("Linear Discriminant Analysis (LDA)", "Linear discriminant analysis classification algorithm (wrapper for ALGLIB).")] 40 40 [Creatable(CreatableAttribute.Categories.DataAnalysisClassification, Priority = 100)] 41 41 [StorableClass] … … 71 71 IEnumerable<int> rows = problemData.TrainingIndices; 72 72 int nClasses = problemData.ClassNames.Count(); 73 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows); 73 var doubleVariableNames = allowedInputVariables.Where(dataset.VariableHasType<double>).ToArray(); 74 var factorVariableNames = allowedInputVariables.Where(dataset.VariableHasType<string>).ToArray(); 75 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, doubleVariableNames.Concat(new string[] { targetVariable }), rows); 76 77 var factorVariables = AlglibUtil.GetFactorVariableValues(dataset, factorVariableNames, rows); 78 double[,] factorMatrix = AlglibUtil.PrepareInputMatrix(dataset, factorVariables, rows); 79 80 inputMatrix = factorMatrix.HorzCat(inputMatrix); 81 74 82 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 75 83 throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset."); … … 83 91 int info; 84 92 double[] w; 85 alglib.fisherlda(inputMatrix, inputMatrix.GetLength(0), allowedInputVariables.Count(), nClasses, out info, out w);93 alglib.fisherlda(inputMatrix, inputMatrix.GetLength(0), inputMatrix.GetLength(1) - 1, nClasses, out info, out w); 86 94 if (info < 1) throw new ArgumentException("Error in calculation of linear discriminant analysis solution"); 87 95 … … 93 101 94 102 int col = 0; 95 foreach (string column in allowedInputVariables) { 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) { 96 116 VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode(); 97 117 vNode.VariableName = column;
Note: See TracChangeset
for help on using the changeset viewer.