Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17562


Ignore:
Timestamp:
05/27/20 07:34:25 (4 years ago)
Author:
chaider
Message:

#2971 removed root/power symbols

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  
    234234            break;
    235235          }
    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           }
    244236        case OpCodes.Square: {
    245237            var argumentInterval = Evaluate(instructions, ref instructionCounter, nodeIntervals);
    246238            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             }
    255239            break;
    256240          }
     
    310294          !(n.Symbol is Logarithm) &&
    311295          !(n.Symbol is Exponential) &&
    312           !(n.Symbol is Power) &&
    313296          !(n.Symbol is Square) &&
    314           !(n.Symbol is Root) &&
    315297          !(n.Symbol is SquareRoot) &&
    316298          !(n.Symbol is Cube) &&
  • branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs

    r17549 r17562  
    7878    }
    7979
    80 
    81 
    8280    public override string ToString() {
    8381      return "Interval: [" + LowerBound + ", " + UpperBound + "]";
     
    228226    }
    229227
    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 
    250228    public static Interval Square(Interval a) {
    251229      if (a.UpperBound <= 0) return new Interval(a.UpperBound * a.UpperBound, a.LowerBound * a.LowerBound);     // interval is negative
     
    258236    }
    259237
    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>
    287244    public static Interval SquareRoot(Interval a) {
    288245      if (a.LowerBound < 0) return new Interval(double.NaN, double.NaN);
Note: See TracChangeset for help on using the changeset viewer.