Changeset 17562
 Timestamp:
 05/27/20 07:34:25 (4 years ago)
 Location:
 branches/2971_named_intervals
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r17537 r17562 234 234 break; 235 235 } 236 case OpCodes.Power: {237 result = Evaluate(instructions, ref instructionCounter, nodeIntervals);238 for (int i = 1; i < currentInstr.nArguments; i++) {239 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);240 result = Interval.Power(result, argumentInterval);241 }242 break;243 }244 236 case OpCodes.Square: { 245 237 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals); 246 238 result = Interval.Square(argumentInterval); 247 break;248 }249 case OpCodes.Root: {250 result = Evaluate(instructions, ref instructionCounter, nodeIntervals);251 for (int i = 1; i < currentInstr.nArguments; i++) {252 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);253 result = Interval.Root(result, argumentInterval);254 }255 239 break; 256 240 } … … 310 294 !(n.Symbol is Logarithm) && 311 295 !(n.Symbol is Exponential) && 312 !(n.Symbol is Power) &&313 296 !(n.Symbol is Square) && 314 !(n.Symbol is Root) &&315 297 !(n.Symbol is SquareRoot) && 316 298 !(n.Symbol is Cube) && 
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
r17549 r17562 78 78 } 79 79 80 81 82 80 public override string ToString() { 83 81 return "Interval: [" + LowerBound + ", " + UpperBound + "]"; … … 228 226 } 229 227 230 public static Interval Power(Interval a, Interval b) {231 if (a.Contains(0.0) && b.LowerBound < 0) return new Interval(double.NaN, double.NaN);232 233 int bLower = (int)Math.Round(b.LowerBound);234 int bUpper = (int)Math.Round(b.UpperBound);235 236 List<double> powerValues = new List<double>();237 powerValues.Add(Math.Pow(a.UpperBound, bUpper));238 powerValues.Add(Math.Pow(a.UpperBound, bUpper  1));239 powerValues.Add(Math.Pow(a.UpperBound, bLower));240 powerValues.Add(Math.Pow(a.UpperBound, bLower + 1));241 242 powerValues.Add(Math.Pow(a.LowerBound, bUpper));243 powerValues.Add(Math.Pow(a.LowerBound, bUpper  1));244 powerValues.Add(Math.Pow(a.LowerBound, bLower));245 powerValues.Add(Math.Pow(a.LowerBound, bLower + 1));246 247 return new Interval(powerValues.Min(), powerValues.Max());248 }249 250 228 public static Interval Square(Interval a) { 251 229 if (a.UpperBound <= 0) return new Interval(a.UpperBound * a.UpperBound, a.LowerBound * a.LowerBound); // interval is negative … … 258 236 } 259 237 260 public static Interval Root(Interval a, Interval b) { 261 int lower = (int)Math.Round(b.LowerBound); 262 int higher = (int)Math.Round(b.UpperBound); 263 264 //Root root(0,0) = 0 265 if (a.LowerBound == 0 && b.LowerBound == 0 && lower == 0 && higher == 0) 266 return new Interval(0, 0); 267 268 //Root is zero ==> undefined ==> 5^(1.0/0) 269 if (higher == 0  lower == 0) 270 return new Interval(double.NaN, double.NaN); 271 272 if (lower < 0  higher < 0) { 273 List<double> vals = new List<double>(); 274 275 vals.Add(Math.Pow(a.LowerBound, 1.0 / lower)); 276 vals.Add(Math.Pow(a.LowerBound, 1.0 / higher)); 277 278 vals.Add(Math.Pow(a.UpperBound, 1.0 / lower)); 279 vals.Add(Math.Pow(a.UpperBound, 1.0 / higher)); 280 281 return new Interval(vals.Min(), vals.Max()); 282 } 283 284 return new Interval(Math.Pow(a.LowerBound, 1.0 / higher), Math.Pow(a.UpperBound, 1.0 / lower)); 285 } 286 238 /// <summary> 239 /// Calculates the principal square root of a given interval. Discards the second possible result of root, because 240 /// all interpreters just calculate the positive principal root. 241 /// </summary> 242 /// <param name="a">Interval to build square root from.</param> 243 /// <returns></returns> 287 244 public static Interval SquareRoot(Interval a) { 288 245 if (a.LowerBound < 0) return new Interval(double.NaN, double.NaN);
Note: See TracChangeset
for help on using the changeset viewer.