Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/17/16 15:41:33 (8 years ago)
Author:
gkronber
Message:

#2697: reverse merge of r14378, r14390, r14391, r14393, r14394, r14396

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  
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Linq;
    2523
    2624namespace HeuristicLab.Problems.DataAnalysis {
    2725  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++;
    5131      }
    52 
    53       return matrix;
    5432    }
    5533  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r14396 r14400  
    7373    }
    7474
    75     public double[,] AllowedInputsTrainingValues {
    76       get { return Dataset.ToArray(AllowedInputVariables, TrainingIndices); }
    77     }
    78 
    79     public double[,] AllowedInputsTestValues { get { return Dataset.ToArray(AllowedInputVariables, TestIndices); } }
    8075    public IntRange TrainingPartition {
    8176      get { return TrainingPartitionParameter.Value; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/LinearTransformation.cs

    r14393 r14400  
    5252    public double Multiplier {
    5353      get { return MultiplierParameter.Value.Value; }
    54       set {
     54      protected set {
    5555        MultiplierParameter.Value.Value = value;
    5656      }
     
    5959    public double Addend {
    6060      get { return AddendParameter.Value.Value; }
    61       set {
     61      protected set {
    6262        AddendParameter.Value.Value = value;
    6363      }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftStandardDistributionTransformation.cs

    r14393 r14400  
    7171
    7272    public override IEnumerable<double> Apply(IEnumerable<double> data) {
     73      ConfigureParameters(data);
    7374      if (OriginalStandardDeviation.IsAlmost(0.0)) {
    7475        return data;
     
    9394    }
    9495
    95     public override void ConfigureParameters(IEnumerable<double> data) {
     96    protected void ConfigureParameters(IEnumerable<double> data) {
    9697      OriginalStandardDeviation = data.StandardDeviation();
    9798      OriginalMean = data.Average();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftToRangeTransformation.cs

    r14393 r14400  
    4444    }
    4545
     46    public override IEnumerable<double> Apply(IEnumerable<double> data) {
     47      ConfigureParameters(data);
     48      return base.Apply(data);
     49    }
     50
    4651    public override bool Check(IEnumerable<double> data, out string errorMsg) {
    4752      ConfigureParameters(data);
     
    4954    }
    5055
    51     public override void ConfigureParameters(IEnumerable<double> data) {
     56    protected void ConfigureParameters(IEnumerable<double> data) {
    5257      double originalRangeStart = data.Min();
    5358      double originalRangeEnd = data.Max();
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs

    r14393 r14400  
    6666    protected Transformation(IEnumerable<string> allowedColumns) : base(allowedColumns) { }
    6767
    68     public virtual void ConfigureParameters(IEnumerable<T> data) {
    69       // override in transformations with parameters
    70     }
    71 
    7268    public abstract IEnumerable<T> Apply(IEnumerable<T> data);
    73     public IEnumerable<T> ConfigureAndApply(IEnumerable<T> data) {
    74       ConfigureParameters(data);
    75       return Apply(data);
    76     }
    7769
    7870    public abstract bool Check(IEnumerable<T> data, out string errorMsg);
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs

    r14396 r14400  
    3333    IEnumerable<string> AllowedInputVariables { get; }
    3434
    35     double[,] AllowedInputsTrainingValues { get; }
    36     double[,] AllowedInputsTestValues { get; }
    37 
    3835    IntRange TrainingPartition { get; }
    3936    IntRange TestPartition { get; }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/ITransformation.cs

    r14393 r14400  
    3030
    3131  public interface ITransformation<T> : ITransformation {
    32     void ConfigureParameters(IEnumerable<T> data);
    33     IEnumerable<T> ConfigureAndApply(IEnumerable<T> data);
    3432    IEnumerable<T> Apply(IEnumerable<T> data);
    3533  }
Note: See TracChangeset for help on using the changeset viewer.