- Timestamp:
- 11/25/19 09:19:26 (5 years ago)
- Location:
- branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis merged: 17305,17348,17350
- Property svn:mergeinfo changed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis/3.4 merged: 17305,17348,17350
- Property svn:mergeinfo changed
-
branches/2971_named_intervals/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval/Interval.cs
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs merged: 17348,17350
r17313 r17368 37 37 protected Interval(StorableConstructorFlag _) { } 38 38 39 /// <summary> 40 /// Creates an interval with given bounds, where lower bound must be smaller than 41 /// the upper bound. Floating point precision errors trough calculations are fixed by, 42 /// checking if the intervals are almost the same (E-12). If this is the case, the bounds 43 /// will be set to the bound closer to zero. 44 /// </summary> 45 /// <param name="lowerBound">Lower bound of the interval</param> 46 /// <param name="upperBound">Upper bound of the interval</param> 39 47 public Interval(double lowerBound, double upperBound) { 40 //TODO Handle floating point issues where lowerbound is bigger than upperbound in the nth decimal place 48 if (lowerBound.IsAlmost(upperBound)) { 49 //If the bounds go over zero 50 if (lowerBound <= 0 && upperBound >= 0) { 51 lowerBound = 0.0; 52 upperBound = 0.0; 53 //Interval is negative 54 } else if (upperBound < 0) { 55 lowerBound = upperBound; 56 //Interval is positive 57 } else { 58 upperBound = lowerBound; 59 } 60 } 61 41 62 if (lowerBound > upperBound) 42 63 throw new ArgumentException("lowerBound must be smaller than or equal to upperBound."); … … 98 119 } 99 120 121 /// <summary> 122 /// True if the interval is positive without zero 123 /// </summary> 124 public bool IsPositive { 125 get => LowerBound > 0.0; 126 } 127 128 /// <summary> 129 /// True if the interval is negative without zero 130 /// </summary> 131 public bool IsNegative { 132 get => UpperBound < 0.0; 133 } 134 100 135 public static Interval GetInterval(IEnumerable<double> values) { 101 136 if (values == null) throw new ArgumentNullException("values"); … … 166 201 } 167 202 168 // mkommend:Division by intervals containing 0 is implemented as defined in203 //Division by intervals containing 0 is implemented as defined in 169 204 //http://en.wikipedia.org/wiki/Interval_arithmetic 170 205 public static Interval Divide(Interval a, Interval b) { … … 209 244 public static Interval Tangens(Interval a) { 210 245 return Interval.Divide(Interval.Sine(a), Interval.Cosine(a)); 211 } 246 } 212 247 public static Interval HyperbolicTangent(Interval a) { 213 248 return new Interval(Math.Tanh(a.LowerBound), Math.Tanh(a.UpperBound)); … … 244 279 if (a.UpperBound <= 0) return new Interval(a.UpperBound * a.UpperBound, a.LowerBound * a.LowerBound); // interval is negative 245 280 else if (a.LowerBound >= 0) return new Interval(a.LowerBound * a.LowerBound, a.UpperBound * a.UpperBound); // interval is positive 246 else return new Interval(0, Math.Max(a.LowerBound *a.LowerBound, a.UpperBound*a.UpperBound)); // interval goes over zero281 else return new Interval(0, Math.Max(a.LowerBound * a.LowerBound, a.UpperBound * a.UpperBound)); // interval goes over zero 247 282 } 248 283 … … 273 308 var absLower = Math.Abs(a.LowerBound); 274 309 var absUpper = Math.Abs(a.UpperBound); 275 return new Interval(Math.Min(absLower, absUpper), Math.Max(absLower, absUpper)); 310 var min = Math.Min(absLower, absUpper); 311 var max = Math.Max(absLower, absUpper); 312 313 if (a.Contains(0.0)) { 314 min = 0.0; 315 } 316 317 return new Interval(min, max); 318 } 319 320 public static Interval AnalyticalQuotient(Interval a, Interval b) { 321 var dividend = a; 322 var divisor = Add(Square(b), new Interval(1.0, 1.0)); 323 divisor = SquareRoot(divisor); 324 325 var quotient = Divide(dividend, divisor); 326 return quotient; 276 327 } 277 328 #endregion - Property svn:mergeinfo changed
Note: See TracChangeset
for help on using the changeset viewer.