- Timestamp:
- 03/29/21 09:54:58 (4 years ago)
- Location:
- branches/3105_PythonFormatter
- Files:
-
- 10 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3105_PythonFormatter
- Property svn:mergeinfo changed
/trunk (added) merged: 17845,17856,17858-17859,17861,17867,17871-17873,17888-17889,17902-17903,17906-17914
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs
r17180 r17918 96 96 } 97 97 98 public static IntervalCollection GetIntervals(this IDataset dataset) { 99 IntervalCollection intervalCollection = new IntervalCollection(); 100 foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables 101 var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable)); 102 intervalCollection.AddInterval(variable, variableInterval); 103 } 104 105 return intervalCollection; 106 } 107 98 108 public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetFactorVariableValues( 99 109 this IDataset ds, IEnumerable<string> factorVariables, IEnumerable<int> rows) { -
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r17579 r17918 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"> -
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r17835 r17918 306 306 classNamesCache.Add(ClassNamesParameter.Value[i, 0]); 307 307 } 308 308 309 public override IDeepCloneable Clone(Cloner cloner) { 309 310 if (this == emptyProblemData) return emptyProblemData; … … 314 315 315 316 public ClassificationProblemData(IClassificationProblemData classificationProblemData) 316 : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable, classificationProblemData.ClassNames, classificationProblemData.PositiveClass) { 317 317 : this(classificationProblemData, classificationProblemData.Dataset) { 318 } 319 320 /// <summary> 321 /// This method satisfies a common use case: making a copy of the problem but providing a different dataset. 322 /// One must be careful here that the dataset passed is not modified, as that would invalidate the problem data internals. 323 /// Passing a ModifiableDataset to this constructor is therefore discouraged. 324 /// </summary> 325 /// <param name="classificationProblemData">The original instance of classification problem data.</param> 326 /// <param name="dataset">The new dataset.</param> 327 public ClassificationProblemData(IClassificationProblemData classificationProblemData, IDataset dataset) 328 : this(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable, classificationProblemData.ClassNames, classificationProblemData.PositiveClass) { 329 318 330 TrainingPartition.Start = classificationProblemData.TrainingPartition.Start; 319 331 TrainingPartition.End = classificationProblemData.TrainingPartition.End; 320 332 TestPartition.Start = classificationProblemData.TestPartition.Start; 321 333 TestPartition.End = classificationProblemData.TestPartition.End; 322 334 323 335 for (int i = 0; i < Classes; i++) { 324 336 for (int j = 0; j < Classes; j++) { … … 328 340 } 329 341 330 public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null)331 : this(dataset, allowedInputVariables, targetVariable, Enumerable.Empty<string>(), null, transformations) { }332 333 342 public ClassificationProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 334 IEnumerable<string> classNames ,343 IEnumerable<string> classNames = null, 335 344 string positiveClass = null, // can be null in which case it's set as the first class name 336 345 IEnumerable<ITransformation> transformations = null) … … 348 357 349 358 // set the class names 350 if (classNames .Any()) {359 if (classNames != null && classNames.Any()) { 351 360 // better to allocate lists because we use these multiple times below 352 361 var names = classNames.ToList(); 353 var values = ClassValues .ToList();362 var values = ClassValuesCache; 354 363 355 364 if (names.Count != values.Count) { -
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
- Property svn:mergeinfo changed
r17583 r17918 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 … … 267 271 } 268 272 269 public static Interval Analytic alQuotient(Interval a, Interval b) {273 public static Interval AnalyticQuotient(Interval a, Interval b) { 270 274 var dividend = a; 271 275 var divisor = Add(Square(b), new Interval(1.0, 1.0)); … … 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 AnalyticQuotient(a, new Interval(b)); } 309 public static Interval AnalyticQuotient(double a, Interval b) { return AnalyticQuotient(new Interval(a), b); } 310 public static Interval AnalyticQuotient(double a, double b) { return AnalyticQuotient(new Interval(a), new Interval(b)); } 311 #endregion 278 312 } 279 313 } -
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/IntervalCollection.cs
r17564 r17918 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 private IDictionary<string, Interval> intervals { get; set; } = new Dictionary<string, Interval>(); 38 39 [Storable(OldName = "StorableIntervalInformation")] 39 40 private KeyValuePair<string, double[]>[] StorableIntervalInformation { 41 set { 42 foreach (var varInt in value) 43 intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1])); 44 } 45 } 46 47 [Storable] 48 private object[] StorableIntervals { 40 49 get { 41 var l = new List<KeyValuePair<string, double[]>>(); 42 foreach (var varInt in intervals) 50 var names = intervals.Keys.ToArray(); 51 var lowerBounds = intervals.Values.Select(i => i.LowerBound).ToArray(); 52 var upperBounds = intervals.Values.Select(i => i.UpperBound).ToArray(); 43 53 44 l.Add(new KeyValuePair<string, double[]>(varInt.Key, 45 new double[] { varInt.Value.LowerBound, varInt.Value.UpperBound })); 46 return l.ToArray(); 54 return new object[] { names, lowerBounds, upperBounds }; 47 55 } 48 56 49 57 set { 50 foreach (var varInt in value) 51 intervals.Add(varInt.Key, new Interval(varInt.Value[0], varInt.Value[1])); 58 var names = (string[])value[0]; 59 var lowerBounds = (double[])value[1]; 60 var upperBounds = (double[])value[2]; 61 62 for (int i = 0; i < names.Length; i++) { 63 intervals.Add(names[i], new Interval(lowerBounds[i], upperBounds[i])); 64 } 52 65 } 53 66 } … … 80 93 public void SetInterval(string identifier, Interval interval) { 81 94 intervals[identifier] = interval; 95 RaiseChanged(); 82 96 } 83 97 84 98 public void AddInterval(string identifier, Interval interval) { 85 99 intervals.Add(identifier, interval); 100 RaiseChanged(); 86 101 } 87 102 88 103 public void DeleteInterval(string identifier) { 89 104 intervals.Remove(identifier); 105 RaiseChanged(); 90 106 } 91 107 92 108 public IReadOnlyDictionary<string, Interval> GetReadonlyDictionary() { 109 return intervals.ToDictionary(pair => pair.Key, pair => pair.Value); 110 } 111 112 public IDictionary<string, Interval> GetDictionary() { 93 113 return intervals.ToDictionary(pair => pair.Key, pair => pair.Value); 94 114 } … … 98 118 yield return Tuple.Create(variableInterval.Key, variableInterval.Value); 99 119 } 120 121 public event EventHandler Changed; 122 private void RaiseChanged() { 123 var handler = Changed; 124 if (handler != null) 125 handler(this, EventArgs.Empty); 126 } 127 100 128 } 101 129 } -
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17579 r17918 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 } 98 99 #endregion 99 100 100 public IConstrainedValueParameter<StringValue> TargetVariableParameter { 101 get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; } 102 } 103 101 #region parameter properties 102 public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; 103 public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName]; 104 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 105 105 #endregion 106 107 #region properties 106 108 public IntervalCollection VariableRanges { 107 109 get => VariableRangesParameter.Value; 108 110 } 111 112 113 public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value; 109 114 110 115 … … 120 125 } 121 126 } 122 123 public IEnumerable<double> TargetVariableValues { 124 get { return Dataset.GetDoubleValues(TargetVariable); } 125 } 126 public IEnumerable<double> TargetVariableTrainingValues { 127 get { return Dataset.GetDoubleValues(TargetVariable, TrainingIndices); } 128 } 129 public IEnumerable<double> TargetVariableTestValues { 130 get { return Dataset.GetDoubleValues(TargetVariable, TestIndices); } 131 } 127 public IEnumerable<double> TargetVariableValues => Dataset.GetDoubleValues(TargetVariable); 128 public IEnumerable<double> TargetVariableTrainingValues => Dataset.GetDoubleValues(TargetVariable, TrainingIndices); 129 public IEnumerable<double> TargetVariableTestValues => Dataset.GetDoubleValues(TargetVariable, TestIndices); 130 #endregion 131 132 132 133 133 … … 137 137 private void AfterDeserialization() { 138 138 if (!Parameters.ContainsKey(VariableRangesParameterName)) { 139 var intervalCollection = CalculateDatasetIntervals(this.Dataset);139 var intervalCollection = Dataset.GetIntervals(); 140 140 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection)); 141 141 } 142 if (Parameters.ContainsKey("IntervalConstraints")) { 143 var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"]; 144 Parameters.Remove(param); 145 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, param.Value)); 146 } 147 if (!Parameters.ContainsKey(ShapeConstraintsParameterName)) { 148 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, new ShapeConstraints())); 149 } 150 142 151 RegisterParameterEvents(); 143 152 } … … 163 172 } 164 173 165 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, IEnumerable<ITransformation> transformations = null) 174 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 175 IEnumerable<ITransformation> transformations = null, 176 IntervalCollection variableRanges = null, 177 ShapeConstraints shapeConstraints = null) 166 178 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 167 179 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 168 180 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)); 181 if (variableRanges == null) { 182 variableRanges = Dataset.GetIntervals(); 183 } 184 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges)); 185 186 if (shapeConstraints == null) { 187 shapeConstraints = new ShapeConstraints(); 188 } 189 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints)); 171 190 RegisterParameterEvents(); 172 191 } 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 variables177 var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));178 intervalCollection.AddInterval(variable, variableInterval);179 }180 181 return intervalCollection;182 }183 184 192 private void RegisterParameterEvents() { 185 TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged); 186 } 187 private void TargetVariableParameter_ValueChanged(object sender, EventArgs e) { 193 TargetVariableParameter.ValueChanged += new EventHandler(Parameter_ValueChanged); 194 // VariableRanges and ShapeConstraints are fixed parameters 195 } 196 private void Parameter_ValueChanged(object sender, EventArgs e) { 188 197 OnChanged(); 189 198 } -
branches/3105_PythonFormatter/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionProblemData.cs
r17579 r17918 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.