Changeset 17902 for trunk/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 03/16/21 14:23:41 (4 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis
- Files:
-
- 7 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r17579 r17902 142 142 <Compile Include="Implementation\Interval\Interval.cs" /> 143 143 <Compile Include="Implementation\Interval\IntervalCollection.cs" /> 144 <Compile Include="Implementation\Interval\ShapeConstraint.cs" /> 145 <Compile Include="Implementation\Interval\ShapeConstraintsParser.cs" /> 144 146 <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" /> 145 147 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> 146 148 <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" /> 149 <Compile Include="Implementation\Regression\ShapeConstraints.cs" /> 147 150 <Compile Include="Implementation\Regression\RegressionEnsembleProblemData.cs" /> 148 151 <Compile Include="Implementation\Regression\RegressionEnsembleModel.cs"> -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
- Property svn:mergeinfo changed
r17583 r17902 33 33 [Storable] 34 34 public double UpperBound { get; private set; } 35 36 public double Width => UpperBound - LowerBound; 35 37 36 38 [StorableConstructor] … … 67 69 } 68 70 71 private Interval(double v) : this(v, v) { } 72 69 73 public bool Contains(double value) { 70 74 return LowerBound <= value && value <= UpperBound; … … 126 130 return false; 127 131 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))); 130 134 } 131 135 … … 276 280 } 277 281 #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 278 312 } 279 313 } -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs
r17564 r17902 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2019Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 34 34 get => HeuristicLab.Common.Resources.VSImageLibrary.Object; 35 35 } 36 private IDictionary<string, Interval> intervals { get; } = new Dictionary<string, Interval>();37 36 38 [Storable(Name = "StorableIntervalInformation")] 37 //[Storable] 38 private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>(); 39 40 [Storable(OldName = "StorableIntervalInformation")] 39 41 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 { 40 50 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(); 43 54 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 }; 47 56 } 48 57 49 58 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 } 52 66 } 53 67 } … … 80 94 public void SetInterval(string identifier, Interval interval) { 81 95 intervals[identifier] = interval; 96 RaiseChanged(); 82 97 } 83 98 84 99 public void AddInterval(string identifier, Interval interval) { 85 100 intervals.Add(identifier, interval); 101 RaiseChanged(); 86 102 } 87 103 88 104 public void DeleteInterval(string identifier) { 89 105 intervals.Remove(identifier); 106 RaiseChanged(); 90 107 } 91 108 92 109 public IReadOnlyDictionary<string, Interval> GetReadonlyDictionary() { 110 return intervals.ToDictionary(pair => pair.Key, pair => pair.Value); 111 } 112 113 public IDictionary<string, Interval> GetDictionary() { 93 114 return intervals.ToDictionary(pair => pair.Key, pair => pair.Value); 94 115 } … … 98 119 yield return Tuple.Create(variableInterval.Key, variableInterval.Value); 99 120 } 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 100 129 } 101 130 } -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17579 r17902 35 35 protected const string TargetVariableParameterName = "TargetVariable"; 36 36 protected const string VariableRangesParameterName = "VariableRanges"; 37 protected const string IntervalConstraintsParameterName = "IntervalConstraints";37 protected const string ShapeConstraintsParameterName = "ShapeConstraints"; 38 38 public string Filename { get; set; } 39 39 … … 94 94 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 95 95 problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection())); 96 problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints())); 96 97 emptyProblemData = problemData; 97 98 } … … 107 108 get => VariableRangesParameter.Value; 108 109 } 110 111 public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => 112 (IFixedValueParameter<ShapeConstraints>) Parameters[ShapeConstraintsParameterName]; 113 114 public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value; 109 115 110 116 … … 140 146 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection)); 141 147 } 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 142 157 RegisterParameterEvents(); 143 158 } … … 163 178 } 164 179 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) 166 184 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 167 185 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 168 186 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)); 171 195 RegisterParameterEvents(); 172 196 } … … 174 198 private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) { 175 199 IntervalCollection intervalCollection = new IntervalCollection(); 176 foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables200 foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables 177 201 var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable)); 178 202 intervalCollection.AddInterval(variable, variableInterval); -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs
r17579 r17902 1 1 #region License Information 2 2 3 /* HeuristicLab 3 4 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 18 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 19 20 */ 21 20 22 #endregion 21 23 … … 28 30 string TargetVariable { get; set; } 29 31 30 IntervalCollection VariableRanges { get;} 32 IntervalCollection VariableRanges { get; } 33 ShapeConstraints ShapeConstraints { get; } 31 34 32 35 IEnumerable<double> TargetVariableValues { get; }
Note: See TracChangeset
for help on using the changeset viewer.