Ignore:
Timestamp:
05/30/20 22:00:12 (2 years ago)
Author:
mkommend
Message:

#2971: Merged branch into trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17180 r17579  
    1 #region License Information
     1#region License Information
    22/* HeuristicLab
    33 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    2728using HeuristicLab.Data;
    2829using HeuristicLab.Parameters;
    29 using HEAL.Attic;
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis {
     
    3434  public class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData, IStorableContent {
    3535    protected const string TargetVariableParameterName = "TargetVariable";
     36    protected const string VariableRangesParameterName = "VariableRanges";
     37    protected const string IntervalConstraintsParameterName = "IntervalConstraints";
    3638    public string Filename { get; set; }
    3739
     
    9193      problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly()));
    9294      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
     95      problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection()));
    9396      emptyProblemData = problemData;
    9497    }
     
    98101      get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; }
    99102    }
     103
     104    public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName];
     105
     106    public IntervalCollection VariableRanges {
     107      get => VariableRangesParameter.Value;
     108    }
     109
     110
    100111    public string TargetVariable {
    101112      get { return TargetVariableParameter.Value.Value; }
     
    125136    [StorableHook(HookType.AfterDeserialization)]
    126137    private void AfterDeserialization() {
     138      if (!Parameters.ContainsKey(VariableRangesParameterName)) {
     139        var intervalCollection = CalculateDatasetIntervals(this.Dataset);
     140        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
     141      }
    127142      RegisterParameterEvents();
    128143    }
     
    152167      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
    153168      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
     169      var intervalCollection = CalculateDatasetIntervals(this.Dataset);
     170      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    154171      RegisterParameterEvents();
     172    }
     173
     174    private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {
     175      IntervalCollection intervalCollection = new IntervalCollection();
     176      foreach (var variable in dataset.DoubleVariables) {// intervals are only possible for double variables
     177        var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
     178        intervalCollection.AddInterval(variable, variableInterval);
     179      }
     180
     181      return intervalCollection;
    155182    }
    156183
Note: See TracChangeset for help on using the changeset viewer.