- Timestamp:
- 11/17/16 15:41:33 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs
r14393 r14400 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.Linq;25 23 26 24 namespace HeuristicLab.Problems.DataAnalysis { 27 25 public static class DatasetExtensions { 28 public static double[,] ToArray(this IDataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) { 29 return ToArray(dataset, 30 variables, 31 transformations: variables.Select(_ => (ITransformation<double>)null), // no transform 32 rows: rows); 33 } 34 public static double[,] ToArray(this IDataset dataset, IEnumerable<string> variables, IEnumerable<ITransformation<double>> transformations, IEnumerable<int> rows) { 35 string[] variablesArr = variables.ToArray(); 36 int[] rowsArr = rows.ToArray(); 37 ITransformation<double>[] transformArr = transformations.ToArray(); 38 if (transformArr.Length != variablesArr.Length) 39 throw new ArgumentException("Number of variables and number of transformations must match."); 40 41 double[,] matrix = new double[rowsArr.Length, variablesArr.Length]; 42 43 for (int i = 0; i < variablesArr.Length; i++) { 44 var origValues = dataset.GetDoubleValues(variablesArr[i], rowsArr); 45 var values = transformArr[i] != null ? transformArr[i].Apply(origValues) : origValues; 46 int row = 0; 47 foreach (var value in values) { 48 matrix[row, i] = value; 49 row++; 50 } 26 public static IEnumerable<T> TakeEvery<T>(this IEnumerable<T> xs, int nth) { 27 int i = 0; 28 foreach (var x in xs) { 29 if (i % nth == 0) yield return x; 30 i++; 51 31 } 52 53 return matrix;54 32 } 55 33 }
Note: See TracChangeset
for help on using the changeset viewer.