Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/12/21 14:00:36 (4 years ago)
Author:
gkronber
Message:

#3073: intermediate comment while refactoring the branch

Location:
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4
Files:
3 added
3 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17768 r17887  
    190190    <Compile Include="Implementation\Interval\Interval.cs" />
    191191    <Compile Include="Implementation\Interval\IntervalCollection.cs" />
    192     <Compile Include="Implementation\Interval\IntervalConstraint.cs" />
    193     <Compile Include="Implementation\Interval\IntervalConstraintsParser.cs" />
     192    <Compile Include="Implementation\Interval\ShapeConstraint.cs" />
     193    <Compile Include="Implementation\Interval\ShapeConstraintsParser.cs" />
    194194    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
    195195    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
    196196    <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" />
     197    <Compile Include="Implementation\Regression\ShapeConstraints.cs" />
    197198    <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" />
    198199    <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs">
     
    306307    <Compile Include="Interfaces\IDataAnalysisModel.cs" />
    307308    <Compile Include="Interfaces\IDataAnalysisProblem.cs" />
    308     <Compile Include="ProblemDataConstraint.cs" />
    309309    <Compile Include="Properties\AssemblyInfo.cs" />
    310310  </ItemGroup>
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17770 r17887  
    2525using HEAL.Attic;
    2626using HeuristicLab.Common;
     27using HeuristicLab.Core;
    2728
    2829namespace HeuristicLab.Problems.DataAnalysis {
     
    8081 
    8182      return false;
    82     }
    83 
    84     public Tuple<Interval, Interval> Split() {
    85       var midpoint = Width / 2;
    86       var left     = new Interval(LowerBound, LowerBound + midpoint - double.Epsilon);
    87       var right    = new Interval(LowerBound + midpoint, UpperBound);
    88       return Tuple.Create(left, right);
    89     }
    90 
    91     //Interval Intersection
    92     public static Interval operator &(Interval lhs, Interval rhs) {
    93       return new Interval(Math.Max(lhs.LowerBound, rhs.LowerBound), Math.Min(lhs.UpperBound, rhs.UpperBound));
    94     }
    95 
    96     //Interval Union
    97     public static Interval operator |(Interval lhs, Interval rhs) {
    98       return new Interval(Math.Min(lhs.LowerBound, rhs.LowerBound), Math.Max(lhs.UpperBound, rhs.UpperBound));
    9983    }
    10084
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs

    r17631 r17887  
    3434      get => HeuristicLab.Common.Resources.VSImageLibrary.Object;
    3535    }
    36     private IDictionary<string, Interval> intervals { get; } = new Dictionary<string, Interval>();
    3736
    38     [Storable(Name = "StorableIntervalInformation")]
     37    //[Storable]
     38    private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>();
     39
     40    [Storable(OldName = "StorableIntervalInformation")]
    3941    private KeyValuePair<string, double[]>[] StorableIntervalInformation {
     42      set {
     43        foreach (var varInt in value)
     44          intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
     45      }
     46    }
     47
     48    [Storable]
     49    private object[] StorableIntervals {
    4050      get {
    41         var l = new List<KeyValuePair<string, double[]>>();
    42         foreach (var varInt in intervals)
     51        var names = intervals.Keys.ToArray();
     52        var lowerBounds = intervals.Values.Select(i => i.LowerBound).ToArray();
     53        var upperBounds = intervals.Values.Select(i => i.UpperBound).ToArray();
    4354
    44           l.Add(new KeyValuePair<string, double[]>(varInt.Key,
    45             new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound }));
    46         return l.ToArray();
     55        return new object[] { names, lowerBounds, upperBounds };
    4756      }
    4857
    4958      set {
    50         foreach (var varInt in value)
    51           intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1]));
     59        var names = (string[])value[0];
     60        var lowerBounds = (double[])value[1];
     61        var upperBounds = (double[])value[2];
     62
     63        for (int i = 0; i < names.Length; i++) {
     64          intervals.Add(names[i], new Interval(lowerBounds[i], upperBounds[i]));
     65        }
    5266      }
    5367    }
     
    8094    public void SetInterval(string identifier, Interval interval) {
    8195      intervals[identifier] = interval;
     96      RaiseChanged();
    8297    }
    8398
    8499    public void AddInterval(string identifier, Interval interval) {
    85100      intervals.Add(identifier, interval);
     101      RaiseChanged();
    86102    }
    87103
    88104    public void DeleteInterval(string identifier) {
    89105      intervals.Remove(identifier);
     106      RaiseChanged();
    90107    }
    91108
     
    102119        yield return Tuple.Create(variableInterval.Key, variableInterval.Value);
    103120    }
     121
     122    public event EventHandler Changed;
     123    private void RaiseChanged() {
     124      OnChanged();
     125      var handler = Changed;
     126      if (handler != null)
     127        handler(this, EventArgs.Empty);
     128    }
     129
     130    protected virtual void OnChanged() {  }
    104131  }
    105132}
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17607 r17887  
    9494      problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>()));
    9595      problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection()));
    96       problemData.Parameters.Add(new FixedValueParameter<ProblemDataConstraint>(IntervalConstraintsParameterName, "", new ProblemDataConstraint(problemData)));
     96      problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(IntervalConstraintsParameterName, "", new ShapeConstraints()));
    9797      emptyProblemData = problemData;
    9898    }
     
    109109    }
    110110
    111     public IFixedValueParameter<ProblemDataConstraint> IntervalConstraintsParameter =>
    112       (IFixedValueParameter<ProblemDataConstraint>) Parameters[IntervalConstraintsParameterName];
    113 
    114     public ProblemDataConstraint IntervalConstraints => IntervalConstraintsParameter.Value;
     111    public IFixedValueParameter<ShapeConstraints> IntervalConstraintsParameter =>
     112      (IFixedValueParameter<ShapeConstraints>) Parameters[IntervalConstraintsParameterName];
     113
     114    public ShapeConstraints IntervalConstraints => IntervalConstraintsParameter.Value;
    115115
    116116
     
    148148
    149149      if (!Parameters.ContainsKey(IntervalConstraintsParameterName)) {
    150         Parameters.Add(new FixedValueParameter<ProblemDataConstraint>(IntervalConstraintsParameterName, new ProblemDataConstraint(this)));
     150        Parameters.Add(new FixedValueParameter<ShapeConstraints>(IntervalConstraintsParameterName, new ShapeConstraints()));
    151151      }
    152152      RegisterParameterEvents();
     
    173173    }
    174174
    175     public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)
     175    public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
     176      IEnumerable<ITransformation> transformations = null,
     177      IntervalCollection variableRanges = null,
     178      ShapeConstraints intervalConstraints = null)
    176179      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    177180      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
    178181      Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First()));
    179       var intervalCollection = CalculateDatasetIntervals(this.Dataset);
    180       Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    181       Parameters.Add(new FixedValueParameter<ProblemDataConstraint>(IntervalConstraintsParameterName, new ProblemDataConstraint(this)));
     182      if (variableRanges == null) {
     183        variableRanges = CalculateDatasetIntervals(this.Dataset);
     184      }
     185      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
     186      if (intervalConstraints == null) {
     187        intervalConstraints = new ShapeConstraints();
     188      }
     189      Parameters.Add(new FixedValueParameter<ShapeConstraints>(IntervalConstraintsParameterName, intervalConstraints));
    182190      RegisterParameterEvents();
    183191    }
     
    185193    private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {
    186194      IntervalCollection intervalCollection = new IntervalCollection();
    187       foreach (var variable in dataset.DoubleVariables) {// intervals are only possible for double variables
     195      foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables
    188196        var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
    189197        intervalCollection.AddInterval(variable, variableInterval);
  • branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r17607 r17887  
    3030    string TargetVariable { get; set; }
    3131
    32     IntervalCollection    VariableRanges      { get; }
    33     ProblemDataConstraint IntervalConstraints { get; }
     32    IntervalCollection VariableRanges { get; }
     33    ShapeConstraints IntervalConstraints { get; }
    3434
    35     IEnumerable<double> TargetVariableValues         { get; }
     35    IEnumerable<double> TargetVariableValues { get; }
    3636    IEnumerable<double> TargetVariableTrainingValues { get; }
    37     IEnumerable<double> TargetVariableTestValues     { get; }
     37    IEnumerable<double> TargetVariableTestValues { get; }
    3838  }
    3939}
Note: See TracChangeset for help on using the changeset viewer.