Changeset 17887 for branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic
- Timestamp:
- 03/12/21 14:00:36 (4 years ago)
- Location:
- branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/IntervalArithmeticGrammar.cs
r17880 r17887 35 35 var cos = new Cosine(); 36 36 var tan = new Tangent(); 37 var tanh = new HyperbolicTangent(); 37 38 var log = new Logarithm(); 38 var pow = new Power();39 var exp = new Exponential(); 39 40 var square = new Square(); 40 var root = new Root();41 41 var sqrt = new SquareRoot(); 42 var exp = new Exponential(); 43 var tanh = new HyperbolicTangent(); 42 var cube = new Cube(); 43 var cbrt = new CubeRoot(); 44 var abs = new Absolute(); 45 var aq = new AnalyticQuotient(); 44 46 var constant = new Constant(); 45 var aq = new AnalyticQuotient();46 47 constant.MinValue = -20; 47 48 constant.MaxValue = 20; … … 51 52 52 53 //Special symbols 53 var offset = new Addition { Name = "Offset"};54 var scaling = new Multiplication { Name = "Scaling"};54 var offset = new Addition { Name = "Offset" }; 55 var scaling = new Multiplication { Name = "Scaling" }; 55 56 //all other symbols 56 57 var allSymbols = new List<Symbol> { 57 add, sub, mul, div, constant, variableSymbol, sin, cos, tan, log, pow, square, root, sqrt, exp,58 tanh, aq 58 add, sub, mul, div, constant, variableSymbol, sin, cos, tan, log, square, sqrt, cube, cbrt, exp, 59 tanh, aq, abs 59 60 }; 60 61 61 var arithmeticSymbols = new List<Symbol> {add, sub, mul, div}; 62 var trigonometricSymbols = new List<Symbol> {sin, cos, tan, tanh}; 63 var exponentialAndLogarithmicSymbols = new List<Symbol> {exp, log}; 64 var powerSymbols = new List<Symbol> {square, pow, sqrt, root}; 65 var specialSymbols = new List<Symbol> {aq}; 66 var realValueSymbols = new List<Symbol> 67 {add, sub, mul, div, sin, cos, tan, tanh, exp, log, variableSymbol, constant, aq}; 62 var bivariateFuncs = new List<Symbol> { add, sub, mul, div, aq }; 63 var univariateFuncs = new List<Symbol> { sin, cos, tan, tanh, exp, log, abs, square, cube, sqrt, cbrt }; 64 var realValueSymbols = new List<Symbol> { 65 add, sub, mul, div, sin, cos, tan, tanh, exp, log, aq, abs, square, cube, sqrt, cbrt, 66 variableSymbol, constant, 67 }; 68 68 69 69 … … 76 76 #region define subtree count for special symbols 77 77 78 foreach (var symb in arithmeticSymbols) SetSubtreeCount(symb, 2, 2);78 foreach (var symb in bivariateFuncs) SetSubtreeCount(symb, 2, 2); 79 79 80 foreach (var symb in trigonometricSymbols) SetSubtreeCount(symb, 1, 1); 81 82 foreach (var symb in exponentialAndLogarithmicSymbols) SetSubtreeCount(symb, 1, 1); 80 foreach (var symb in univariateFuncs) SetSubtreeCount(symb, 1, 1); 83 81 84 82 SetSubtreeCount(offset, 2, 2); 85 83 SetSubtreeCount(scaling, 2, 2); 86 SetSubtreeCount(pow, 2, 2);87 SetSubtreeCount(root, 2, 2);88 SetSubtreeCount(square, 1, 1);89 SetSubtreeCount(sqrt, 1, 1);90 SetSubtreeCount(aq, 2, 2);91 84 92 85 #endregion … … 109 102 } 110 103 111 //define childs for power symbols112 foreach (var symb in powerSymbols) {113 AddAllowedChildSymbol(symb, variableSymbol, 0);114 AddAllowedChildSymbol(symb, constant, 1);115 }116 117 //define child for sqrt and square118 foreach (var c in realValueSymbols) {119 AddAllowedChildSymbol(square, c, 0);120 AddAllowedChildSymbol(sqrt, c, 0);121 }122 123 //define child for aq124 foreach (var c in realValueSymbols) {125 AddAllowedChildSymbol(aq, c, 0);126 AddAllowedChildSymbol(aq, c, 1);127 }128 129 104 #endregion 130 105 131 Symbols.First(s => s is Power).Enabled = false;132 Symbols.First(s => s is Root).Enabled = false;133 Symbols.First(s => s is A nalyticQuotient).Enabled = false;106 Symbols.First(s => s is Cube).Enabled = false; 107 Symbols.First(s => s is CubeRoot).Enabled = false; 108 Symbols.First(s => s is Absolute).Enabled = false; 134 109 } 135 110 } -
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/IBoundsEstimator.cs
r17768 r17887 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 1 using System.Collections.Generic; 6 2 using HEAL.Attic; 7 3 using HeuristicLab.Core; 8 4 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 9 5 10 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {6 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 11 7 [StorableType("C94A360D-5A9F-48A3-A6D3-CF920C77E50D")] 12 8 public interface IBoundsEstimator : INamedItem, IStatefulItem { 13 9 Interval GetModelBound(ISymbolicExpressionTree tree, IntervalCollection variableRanges); 14 10 15 IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNode sBounds(11 IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodeBounds( 16 12 ISymbolicExpressionTree tree, IntervalCollection variableRanges); 17 13 14 // returns the size of the violation which is the distance to one of the bounds 18 15 double CheckConstraint( 19 ISymbolicExpressionTree tree, IntervalCollection variableRanges, IntervalConstraint constraint);16 ISymbolicExpressionTree tree, IntervalCollection variableRanges, ShapeConstraint constraint); 20 17 21 18 bool IsCompatible(ISymbolicExpressionTree tree); 22 19 23 20 int EvaluatedSolutions { get; set; } 24 21 } 25 22 } -
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IABoundsEstimator.cs
r17880 r17887 461 461 } 462 462 463 public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNode sBounds(463 public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodeBounds( 464 464 ISymbolicExpressionTree tree, IntervalCollection variableRanges) { 465 465 throw new NotImplementedException(); … … 467 467 468 468 public double CheckConstraint( 469 ISymbolicExpressionTree tree, IntervalCollection variableRanges, IntervalConstraint constraint) {469 ISymbolicExpressionTree tree, IntervalCollection variableRanges, ShapeConstraint constraint) { 470 470 var occuringVariableRanges = GetOccurringVariableRanges(tree, variableRanges); 471 471 var instructions = PrepareInterpreterState(tree, occuringVariableRanges); -
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IACompiledExpressionBoundsEstimator.cs
r17772 r17887 104 104 105 105 106 public double CheckConstraint(ISymbolicExpressionTree tree, IntervalCollection variableRanges, IntervalConstraint constraint) {106 public double CheckConstraint(ISymbolicExpressionTree tree, IntervalCollection variableRanges, ShapeConstraint constraint) { 107 107 if (!UseIntervalSplitting) { 108 108 var modelBound = GetModelBound(tree, variableRanges); … … 166 166 } 167 167 168 public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNode sBounds(ISymbolicExpressionTree tree, IntervalCollection variableRanges) {168 public IDictionary<ISymbolicExpressionTreeNode, Interval> GetModelNodeBounds(ISymbolicExpressionTree tree, IntervalCollection variableRanges) { 169 169 throw new NotSupportedException("Model nodes bounds are not supported."); 170 170 } -
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r17760 r17887 24 24 using System; 25 25 using System.Collections.Generic; 26 using System.Collections.ObjectModel;27 26 using System.Linq; 28 27 using HEAL.Attic; … … 38 37 public sealed class IntervalInterpreter : ParameterizedNamedItem, IStatefulItem { 39 38 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 40 private const string MinSplittingWidthParameterName = "MinSplittingWidth";41 private const string MaxSplittingDepthParameterName = "MaxSplittingDepth";42 private const string UseIntervalSplittingParameterName = "UseIntervalSplitting";43 44 39 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter => 45 40 (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; 46 47 public IFixedValueParameter<IntValue> MinSplittingWithParameter =>48 (IFixedValueParameter<IntValue>)Parameters[MinSplittingWidthParameterName];49 50 public IFixedValueParameter<IntValue> MaxSplittingDepthParameter =>51 (IFixedValueParameter<IntValue>)Parameters[MaxSplittingDepthParameterName];52 53 public IFixedValueParameter<BoolValue> UseIntervalSplittingParameter =>54 (IFixedValueParameter<BoolValue>)Parameters[UseIntervalSplittingParameterName];55 56 public int MinSplittingWidth {57 get => MinSplittingWithParameter.Value.Value;58 set => MinSplittingWithParameter.Value.Value = value;59 }60 61 public int MaxSplittingDepth {62 get => MaxSplittingDepthParameter.Value.Value;63 set => MaxSplittingDepthParameter.Value.Value = value;64 }65 66 public bool UseIntervalSplitting {67 get => UseIntervalSplittingParameter.Value.Value;68 set => UseIntervalSplittingParameter.Value.Value = value;69 }70 41 71 42 public int EvaluatedSolutions { … … 84 55 Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, 85 56 "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0))); 86 Parameters.Add(new FixedValueParameter<IntValue>(MinSplittingWidthParameterName,87 "Minimum interval width until splitting is stopped", new IntValue(0)));88 Parameters.Add(new FixedValueParameter<IntValue>(MaxSplittingDepthParameterName,89 "Maximum recursion depth of the splitting", new IntValue(5)));90 Parameters.Add(new FixedValueParameter<BoolValue>(UseIntervalSplittingParameterName, "", new BoolValue(false)));91 57 } 92 58 … … 131 97 Interval outputInterval; 132 98 133 if (UseIntervalSplitting) { 134 outputInterval = GetSymbolicExpressionTreeIntervals(tree, variableRanges, 135 out var _); 136 } else { 137 var instructionCount = 0; 138 var instructions = PrepareInterpreterState(tree, variableRanges); 139 outputInterval = Evaluate(instructions, ref instructionCount); 140 } 99 var instructionCount = 0; 100 var instructions = PrepareInterpreterState(tree, variableRanges); 101 outputInterval = Evaluate(instructions, ref instructionCount); 141 102 142 103 return outputInterval.LowerBound <= outputInterval.UpperBound … … 159 120 160 121 Interval outputInterval; 161 if (UseIntervalSplitting) { 162 //var variables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(x => x.VariableName).Distinct() 163 // .ToList(); 164 var containsDependencyProblem = ContainsVariableMultipleTimes(tree, out var variables); 165 166 if (containsDependencyProblem) { 167 var currIndex = 0; 168 var currDepth = 0; 169 IDictionary<string, Interval> writeableVariableRanges = 170 variableRanges.ToDictionary(kvp => kvp.Key, kvp => kvp.Value); 171 //outputInterval = EvaluateRecursive(instructions, intervals, writeableVariableRanges, variables, MinSplittingWidth, MaxSplittingDepth, 172 // ref currIndex, ref currDepth, tree); 173 outputInterval = EvaluateWithSplitting(instructions, intervals, writeableVariableRanges, variables); 174 } else { 175 var instructionCount = 0; 176 outputInterval = Evaluate(instructions, ref instructionCount, intervals); 177 } 178 } else { 179 var instructionCount = 0; 180 outputInterval = Evaluate(instructions, ref instructionCount, intervals); 181 } 122 var instructionCount = 0; 123 outputInterval = Evaluate(instructions, ref instructionCount, intervals); 182 124 183 125 nodeIntervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>(); … … 219 161 } 220 162 221 public static Interval EvaluateWithSplitting(Instruction[] instructions, 222 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, 223 IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables) { 224 var savedIntervals = variableIntervals.ToDictionary(entry => entry.Key, entry => entry.Value); 225 var min = FindBound(instructions, nodeIntervals, variableIntervals, multipleOccurenceVariables, minimization: true); 226 var max = FindBound(instructions, nodeIntervals, savedIntervals, multipleOccurenceVariables, minimization: false); 227 228 return new Interval(min, max); 229 } 230 231 232 private static double FindBound(Instruction[] instructions, 233 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, 234 IDictionary<string, Interval> variableIntervals, List<string> multipleOccurenceVariables, bool minimization = true) { 235 SortedSet<BoxBound> prioQ = new SortedSet<BoxBound>(); 236 237 var ic = 0; 238 //Calculate full box 239 IReadOnlyDictionary<string, Interval> readonlyRanges = variableIntervals.ToDictionary(k => k.Key, k => k.Value); 240 var interval = Evaluate(instructions, ref ic, nodeIntervals, readonlyRanges); 241 // the order of keys in a dictionary is guaranteed to be the same order as values in a dictionary 242 // https://docs.microsoft.com/en-us/dotnet/api/system.collections.idictionary.keys?view=netcore-3.1#remarks 243 //var box = variableIntervals.Values; 244 //Box only contains intervals from multiple occurence variables 245 var box = multipleOccurenceVariables.Select(k => variableIntervals[k]); 246 if (minimization) { 247 prioQ.Add(new BoxBound(box, interval.LowerBound)); 248 } else { 249 prioQ.Add(new BoxBound(box, -interval.UpperBound)); 250 } 251 252 // TODO a fixed limit for depth?! 253 for (var depth = 0; depth < 200; ++depth) { 254 var currentBound = prioQ.Min; 255 prioQ.Remove(currentBound); 256 257 var newBoxes = Split(currentBound.box); 258 259 foreach (var newBox in newBoxes) { 260 //var intervalEnum = newBox.GetEnumerator(); 261 //var keyEnum = readonlyRanges.Keys.GetEnumerator(); 262 //while (intervalEnum.MoveNext() & keyEnum.MoveNext()) { 263 // variableIntervals[keyEnum.Current] = intervalEnum.Current; 264 //} 265 //Set the splitted variables 266 var intervalEnum = newBox.GetEnumerator(); 267 foreach (var key in multipleOccurenceVariables) { 268 intervalEnum.MoveNext(); 269 variableIntervals[key] = intervalEnum.Current; 270 } 271 272 ic = 0; 273 var res = Evaluate(instructions, ref ic, nodeIntervals, 274 new ReadOnlyDictionary<string, Interval>(variableIntervals)); 275 if (minimization) { 276 prioQ.Add(new BoxBound(newBox, res.LowerBound)); 277 } else { 278 prioQ.Add(new BoxBound(newBox, -res.UpperBound)); 279 } 280 } 281 } 282 283 return minimization ? 284 prioQ.First().bound : 285 -prioQ.First().bound; 286 } 287 288 private static IEnumerable<IEnumerable<Interval>> Split(List<Interval> box) { 289 var boxes = box.Select(region => region.Split()).Select(split => new List<Interval> { split.Item1, split.Item2 }) 290 .ToList(); 291 292 return boxes.CartesianProduct(); 293 } 294 295 // a multi-dimensional box with an associated bound 296 // boxbounds are ordered first by bound (smaller first), then by size of box (larger first) then by distance of bottom left corner to origin 297 private class BoxBound : IComparable<BoxBound> { 298 public List<Interval> box; 299 public double bound; 300 public BoxBound(IEnumerable<Interval> box, double bound) { 301 this.box = new List<Interval>(box); 302 this.bound = bound; 303 } 304 public int CompareTo(BoxBound other) { 305 if (bound != other.bound) return bound.CompareTo(other.bound); 306 307 var thisSize = box.Aggregate(1.0, (current, dimExtent) => current * dimExtent.Width); 308 var otherSize = other.box.Aggregate(1.0, (current, dimExtent) => current * dimExtent.Width); 309 if (thisSize != otherSize) return -thisSize.CompareTo(otherSize); 310 311 var thisDist = box.Sum(dimExtent => dimExtent.LowerBound * dimExtent.LowerBound); 312 var otherDist = other.box.Sum(dimExtent => dimExtent.LowerBound * dimExtent.LowerBound); 313 if (thisDist != otherDist) return thisDist.CompareTo(otherDist); 314 315 // which is smaller first along the dimensions? 316 for (int i = 0; i < box.Count; i++) { 317 if (box[i].LowerBound != other.box[i].LowerBound) return box[i].LowerBound.CompareTo(other.box[i].LowerBound); 318 } 319 320 return 0; 321 } 322 } 323 324 public static Interval EvaluateRecursive( 325 Instruction[] instructions, 326 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals, 327 IDictionary<string, Interval> variableIntervals, IList<string> variables, 328 double minWidth, int maxDepth, ref int currIndex, ref int currDepth, 329 ISymbolicExpressionTree tree) { 330 Interval evaluate() { 331 var ic = 0; 332 IReadOnlyDictionary<string, Interval> readonlyRanges = 333 new ReadOnlyDictionary<string, Interval>(variableIntervals); 334 return Evaluate(instructions, ref ic, nodeIntervals, readonlyRanges); 335 } 336 337 Interval recurse(ref int idx, ref int depth) { 338 return EvaluateRecursive(instructions, nodeIntervals, variableIntervals, variables, minWidth, maxDepth, ref idx, 339 ref depth, tree); 340 } 341 342 343 var v = variables[currIndex]; 344 var x = variableIntervals[v]; 345 if (x.Width < minWidth || currDepth == maxDepth || !MultipleTimes(tree, v)) { 346 if (currIndex + 1 < variables.Count) { 347 currDepth = 0; 348 currIndex++; 349 var z = recurse(ref currIndex, ref currDepth); 350 currIndex--; 351 return z; 352 } 353 354 return evaluate(); 355 } 356 357 var t = x.Split(); 358 var xa = t.Item1; 359 var xb = t.Item2; 360 var d = currDepth; 361 currDepth = d + 1; 362 variableIntervals[v] = xa; 363 var ya = recurse(ref currIndex, ref currDepth); 364 currDepth = d + 1; 365 variableIntervals[v] = xb; 366 var yb = recurse(ref currIndex, ref currDepth); 367 variableIntervals[v] = x; // restore interval 368 return ya | yb; 369 } 370 163 // Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side 164 // Update instructionCounter, whenever Evaluate is called 371 165 public static Interval Evaluate( 372 166 Instruction[] instructions, ref int instructionCounter, 373 167 IDictionary<ISymbolicExpressionTreeNode, Interval> nodeIntervals = null, 374 168 IReadOnlyDictionary<string, Interval> variableIntervals = null) { 375 169 var currentInstr = instructions[instructionCounter]; 376 //Use ref parameter, because the tree will be iterated through recursively from the left-side branch to the right side 377 //Update instructionCounter, whenever Evaluate is called 170 378 171 instructionCounter++; 379 Interval result = null;172 Interval result; 380 173 381 174 switch (currentInstr.opCode) { 382 //Variables, Constants, ...383 175 case OpCodes.Variable: { 384 176 var variableTreeNode = (VariableTreeNode)currentInstr.dynamicNode; 385 177 var weightInterval = new Interval(variableTreeNode.Weight, variableTreeNode.Weight); 386 //var variableInterval = (Interval)currentInstr.data;387 178 388 179 Interval variableInterval; … … 402 193 //Elementary arithmetic rules 403 194 case OpCodes.Add: { 404 //result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 405 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 406 for (var i = 1; i < currentInstr.nArguments; i++) { 407 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 195 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 196 for (var i = 1; i < currentInstr.nArguments; i++) { 408 197 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 409 198 result = Interval.Add(result, argumentInterval); … … 413 202 } 414 203 case OpCodes.Sub: { 415 //result = Evaluate(instructions, ref instructionCounter, nodeIntervals);416 204 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 417 205 if (currentInstr.nArguments == 1) … … 419 207 420 208 for (var i = 1; i < currentInstr.nArguments; i++) { 421 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);422 209 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 423 210 result = Interval.Subtract(result, argumentInterval); … … 427 214 } 428 215 case OpCodes.Mul: { 429 //result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 430 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 431 for (var i = 1; i < currentInstr.nArguments; i++) { 432 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 433 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 216 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 217 for (var i = 1; i < currentInstr.nArguments; i++) { 218 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 434 219 result = Interval.Multiply(result, argumentInterval); 435 220 } … … 438 223 } 439 224 case OpCodes.Div: { 440 //result = Evaluate(instructions, ref instructionCounter, nodeIntervals);441 225 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 442 226 if (currentInstr.nArguments == 1) … … 444 228 445 229 for (var i = 1; i < currentInstr.nArguments; i++) { 446 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);447 230 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 448 231 result = Interval.Divide(result, argumentInterval); … … 451 234 break; 452 235 } 453 //Trigonometric functions454 236 case OpCodes.Sin: { 455 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);456 237 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 457 238 result = Interval.Sine(argumentInterval); … … 459 240 } 460 241 case OpCodes.Cos: { 461 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);462 242 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 463 243 result = Interval.Cosine(argumentInterval); … … 465 245 } 466 246 case OpCodes.Tan: { 467 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);468 247 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 469 248 result = Interval.Tangens(argumentInterval); … … 471 250 } 472 251 case OpCodes.Tanh: { 473 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);474 252 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 475 253 result = Interval.HyperbolicTangent(argumentInterval); 476 254 break; 477 255 } 478 //Exponential functions479 256 case OpCodes.Log: { 480 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);481 257 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 482 258 result = Interval.Logarithm(argumentInterval); … … 484 260 } 485 261 case OpCodes.Exp: { 486 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);487 262 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 488 263 result = Interval.Exponential(argumentInterval); … … 490 265 } 491 266 case OpCodes.Square: { 492 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);493 267 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 494 268 result = Interval.Square(argumentInterval); … … 496 270 } 497 271 case OpCodes.SquareRoot: { 498 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);499 272 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 500 273 result = Interval.SquareRoot(argumentInterval); … … 502 275 } 503 276 case OpCodes.Cube: { 504 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);505 277 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 506 278 result = Interval.Cube(argumentInterval); … … 508 280 } 509 281 case OpCodes.CubeRoot: { 510 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);511 282 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 512 283 result = Interval.CubicRoot(argumentInterval); … … 514 285 } 515 286 case OpCodes.Absolute: { 516 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);517 287 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 518 288 result = Interval.Absolute(argumentInterval); … … 520 290 } 521 291 case OpCodes.AnalyticQuotient: { 522 //result = Evaluate(instructions, ref instructionCounter, nodeIntervals); 523 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 524 for (var i = 1; i < currentInstr.nArguments; i++) { 525 //var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 292 result = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 293 for (var i = 1; i < currentInstr.nArguments; i++) { 526 294 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 527 295 result = Interval.AnalyticalQuotient(result, argumentInterval); … … 538 306 539 307 return result; 540 }541 542 private static bool MultipleTimes(ISymbolicExpressionTree tree, string variable) {543 var varlist = tree.IterateNodesPrefix().OfType<VariableTreeNode>().GroupBy(x => x.VariableName);544 var group = varlist.Select(x => x.Key == variable).Count();545 546 return group > 1;547 }548 549 private static bool ContainsVariableMultipleTimes(ISymbolicExpressionTree tree, out List<String> variables) {550 variables = new List<string>();551 var varlist = tree.IterateNodesPrefix().OfType<VariableTreeNode>().GroupBy(x => x.VariableName);552 foreach (var group in varlist) {553 if (group.Count() > 1) {554 variables.Add(group.Key);555 }556 }557 558 return varlist.Any(group => group.Count() > 1);559 308 } 560 309 -
branches/3073_IA_constraint_splitting_reintegration/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/IntervalUtil.cs
r17881 r17887 7 7 public static class IntervalUtil { 8 8 public static double IntervalConstraintViolation( 9 IntervalConstraint constraint, IBoundsEstimator estimator, IntervalCollection intervalCollection,9 ShapeConstraint constraint, IBoundsEstimator estimator, IntervalCollection intervalCollection, 10 10 ISymbolicExpressionTree solution) { 11 11 var variableRanges = intervalCollection.GetReadonlyDictionary(); … … 14 14 throw new ArgumentException( 15 15 $"The given variable {constraint.Variable} in the constraint does not exist in the model.", 16 nameof( IntervalConstraintsParser));16 nameof(ShapeConstraintsParser)); 17 17 } 18 18 … … 47 47 48 48 public static IEnumerable<double> IntervalConstraintsViolation( 49 IEnumerable< IntervalConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection,49 IEnumerable<ShapeConstraint> constraints, IBoundsEstimator estimator, IntervalCollection intervalCollection, 50 50 ISymbolicExpressionTree solution) { 51 51 return constraints.Select(constraint => IntervalConstraintViolation(constraint, estimator, intervalCollection, solution)).ToList();
Note: See TracChangeset
for help on using the changeset viewer.