Changeset 17391


Ignore:
Timestamp:
12/20/19 14:00:09 (12 months ago)
Author:
djoedick
Message:

#3044: Added transformation of input variables to problem data and created scaled dataset.

Location:
branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17388 r17391  
    170170    private void RegisterParameterEvents() {
    171171      TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged);
     172      ScaleInputsParameter.Value.ValueChanged += new EventHandler(ScaleInputsParameter_ValueChanged);
    172173    }
    173174    private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) {
    174175      OnChanged();
    175176    }
     177
     178    private void ScaleInputsParameter_ValueChanged(object sender, EventArgs e) {
     179      var transformations = new ShiftStandardDistributionTransformation(Dataset.DoubleVariables);
     180      transformations.Mean = 0;
     181      transformations.StandardDeviation = 1;
     182      var scaling = Transformation.CreateTransformations(transformations, Dataset, TrainingIndices, AllowedInputVariables);
     183
     184      var scaledVariables = AllowedInputVariables.Select((var, i) => new { Variable = var, Data = scaling[i].Apply(Dataset.GetDoubleValues(var)).ToArray() });
     185      var newDataset = ((Dataset)Dataset).ToModifiable();
     186
     187      foreach (var v in scaledVariables) {
     188        newDataset.ReplaceVariable(v.Variable, v.Data);
     189      }
     190
     191      if (!Parameters.ContainsKey("Scaled Dataset"))
     192        Parameters.Add(new FixedValueParameter<Dataset>("Scaled Dataset", newDataset.ToDataset()));
     193    }
    176194  }
    177195}
  • branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/ShiftStandardDistributionTransformation.cs

    r16565 r17391  
    4545    public double Mean {
    4646      get { return MeanParameter.Value.Value; }
     47      set { MeanParameter.Value.Value = value; }
    4748    }
    4849    public double StandardDeviation {
    4950      get { return StandardDeviationParameter.Value.Value; }
     51      set { StandardDeviationParameter.Value.Value = value; }
    5052    }
    5153    #endregion
  • branches/3044_variableScaling/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Transformations/Transformation.cs

    r17390 r17391  
    7474    /// <param name="allowedInputVariables"></param>
    7575    /// <returns></returns>
    76     public static ITransformation<double>[] CreateTransformations(ITransformation<double> transformation, IDataset dataset, int[] rows, IReadOnlyCollection<string> allowedInputVariables) {
    77       var trans = new ITransformation<double>[allowedInputVariables.Count];
     76    public static ITransformation<double>[] CreateTransformations(ITransformation<double> transformation, IDataset dataset, IEnumerable<int> rows, IEnumerable<string> allowedInputVariables) {
     77      var trans = new ITransformation<double>[allowedInputVariables.Count()];
    7878      int i = 0;
    7979      foreach (var variable in allowedInputVariables) {
Note: See TracChangeset for help on using the changeset viewer.