Changeset 17348


Ignore:
Timestamp:
11/04/19 14:40:48 (11 days ago)
Author:
chaider
Message:

#3032 Added analytical quotient for intervals

Location:
trunk
Files:
2 edited

Legend:

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

    r17305 r17348  
    237237      return new Interval(Math.Min(absLower, absUpper), Math.Max(absLower, absUpper));
    238238    }
     239
     240    public static Interval AnalyticalQuotient(Interval a, Interval b) {
     241      if (b.LowerBound <= 0 && b.UpperBound >= 0) //Second interval goes over zero or is zero
     242        return new Interval(a.LowerBound, a.UpperBound);
     243
     244      var values = new List<double> {
     245        a.LowerBound / Math.Sqrt(Math.Pow(b.LowerBound, 2) + 1),
     246        a.LowerBound / Math.Sqrt(Math.Pow(b.UpperBound, 2) + 1),
     247        a.UpperBound / Math.Sqrt(Math.Pow(b.LowerBound, 2) + 1),
     248        a.UpperBound / Math.Sqrt(Math.Pow(b.UpperBound, 2) + 1)
     249      };
     250
     251      return new Interval(values.Min(), values.Max());
     252    }
    239253    #endregion
    240254  }
  • trunk/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/IntervalTest.cs

    r17306 r17348  
    182182      Assert.AreEqual(new Interval(0, 2), Interval.Absolute(new Interval(0, 2)));
    183183    }
     184
     185    [TestMethod]
     186    [TestCategory("Problems.DataAnalysis")]
     187    [TestProperty("Time", "short")]
     188    public void TestIntervalAnalyticalQuotient() {
     189      //Second interval goes over zero
     190      Assert.AreEqual(new Interval(-4, 2), Interval.AnalyticalQuotient(new Interval(-4, 2), new Interval(0, 5)));
     191      Assert.AreEqual(new Interval(-4, 2), Interval.AnalyticalQuotient(new Interval(-4, 2), new Interval(-4, 0)));
     192      Assert.AreEqual(new Interval(-4, 2), Interval.AnalyticalQuotient(new Interval(-4, 2), new Interval(-2, 4)));
     193      Assert.AreEqual(new Interval(-4, -2), Interval.AnalyticalQuotient(new Interval(-4, -2), new Interval(0, 5)));
     194      Assert.AreEqual(new Interval(-4, -2), Interval.AnalyticalQuotient(new Interval(-4, -2), new Interval(-4, 0)));
     195      Assert.AreEqual(new Interval(-4, -2), Interval.AnalyticalQuotient(new Interval(-4, -2), new Interval(-2, 4)));
     196      Assert.AreEqual(new Interval(3, 7), Interval.AnalyticalQuotient(new Interval(3, 7), new Interval(0, 5)));
     197      Assert.AreEqual(new Interval(3, 7), Interval.AnalyticalQuotient(new Interval(3, 7), new Interval(-4, 0)));
     198      Assert.AreEqual(new Interval(3, 7), Interval.AnalyticalQuotient(new Interval(3, 7), new Interval(-2, 4)));
     199      Assert.AreEqual(new Interval(0, 0), Interval.AnalyticalQuotient(new Interval(0, 0), new Interval(0, 5)));
     200      Assert.AreEqual(new Interval(-4, -4), Interval.AnalyticalQuotient(new Interval(-4, -4), new Interval(-4, 0)));
     201      Assert.AreEqual(new Interval(4, 4), Interval.AnalyticalQuotient(new Interval(4, 4), new Interval(-2, 4)));
     202
     203      //First interval goes over zero
     204      Assert.AreEqual(new Interval(-2.0/Math.Sqrt(5), 5.0 / Math.Sqrt(5)), Interval.AnalyticalQuotient(new Interval(-2, 5), new Interval(-5, -2)));
     205      Assert.AreEqual(new Interval(-2.0 / Math.Sqrt(5), 5.0 / Math.Sqrt(5)), Interval.AnalyticalQuotient(new Interval(-2, 5), new Interval(2, 5)));
     206      Assert.AreEqual(new Interval(2.0/Math.Sqrt(26), 5.0/Math.Sqrt(5)), Interval.AnalyticalQuotient(new Interval(2, 5), new Interval(-5, -2)));
     207      Assert.AreEqual(new Interval(2.0 / Math.Sqrt(26), 5.0 / Math.Sqrt(5)), Interval.AnalyticalQuotient(new Interval(2, 5), new Interval(2, 5)));
     208      Assert.AreEqual(new Interval(-5.0/Math.Sqrt(5), -2.0/Math.Sqrt(26)), Interval.AnalyticalQuotient(new Interval(-5, -2), new Interval(-5, -2)));
     209      Assert.AreEqual(new Interval(-5.0 / Math.Sqrt(5), -2.0 / Math.Sqrt(26)), Interval.AnalyticalQuotient(new Interval(-5, -2), new Interval(2, 5)));
     210    }
    184211  }
    185212}
Note: See TracChangeset for help on using the changeset viewer.