Changeset 14400 for trunk/sources/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 11/17/16 15:41:33 (8 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 8 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 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r14396 r14400 73 73 } 74 74 75 public double[,] AllowedInputsTrainingValues {76 get { return Dataset.ToArray(AllowedInputVariables, TrainingIndices); }77 }78 79 public double[,] AllowedInputsTestValues { get { return Dataset.ToArray(AllowedInputVariables, TestIndices); } }80 75 public IntRange TrainingPartition { 81 76 get { return TrainingPartitionParameter.Value; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs
r14393 r14400 52 52 public double Multiplier { 53 53 get { return MultiplierParameter.Value.Value; } 54 set {54 protected set { 55 55 MultiplierParameter.Value.Value = value; 56 56 } … … 59 59 public double Addend { 60 60 get { return AddendParameter.Value.Value; } 61 set {61 protected set { 62 62 AddendParameter.Value.Value = value; 63 63 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftStandardDistributionTransformation.cs
r14393 r14400 71 71 72 72 public override IEnumerable<double> Apply(IEnumerable<double> data) { 73 ConfigureParameters(data); 73 74 if (OriginalStandardDeviation.IsAlmost(0.0)) { 74 75 return data; … … 93 94 } 94 95 95 p ublic overridevoid ConfigureParameters(IEnumerable<double> data) {96 protected void ConfigureParameters(IEnumerable<double> data) { 96 97 OriginalStandardDeviation = data.StandardDeviation(); 97 98 OriginalMean = data.Average(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftToRangeTransformation.cs
r14393 r14400 44 44 } 45 45 46 public override IEnumerable<double> Apply(IEnumerable<double> data) { 47 ConfigureParameters(data); 48 return base.Apply(data); 49 } 50 46 51 public override bool Check(IEnumerable<double> data, out string errorMsg) { 47 52 ConfigureParameters(data); … … 49 54 } 50 55 51 p ublic overridevoid ConfigureParameters(IEnumerable<double> data) {56 protected void ConfigureParameters(IEnumerable<double> data) { 52 57 double originalRangeStart = data.Min(); 53 58 double originalRangeEnd = data.Max(); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs
r14393 r14400 66 66 protected Transformation(IEnumerable<string> allowedColumns) : base(allowedColumns) { } 67 67 68 public virtual void ConfigureParameters(IEnumerable<T> data) {69 // override in transformations with parameters70 }71 72 68 public abstract IEnumerable<T> Apply(IEnumerable<T> data); 73 public IEnumerable<T> ConfigureAndApply(IEnumerable<T> data) {74 ConfigureParameters(data);75 return Apply(data);76 }77 69 78 70 public abstract bool Check(IEnumerable<T> data, out string errorMsg); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r14396 r14400 33 33 IEnumerable<string> AllowedInputVariables { get; } 34 34 35 double[,] AllowedInputsTrainingValues { get; }36 double[,] AllowedInputsTestValues { get; }37 38 35 IntRange TrainingPartition { get; } 39 36 IntRange TestPartition { get; } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/ITransformation.cs
r14393 r14400 30 30 31 31 public interface ITransformation<T> : ITransformation { 32 void ConfigureParameters(IEnumerable<T> data);33 IEnumerable<T> ConfigureAndApply(IEnumerable<T> data);34 32 IEnumerable<T> Apply(IEnumerable<T> data); 35 33 }
Note: See TracChangeset
for help on using the changeset viewer.