- Timestamp:
- 04/11/11 18:41:03 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/AlglibUtil.cs
r5809 r6002 27 27 public static class AlglibUtil { 28 28 public static double[,] PrepareInputMatrix(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) { 29 List<int> allowedRows = CalculateAllowedRows(dataset, variables, rows).ToList(); 29 List<string> variablesList = variables.ToList(); 30 List<int> rowsList = rows.ToList(); 30 31 31 double[,] matrix = new double[ allowedRows.Count, variables.Count()];32 for (int row = 0; row < allowedRows.Count; row++) {32 double[,] matrix = new double[rowsList.Count, variablesList.Count]; 33 for (int row = 0; row < rowsList.Count; row++) { 33 34 int col = 0; 34 35 foreach (string column in variables) { 35 matrix[row, col] = dataset[column, row ];36 matrix[row, col] = dataset[column, rowsList[row]]; 36 37 col++; 37 38 } … … 39 40 return matrix; 40 41 } 41 42 private static IEnumerable<int> CalculateAllowedRows(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) {43 // return only rows that contain no infinity or NaN values44 return from row in rows45 where (from variable in variables46 let x = dataset[variable, row]47 where double.IsInfinity(x) || double.IsNaN(x)48 select 1)49 .Any() == false50 select row;51 }52 42 } 53 43 } -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r5809 r6002 73 73 int nClasses = problemData.ClassNames.Count(); 74 74 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows); 75 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 76 throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset."); 75 77 76 78 // change class values into class index -
trunk/sources/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r5809 r6002 76 76 IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart); 77 77 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows); 78 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 79 throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset."); 78 80 79 81 alglib.linearmodel lm = new alglib.linearmodel();
Note: See TracChangeset
for help on using the changeset viewer.