Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/21 14:23:41 (4 years ago)
Author:
gkronber
Message:

#3073 merged reintegration branch to trunk

Location:
trunk/HeuristicLab.Problems.DataAnalysis
Files:
7 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis

  • trunk/HeuristicLab.Problems.DataAnalysis/3.4

  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17579 r17902  
    142142    <Compile Include="Implementation\Interval\Interval.cs" />
    143143    <Compile Include="Implementation\Interval\IntervalCollection.cs" />
     144    <Compile Include="Implementation\Interval\ShapeConstraint.cs" />
     145    <Compile Include="Implementation\Interval\ShapeConstraintsParser.cs" />
    144146    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
    145147    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
    146148    <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" />
     149    <Compile Include="Implementation\Regression\ShapeConstraints.cs" />
    147150    <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" />
    148151    <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs">
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17583 r17902  
    3333    [Storable]
    3434    public double UpperBound { get; private set; }
     35
     36    public double Width => UpperBound - LowerBound;
    3537
    3638    [StorableConstructor]
     
    6769    }
    6870
     71    private Interval(double v) : this(v, v) { }
     72
    6973    public bool Contains(double value) {
    7074      return LowerBound <= value && value <= UpperBound;
     
    126130        return false;
    127131
    128       return (UpperBound.IsAlmost(other.UpperBound) || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))
    129         && (LowerBound.IsAlmost(other.LowerBound) || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound)));
     132      return (UpperBound==other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))
     133        && (LowerBound==other.LowerBound || (double.IsNaN(LowerBound) && double.IsNaN(other.LowerBound)));
    130134    }
    131135
     
    276280    }
    277281    #endregion
     282
     283    #region arithmetic overloads
     284    public static Interval operator +(Interval a, Interval b) => Add(a, b);
     285    public static Interval operator +(Interval a, double b) => Add(a, new Interval(b));
     286    public static Interval operator +(double a, Interval b) => Add(new Interval(a), b);
     287    public static Interval operator -(Interval a, Interval b) => Subtract(a, b);
     288    public static Interval operator -(Interval a, double b) => Subtract(a, new Interval(b));
     289    public static Interval operator -(double a, Interval b) => Subtract(new Interval(a), b);
     290    public static Interval operator -(Interval a) => Subtract(new Interval(0), a);
     291    public static Interval operator *(Interval a, Interval b) => Multiply(a, b);
     292    public static Interval operator *(Interval a, double b) => Multiply(a, new Interval(b));
     293    public static Interval operator *(double a, Interval b) => Multiply(new Interval(a), b);
     294    public static Interval operator /(Interval a, Interval b) => Divide(a, b);
     295    public static Interval operator /(Interval a, double b) => Divide(a, new Interval(b));
     296    public static Interval operator /(double a, Interval b) => Divide(new Interval(a), b);
     297    public static Interval Exponential(double a) { return Exponential(new Interval(a)); }
     298    public static Interval Logarithm(double a) { return Logarithm(new Interval(a)); }
     299    public static Interval Sine(double a) { return Sine(new Interval(a)); }
     300    public static Interval Cosine(double a) { return Cosine(new Interval(a)); }
     301    public static Interval Tangens(double a) { return Tangens(new Interval(a)); }
     302    public static Interval HyperbolicTangent(double a) { return HyperbolicTangent(new Interval(a)); }
     303    public static Interval Square(double a) { return Square(new Interval(a)); }
     304    public static Interval Cube(double a) { return Cube(new Interval(a)); }
     305    public static Interval SquareRoot(double a) { return SquareRoot(new Interval(a)); }
     306    public static Interval CubicRoot(double a) { return CubicRoot(new Interval(a)); }
     307    public static Interval Absolute(double a) { return Absolute(new Interval(a)); }
     308    public static Interval AnalyticQuotient(Interval a, double b) { return AnalyticalQuotient(a, new Interval(b)); }
     309    public static Interval AnalyticQuotient(double a, Interval b) { return AnalyticalQuotient(new Interval(a), b); }
     310    public static Interval AnalyticQuotient(double a, double b) { return AnalyticalQuotient(new Interval(a), new Interval(b)); }
     311    #endregion
    278312  }
    279313}
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs

    r17564 r17902  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    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
    92109    public IReadOnlyDictionary<string, Interval> GetReadonlyDictionary() {
     110      return intervals.ToDictionary(pair => pair.Key, pair => pair.Value);
     111    }
     112
     113    public IDictionary<string, Interval> GetDictionary() {
    93114      return intervals.ToDictionary(pair => pair.Key, pair => pair.Value);
    94115    }
     
    98119        yield return Tuple.Create(variableInterval.Key, variableInterval.Value);
    99120    }
     121
     122    public event EventHandler Changed;
     123    private void RaiseChanged() {
     124      var handler = Changed;
     125      if (handler != null)
     126        handler(this, EventArgs.Empty);
     127    }
     128
    100129  }
    101130}
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs

    r17579 r17902  
    3535    protected const string TargetVariableParameterName = "TargetVariable";
    3636    protected const string VariableRangesParameterName = "VariableRanges";
    37     protected const string IntervalConstraintsParameterName = "IntervalConstraints";
     37    protected const string ShapeConstraintsParameterName = "ShapeConstraints";
    3838    public string Filename { get; set; }
    3939
     
    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<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints()));
    9697      emptyProblemData = problemData;
    9798    }
     
    107108      get => VariableRangesParameter.Value;
    108109    }
     110
     111    public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter =>
     112      (IFixedValueParameter<ShapeConstraints>) Parameters[ShapeConstraintsParameterName];
     113
     114    public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value;
    109115
    110116
     
    140146        Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection));
    141147      }
     148      if(Parameters.ContainsKey("IntervalConstraints")) {
     149        var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"];
     150        Parameters.Remove(param);
     151        Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, param.Value));
     152      }
     153      if (!Parameters.ContainsKey(ShapeConstraintsParameterName)) {
     154        Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, new ShapeConstraints()));
     155      }
     156
    142157      RegisterParameterEvents();
    143158    }
     
    163178    }
    164179
    165     public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)
     180    public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable,
     181      IEnumerable<ITransformation> transformations = null,
     182      IntervalCollection variableRanges = null,
     183      ShapeConstraints shapeConstraints = null)
    166184      : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) {
    167185      var variables = InputVariables.Select(x => x.AsReadOnly()).ToList();
    168186      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));
     187      if (variableRanges == null) {
     188        variableRanges = CalculateDatasetIntervals(this.Dataset);
     189      }
     190      Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges));
     191      if (shapeConstraints == null) {
     192        shapeConstraints = new ShapeConstraints();
     193      }
     194      Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints));
    171195      RegisterParameterEvents();
    172196    }
     
    174198    private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {
    175199      IntervalCollection intervalCollection = new IntervalCollection();
    176       foreach (var variable in dataset.DoubleVariables) {// intervals are only possible for double variables
     200      foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables
    177201        var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));
    178202        intervalCollection.AddInterval(variable, variableInterval);
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs

    r17579 r17902  
    11#region License Information
     2
    23/* HeuristicLab
    34 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     
    1819 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
    1920 */
     21
    2022#endregion
    2123
     
    2830    string TargetVariable { get; set; }
    2931
    30     IntervalCollection VariableRanges { get;}
     32    IntervalCollection VariableRanges { get; }
     33    ShapeConstraints ShapeConstraints { get; }
    3134
    3235    IEnumerable<double> TargetVariableValues { get; }
Note: See TracChangeset for help on using the changeset viewer.