Changeset 5658 for branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans
- Timestamp:
- 03/10/11 12:38:43 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClustering.cs
r5651 r5658 94 94 double[,] centers; 95 95 int[] xyc; 96 double[,] inputMatrix = KMeansClusteringUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);96 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); 97 97 alglib.kmeansgenerate(inputMatrix, inputMatrix.GetLength(0), inputMatrix.GetLength(1), k, restarts + 1, out info, out centers, out xyc); 98 98 if (info != 1) throw new ArgumentException("Error in calculation of k-Means clustering solution"); -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs
r5651 r5658 64 64 public KMeansClusteringModel(double[,] centers, IEnumerable<string> allowedInputVariables) 65 65 : base() { 66 this.name = ItemName; 67 this.description = ItemDescription; 66 68 // disect center matrix into list of double[] 67 69 // centers are given as double matrix where number of rows = dimensions and number of columns = clusters -
branches/DataAnalysis Refactoring/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringUtil.cs
r5651 r5658 27 27 namespace HeuristicLab.Algorithms.DataAnalysis { 28 28 public static class KMeansClusteringUtil { 29 public static double[,] PrepareInputMatrix(Dataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<int> rows) {30 List<int> allowedRows = CalculateAllowedRows(dataset, allowedInputVariables, rows).ToList();31 32 double[,] matrix = new double[allowedRows.Count, allowedInputVariables.Count()];33 for (int row = 0; row < allowedRows.Count; row++) {34 int col = 0;35 foreach (string column in allowedInputVariables) {36 matrix[row, col] = dataset[column, row];37 col++;38 }39 }40 return matrix;41 }42 43 private static IEnumerable<int> CalculateAllowedRows(Dataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<int> rows) {44 // return only rows that contain no infinity or NaN values45 return from row in rows46 where (from inputVariable in allowedInputVariables47 let x = dataset[inputVariable, row]48 where double.IsInfinity(x) || double.IsNaN(x)49 select 1)50 .Any() == false51 select row;52 }53 54 29 public static IEnumerable<int> FindClosestCenters(IEnumerable<double[]> centers, Dataset dataset, IEnumerable<string> allowedInputVariables, IEnumerable<int> rows) { 55 30 int nRows = rows.Count();
Note: See TracChangeset
for help on using the changeset viewer.