Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16757


Ignore:
Timestamp:
04/04/19 13:20:34 (6 years ago)
Author:
gkronber
Message:

#2966: fixed bug in interval calculation for cos(x) and added/fixed unit tests for sin and cos

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs

    r16646 r16757  
    167167    }
    168168    public static Interval Cosine(Interval a) {
    169       return Interval.Sine(Interval.Subtract(a, new Interval(Math.PI / 2, Math.PI / 2)));
     169      return Interval.Sine(Interval.Add(a, new Interval(Math.PI / 2, Math.PI / 2)));
    170170    }
    171171    public static Interval Tangens(Interval a) {
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/IntervalInterpreterTest.cs

    r16743 r16757  
    7979      EvaluateTest("sin(x1+x2)", new Interval(-1, 1), variableRanges);
    8080      EvaluateTest("sin(1+2)", new Interval(Math.Sin(3), Math.Sin(3)));
     81
     82      var localVarRanges = new Dictionary<string, Interval>();
     83      localVarRanges.Add("x1", new Interval(-1, 1));
     84      localVarRanges.Add("x2", new Interval(-(Math.PI / 2), 0));
     85      localVarRanges.Add("x3", new Interval(0, Math.PI / 2));
     86      localVarRanges.Add("x4", new Interval(-Math.PI, Math.PI));
     87      localVarRanges.Add("x5", new Interval(Math.PI/4, Math.PI*3.0/4));
     88
     89      EvaluateTest("sin(x1)", new Interval(Math.Sin(-1), Math.Sin(1)), localVarRanges);
     90      EvaluateTest("sin(x2)", new Interval(-1, 0), localVarRanges);
     91      EvaluateTest("sin(x3)", new Interval(0, 1), localVarRanges);
     92      EvaluateTest("sin(x4)", new Interval(-1, 1), localVarRanges);
     93      EvaluateTest("sin(x5)", new Interval(Math.Sin(Math.PI/4), 1), localVarRanges);
    8194    }
    8295
     
    87100      EvaluateTest("cos(x1+x2)", new Interval(-1, 1));
    88101      EvaluateTest("cos(x1+x2)", new Interval(-1, 1), variableRanges);
    89       EvaluateTest("cos(1+2)", new Interval(Math.Sin(3 - Math.PI / 2), Math.Sin(3 - Math.PI / 2)));
     102      EvaluateTest("cos(1+2)", new Interval(Math.Sin(3 + Math.PI / 2), Math.Sin(3 + Math.PI / 2)));
     103
     104      var localVarRanges = new Dictionary<string, Interval>();
     105      localVarRanges.Add("x1", new Interval(-1, 1));
     106      localVarRanges.Add("x2", new Interval(-(Math.PI / 2), 0));
     107      localVarRanges.Add("x3", new Interval(0, Math.PI / 2));
     108      localVarRanges.Add("x4", new Interval(-Math.PI, Math.PI));
     109      localVarRanges.Add("x5", new Interval(Math.PI / 4, Math.PI * 3.0 / 4));
     110
     111      EvaluateTest("cos(x1)", new Interval(Math.Cos(-1), 1), localVarRanges);
     112      EvaluateTest("cos(x2)", new Interval(0, 1), localVarRanges);
     113      EvaluateTest("cos(x3)", new Interval(0, 1), localVarRanges);
     114      EvaluateTest("cos(x4)", new Interval(-1, 1), localVarRanges);
     115      EvaluateTest("cos(x5)", new Interval(Math.Cos(Math.PI *3.0/ 4), Math.Cos(Math.PI/ 4)), localVarRanges);
     116
    90117    }
    91118
Note: See TracChangeset for help on using the changeset viewer.