Changeset 17928 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
- Timestamp:
- 04/06/21 13:13:32 (4 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17180 r17928 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; 27 28 using HeuristicLab.Data; 28 29 using HeuristicLab.Parameters; 29 using HEAL.Attic;30 30 31 31 namespace HeuristicLab.Problems.DataAnalysis { … … 34 34 public class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData, IStorableContent { 35 35 protected const string TargetVariableParameterName = "TargetVariable"; 36 protected const string VariableRangesParameterName = "VariableRanges"; 37 protected const string ShapeConstraintsParameterName = "ShapeConstraints"; 36 38 public string Filename { get; set; } 37 39 … … 91 93 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 92 94 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 95 problemData.Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, "", new IntervalCollection())); 96 problemData.Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, "", new ShapeConstraints())); 93 97 emptyProblemData = problemData; 94 98 } 95 99 #endregion 96 100 97 public IConstrainedValueParameter<StringValue> TargetVariableParameter { 98 get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; } 99 } 101 #region parameter properties 102 public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; 103 public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName]; 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 105 #endregion 106 107 #region properties 108 public IntervalCollection VariableRanges { 109 get => VariableRangesParameter.Value; 110 } 111 112 113 public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value; 114 115 100 116 public string TargetVariable { 101 117 get { return TargetVariableParameter.Value.Value; } … … 109 125 } 110 126 } 111 112 public IEnumerable<double> TargetVariableValues { 113 get { return Dataset.GetDoubleValues(TargetVariable); } 114 } 115 public IEnumerable<double> TargetVariableTrainingValues { 116 get { return Dataset.GetDoubleValues(TargetVariable, TrainingIndices); } 117 } 118 public IEnumerable<double> TargetVariableTestValues { 119 get { return Dataset.GetDoubleValues(TargetVariable, TestIndices); } 120 } 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 121 132 122 133 … … 125 136 [StorableHook(HookType.AfterDeserialization)] 126 137 private void AfterDeserialization() { 138 if (!Parameters.ContainsKey(VariableRangesParameterName)) { 139 var intervalCollection = Dataset.GetIntervals(); 140 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection)); 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 127 151 RegisterParameterEvents(); 128 152 } … … 148 172 } 149 173 150 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) 151 178 : base(dataset, allowedInputVariables, transformations ?? Enumerable.Empty<ITransformation>()) { 152 179 var variables = InputVariables.Select(x => x.AsReadOnly()).ToList(); 153 180 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First())); 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)); 154 190 RegisterParameterEvents(); 155 191 } 156 157 192 private void RegisterParameterEvents() { 158 TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged); 159 } 160 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) { 161 197 OnChanged(); 162 198 }
Note: See TracChangeset
for help on using the changeset viewer.