Changeset 17963
- Timestamp:
- 04/23/21 18:26:45 (4 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs
r17820 r17963 784 784 } else if (IsExp(node)) { 785 785 return MakeExp(MakeProduct(node.GetSubtree(0), MakeConstant(2.0))); // sqr(exp(x)) = exp(2x) 786 } else if (IsSquare(node)) { 787 return MakePower(node.GetSubtree(0), MakeConstant(4)); 786 788 } else if (IsCube(node)) { 787 789 return MakePower(node.GetSubtree(0), MakeConstant(6)); … … 809 811 } else if (IsSquare(node)) { 810 812 return MakePower(node.GetSubtree(0), MakeConstant(6)); 813 } else if (IsCube(node)) { 814 return MakePower(node.GetSubtree(0), MakeConstant(9)); 811 815 } else { 812 816 var cubeNode = cubeSymbol.CreateTreeNode(); -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r17911 r17963 283 283 break; 284 284 } 285 case OpCodes.Power: { 286 var a = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 287 var b = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); 288 // support only integer powers 289 if(b.LowerBound == b.UpperBound && Math.Truncate(b.LowerBound) == b.LowerBound) { 290 result = Interval.Power(a, (int)b.LowerBound); 291 } else { 292 throw new NotSupportedException("Interval is only supported for integer powers"); 293 } 294 break; 295 } 296 285 297 case OpCodes.Absolute: { 286 298 var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals, variableIntervals); … … 329 341 !(n.Symbol is Cube) && 330 342 !(n.Symbol is CubeRoot) && 343 !(n.Symbol is Power) && 331 344 !(n.Symbol is Absolute) && 332 345 !(n.Symbol is AnalyticQuotient) -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs
r17180 r17963 144 144 { typeof(Cosine), OpCodes.Cos }, 145 145 { typeof(Tangent), OpCodes.Tan }, 146 { typeof 146 { typeof(HyperbolicTangent), OpCodes.Tanh}, 147 147 { typeof(Logarithm), OpCodes.Log }, 148 148 { typeof(Exponential), OpCodes.Exp }, -
trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
r17911 r17963 78 78 if (double.IsNegativeInfinity(LowerBound) && double.IsPositiveInfinity(UpperBound)) return true; 79 79 if (other.LowerBound >= LowerBound && other.UpperBound <= UpperBound) return true; 80 80 81 81 return false; 82 82 } … … 97 97 /// </summary> 98 98 public bool IsPositive { 99 get => LowerBound > 0.0; 99 get => LowerBound > 0.0; 100 100 } 101 101 … … 130 130 return false; 131 131 132 return (UpperBound ==other.UpperBound || (double.IsNaN(UpperBound) && double.IsNaN(other.UpperBound)))133 && (LowerBound ==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))); 134 134 } 135 135 … … 238 238 public static Interval Cube(Interval a) { 239 239 return new Interval(Math.Pow(a.LowerBound, 3), Math.Pow(a.UpperBound, 3)); 240 } 241 242 public static Interval Power(Interval a, int b) { 243 if (b < 0) return Power(1.0 / a, -b); // a^(-b) = 1/(a^b) 244 if (b == 0 && (a.Contains(0.0) || a.IsInfiniteOrUndefined)) return new Interval(double.NaN, double.NaN); // 0^0, +/-inf^0 are undefined 245 if (b == 0) return new Interval(1.0, 1.0); // x^0 = 1 246 if (b == 1) return a; 247 if (b % 2 == 0) { 248 // even powers (see x²) 249 if (a.UpperBound <= 0) return new Interval(Math.Pow(a.UpperBound, b), Math.Pow(a.LowerBound, b)); // interval is negative 250 if (a.LowerBound >= 0) return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b)); // interval is positive 251 return new Interval(0, Math.Max(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b))); // interval goes over zero 252 } else { 253 // odd powers (see x³) 254 return new Interval(Math.Pow(a.LowerBound, b), Math.Pow(a.UpperBound, b)); 255 } 240 256 } 241 257
Note: See TracChangeset
for help on using the changeset viewer.