Changeset 17911
- Timestamp:
- 03/23/21 15:24:58 (4 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs
r17579 r17911 109 109 Add(new Result(ModelBoundsResultName, "Results concerning the derivation of symbolic regression solution", value)); 110 110 } 111 112 111 } 113 112 } -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalArithBoundsEstimator.cs
r17910 r17911 232 232 for (var i = 1; i < currentInstr.nArguments; i++) { 233 233 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 234 result = Interval.Analytic alQuotient(result, argumentInterval);234 result = Interval.AnalyticQuotient(result, argumentInterval); 235 235 } 236 236 -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r17902 r17911 146 146 throw new ArgumentNullException("No variablew ranges are present!", nameof(variableRanges)); 147 147 148 // Check if all variables used in the tree are present in the dataset148 // Check if all variables used in the tree are present in the dataset 149 149 foreach (var variable in tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName) 150 150 .Distinct()) … … 191 191 break; 192 192 } 193 //Elementary arithmetic rules194 193 case OpCodes.Add: { 195 194 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); … … 293 292 for (var i = 1; i < currentInstr.nArguments; i++) { 294 293 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 295 result = Interval.Analytic alQuotient(result, argumentInterval);294 result = Interval.AnalyticQuotient(result, argumentInterval); 296 295 } 297 296 -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/DatasetExtensions.cs
r17180 r17911 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) { -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
r17902 r17911 271 271 } 272 272 273 public static Interval Analytic alQuotient(Interval a, Interval b) {273 public static Interval AnalyticQuotient(Interval a, Interval b) { 274 274 var dividend = a; 275 275 var divisor = Add(Square(b), new Interval(1.0, 1.0)); … … 306 306 public static Interval CubicRoot(double a) { return CubicRoot(new Interval(a)); } 307 307 public static Interval Absolute(double a) { return Absolute(new Interval(a)); } 308 public static Interval AnalyticQuotient(Interval a, double b) { return Analytic alQuotient(a, new Interval(b)); }309 public static Interval AnalyticQuotient(double a, Interval b) { return Analytic alQuotient(new Interval(a), b); }310 public static Interval AnalyticQuotient(double a, double b) { return Analytic alQuotient(new Interval(a), new Interval(b)); }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 311 #endregion 312 312 } -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/ShapeConstraintsParser.cs
r17906 r17911 76 76 private const string weightRegex = @"\s*(weight:\s*(?<weight>\S*))?"; 77 77 public static ShapeConstraint ParseFunctionRangeConstraint(string expr) { 78 if (!expr.StartsWith("f")) throw new ArgumentException($"Invalid function range constraint {expr} (e.g. f in [1..2])" , nameof(expr));78 if (!expr.StartsWith("f")) throw new ArgumentException($"Invalid function range constraint {expr} (e.g. f in [1..2])"); 79 79 var start = "f".Length; 80 80 var end = expr.Length; … … 131 131 return new ShapeConstraint(interval, weight); 132 132 } else 133 throw new ArgumentException($"The inserted target constraint {expr} is not valid.", nameof(expr));133 throw new ArgumentException($"The target constraint {expr} is not valid."); 134 134 } 135 135 public static ShapeConstraint ParseDerivationConstraint(string expr) { … … 161 161 if (enumeratorNumDeriv != "" || denominatorNumDeriv != "") { 162 162 if (enumeratorNumDeriv == "" || denominatorNumDeriv == "") 163 throw new ArgumentException($"Number of derivation has to be written on both sides in {expr}." , nameof(expr));163 throw new ArgumentException($"Number of derivation has to be written on both sides in {expr}."); 164 164 if (enumeratorNumDeriv != denominatorNumDeriv) 165 throw new ArgumentException($"Derivation number is not equal on both sides in {expr}." , nameof(expr));165 throw new ArgumentException($"Derivation number is not equal on both sides in {expr}."); 166 166 } 167 167 … … 193 193 return new ShapeConstraint(variable, numberOfDerivation, interval, weight); 194 194 } else 195 throw new ArgumentException($"The inserted derivation constraint {expr} is not valid.", nameof(expr));195 throw new ArgumentException($"The derivation constraint {expr} is not valid."); 196 196 } 197 197 -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r17902 r17911 99 99 #endregion 100 100 101 public IConstrainedValueParameter<StringValue> TargetVariableParameter { 102 get { return (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; } 103 } 104 101 #region parameter properties 102 public IConstrainedValueParameter<StringValue> TargetVariableParameter => (IConstrainedValueParameter<StringValue>)Parameters[TargetVariableParameterName]; 103 public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter => (IFixedValueParameter<ShapeConstraints>)Parameters[ShapeConstraintsParameterName]; 105 104 public IFixedValueParameter<IntervalCollection> VariableRangesParameter => (IFixedValueParameter<IntervalCollection>)Parameters[VariableRangesParameterName]; 106 105 #endregion 106 107 #region properties 107 108 public IntervalCollection VariableRanges { 108 109 get => VariableRangesParameter.Value; 109 110 } 110 111 111 public IFixedValueParameter<ShapeConstraints> ShapeConstraintsParameter =>112 (IFixedValueParameter<ShapeConstraints>) Parameters[ShapeConstraintsParameterName];113 112 114 113 public ShapeConstraints ShapeConstraints => ShapeConstraintsParameter.Value; … … 126 125 } 127 126 } 128 129 public IEnumerable<double> TargetVariableValues { 130 get { return Dataset.GetDoubleValues(TargetVariable); } 131 } 132 public IEnumerable<double> TargetVariableTrainingValues { 133 get { return Dataset.GetDoubleValues(TargetVariable, TrainingIndices); } 134 } 135 public IEnumerable<double> TargetVariableTestValues { 136 get { return Dataset.GetDoubleValues(TargetVariable, TestIndices); } 137 } 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 138 132 139 133 … … 143 137 private void AfterDeserialization() { 144 138 if (!Parameters.ContainsKey(VariableRangesParameterName)) { 145 var intervalCollection = CalculateDatasetIntervals(this.Dataset);139 var intervalCollection = Dataset.GetIntervals(); 146 140 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, intervalCollection)); 147 141 } 148 if (Parameters.ContainsKey("IntervalConstraints")) {142 if (Parameters.ContainsKey("IntervalConstraints")) { 149 143 var param = (IFixedValueParameter<ShapeConstraints>)Parameters["IntervalConstraints"]; 150 144 Parameters.Remove(param); … … 178 172 } 179 173 180 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 174 public RegressionProblemData(IDataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable, 181 175 IEnumerable<ITransformation> transformations = null, 182 176 IntervalCollection variableRanges = null, … … 186 180 Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>(variables), variables.Where(x => x.Value == targetVariable).First())); 187 181 if (variableRanges == null) { 188 variableRanges = CalculateDatasetIntervals(this.Dataset);182 variableRanges = Dataset.GetIntervals(); 189 183 } 190 184 Parameters.Add(new FixedValueParameter<IntervalCollection>(VariableRangesParameterName, variableRanges)); 185 191 186 if (shapeConstraints == null) { 192 187 shapeConstraints = new ShapeConstraints(); 193 } 188 } 194 189 Parameters.Add(new FixedValueParameter<ShapeConstraints>(ShapeConstraintsParameterName, shapeConstraints)); 195 190 RegisterParameterEvents(); 196 191 } 197 198 private static IntervalCollection CalculateDatasetIntervals(IDataset dataset) {199 IntervalCollection intervalCollection = new IntervalCollection();200 foreach (var variable in dataset.DoubleVariables) { // intervals are only possible for double variables201 var variableInterval = Interval.GetInterval(dataset.GetDoubleValues(variable));202 intervalCollection.AddInterval(variable, variableInterval);203 }204 205 return intervalCollection;206 }207 208 192 private void RegisterParameterEvents() { 209 TargetVariableParameter.ValueChanged += new EventHandler(TargetVariableParameter_ValueChanged); 210 } 211 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) { 212 197 OnChanged(); 213 198 }
Note: See TracChangeset
for help on using the changeset viewer.