- Timestamp:
- 04/06/21 13:13:32 (4 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 11 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab-3.3/PluginDependenciesTest.cs
r17180 r17928 39 39 [ClassInitialize] 40 40 public static void MyClassInitialize(TestContext testContext) { 41 loadedPlugins = PluginLoader.Assemblies.Where(PluginLoader.IsPluginAssembly).ToDictionary(a => a, GetPluginFromAssembly); 41 try { 42 loadedPlugins = PluginLoader.Assemblies.Where(PluginLoader.IsPluginAssembly).ToDictionary(a => a, GetPluginFromAssembly); 43 } catch (BadImageFormatException e) { 44 var message = string.Join(Environment.NewLine, "Could not load all types. Check if test process architecture is set to x64.", string.Empty, "Exception:", e); 45 Assert.Fail(message); 46 } 47 42 48 pluginNames = loadedPlugins.ToDictionary(a => a.Key.GetName().FullName, a => GetPluginName(a.Value)); 43 49 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab-3.3/Samples/GaussianProcessRegressionSampleTest.cs
r17180 r17928 68 68 gpr.Problem = regProblem; 69 69 70 gpr.CovarianceFunction = new CovarianceSquaredExponentialIso();71 gpr.MeanFunction = new MeanConst();70 gpr.CovarianceFunction = gpr.CovarianceFunctionParameter.ValidValues.OfType<CovarianceSquaredExponentialIso>().First(); 71 gpr.MeanFunction = gpr.MeanFunctionParameter.ValidValues.OfType<MeanConst>().First(); 72 72 gpr.MinimizationIterations = 20; 73 73 gpr.Seed = 0; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/AllArchitectureAlteringOperatorsTest.cs
r17180 r17928 86 86 par1 = (SymbolicExpressionTree)trees.SampleRandom(random).Clone(); 87 87 } while (par0.Length > MAX_TREE_LENGTH || par1.Length > MAX_TREE_LENGTH); 88 var newTree = SubtreeCrossover.Cross(random, par0, par1, 0.9, MAX_TREE_LENGTH, MAX_TREE_DEPTH);88 var newTree = SubtreeCrossover.Cross(random, par0, par1, 1.0, 0.9, MAX_TREE_LENGTH, MAX_TREE_DEPTH); 89 89 stopwatch.Stop(); 90 90 Util.IsValid(newTree); -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4/SubtreeCrossoverTest.cs
r17180 r17928 54 54 var par0 = (ISymbolicExpressionTree)trees.SampleRandom(random).Clone(); 55 55 var par1 = (ISymbolicExpressionTree)trees.SampleRandom(random).Clone(); 56 children[i] = SubtreeCrossover.Cross(random, par0, par1, 0.9, 100, 10);56 children[i] = SubtreeCrossover.Cross(random, par0, par1, 1.0, 0.9, 100, 10); 57 57 } 58 58 trees = children; -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/PersistenceConsistencyChecks.cs
r17019 r17928 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Reflection; 4 5 using HEAL.Attic; 5 6 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 16 17 var dict = new Dictionary<Guid, string>(); 17 18 var duplicates = new Dictionary<string, string>(); 18 // using AppDomain instead of ApplicationManager so that NonDiscoverableTypes are also checked19 foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())) {20 var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);21 if (attr == null)22 continue;23 19 24 foreach (var guid in attr.Guids) { 25 if (!dict.ContainsKey(guid)) { 26 dict.Add(guid, type.FullName); 27 } else { 28 duplicates.Add(type.FullName, dict[guid]); 20 try { 21 // using AppDomain instead of ApplicationManager so that NonDiscoverableTypes are also checked 22 foreach (Type type in AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())) { 23 var attr = StorableTypeAttribute.GetStorableTypeAttribute(type); 24 if (attr == null) 25 continue; 26 27 foreach (var guid in attr.Guids) { 28 if (!dict.ContainsKey(guid)) { 29 dict.Add(guid, type.FullName); 30 } else { 31 duplicates.Add(type.FullName, dict[guid]); 32 } 29 33 } 30 34 } 35 } catch (ReflectionTypeLoadException e) { 36 var loaderExeptions = string.Join("-----" + Environment.NewLine, e.LoaderExceptions.Select(x => x.ToString())); 37 var message = string.Join(Environment.NewLine, "Could not load all types. Check if test process architecture is set to x64.", 38 string.Empty, "Exception:", e, string.Empty, "LoaderExceptions:", loaderExeptions); 39 Assert.Fail(message); 31 40 } 32 41 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis-3.4/IntervalTest.cs
r16646 r17928 1 1 using System; 2 using System.Collections.Generic; 2 3 using Microsoft.VisualStudio.TestTools.UnitTesting; 3 4 … … 11 12 private readonly Interval e = new Interval(4, 6); 12 13 13 [TestMethod] 14 [TestCategory("Problems.DataAnalysis")] 15 [TestProperty("Time", "short")] 16 public void TestIntervalAddOperation() { 14 private void CheckLowerAndUpperBoundOfInterval(Interval expected, Interval calculated) { 15 var lowerBoundExpected = expected.LowerBound; 16 var upperBoundExpected = expected.UpperBound; 17 var lowerBoundCalculated = calculated.LowerBound; 18 var upperBoundCalculated = calculated.UpperBound; 19 20 if(double.IsNaN(lowerBoundExpected) && double.IsNaN(lowerBoundCalculated)) { 21 Assert.IsTrue(double.IsNaN(lowerBoundExpected) && double.IsNaN(lowerBoundCalculated)); 22 } else if (double.IsNaN(upperBoundExpected) && double.IsNaN(upperBoundCalculated)) { 23 Assert.IsTrue(double.IsNaN(upperBoundExpected) && double.IsNaN(upperBoundCalculated)); 24 } else { 25 Assert.AreEqual(lowerBoundExpected, lowerBoundCalculated, 1e-9); 26 Assert.AreEqual(upperBoundExpected, upperBoundCalculated, 1e-9); 27 } 28 } 29 30 [TestMethod] 31 [TestCategory("Problems.DataAnalysis")] 32 [TestProperty("Time", "short")] 33 public void AddIntervalTest() { 17 34 //add [x1,x2] + [y1,y2] = [x1 + y1,x2 + y2] 18 35 … … 28 45 [TestCategory("Problems.DataAnalysis")] 29 46 [TestProperty("Time", "short")] 30 public void TestIntervalSubOperation() {47 public void SubtractIntervalTest() { 31 48 //subtract [x1,x2] − [y1,y2] = [x1 − y2,x2 − y1] 32 49 33 50 //[-1, 1] - [-2, 2] = [-3, 3] 34 Assert.AreEqual<Interval>(Interval.Subtract(a, b), new Interval(-3, 3));51 CheckLowerAndUpperBoundOfInterval(Interval.Subtract(a, b), new Interval(-3, 3)); 35 52 //([-1, 1] - [-2, 2]) - [0, 3] = [-6, 3] 36 Assert.AreEqual<Interval>(Interval.Subtract(Interval.Subtract(a, b), c), new Interval(-6, 3));53 CheckLowerAndUpperBoundOfInterval(Interval.Subtract(Interval.Subtract(a, b), c), new Interval(-6, 3)); 37 54 //([-1, 1] - [0, 3]) - [-2, 2] = [-6, 3] 38 Assert.AreEqual<Interval>(Interval.Subtract(Interval.Subtract(a, c), b), new Interval(-6, 3));39 } 40 41 [TestMethod] 42 [TestCategory("Problems.DataAnalysis")] 43 [TestProperty("Time", "short")] 44 public void TestIntervalMutlipyOperation() {55 CheckLowerAndUpperBoundOfInterval(Interval.Subtract(Interval.Subtract(a, c), b), new Interval(-6, 3)); 56 } 57 58 [TestMethod] 59 [TestCategory("Problems.DataAnalysis")] 60 [TestProperty("Time", "short")] 61 public void MultiplyIntervalTest() { 45 62 //multiply [x1,x2] * [y1,y2] = [min(x1*y1,x1*y2,x2*y1,x2*y2),max(x1*y1,x1*y2,x2*y1,x2*y2)] 46 63 47 64 //[-1, 1] * [-2, 2] = [-2, 2] 48 Assert.AreEqual<Interval>(Interval.Multiply(a, b), new Interval(-2, 2));65 CheckLowerAndUpperBoundOfInterval(Interval.Multiply(a, b), new Interval(-2, 2)); 49 66 //([-1, 1] * [-2, 2]) * [0, 3] = [-6, 6] 50 Assert.AreEqual<Interval>(Interval.Multiply(Interval.Multiply(a, b), c), new Interval(-6, 6));67 CheckLowerAndUpperBoundOfInterval(Interval.Multiply(Interval.Multiply(a, b), c), new Interval(-6, 6)); 51 68 //([-1, 1] * [0, 3]) * [-2, 2] = [-6, 6] 52 Assert.AreEqual<Interval>(Interval.Multiply(Interval.Multiply(a, c), b), new Interval(-6, 6));69 CheckLowerAndUpperBoundOfInterval(Interval.Multiply(Interval.Multiply(a, c), b), new Interval(-6, 6)); 53 70 54 71 // [-2, 0] * [-2, 0] = [0, 4] 55 Assert.AreEqual<Interval>(new Interval(0, 4), Interval.Multiply(new Interval(-2, 0), new Interval(-2, 0)));56 } 57 58 [TestMethod] 59 [TestCategory("Problems.DataAnalysis")] 60 [TestProperty("Time", "short")] 61 public void TestIntervalDivideOperation() {72 CheckLowerAndUpperBoundOfInterval(new Interval(0, 4), Interval.Multiply(new Interval(-2, 0), new Interval(-2, 0))); 73 } 74 75 [TestMethod] 76 [TestCategory("Problems.DataAnalysis")] 77 [TestProperty("Time", "short")] 78 public void DivideIntervalTest() { 62 79 //divide [x1, x2] / [y1, y2] = [x1, x2] * (1/[y1, y2]), where 1 / [y1,y2] = [1 / y2,1 / y1] if 0 not in [y_1, y_2]. 63 80 64 81 //[4, 6] / [1, 3] = [4/3, 6] 65 Assert.AreEqual<Interval>(Interval.Divide(e, d), new Interval(4.0 / 3.0, 6));82 CheckLowerAndUpperBoundOfInterval(Interval.Divide(e, d), new Interval(4.0 / 3.0, 6)); 66 83 //([4, 6] / [1, 3]) / [1, 3] = [4/9, 6] 67 Assert.AreEqual<Interval>(Interval.Divide(Interval.Divide(e, d), d), new Interval(4.0 / 9.0, 6));84 CheckLowerAndUpperBoundOfInterval(Interval.Divide(Interval.Divide(e, d), d), new Interval(4.0 / 9.0, 6)); 68 85 //[4, 6] / [0, 3] = [4/3, +Inf] 69 Assert.AreEqual<Interval>(Interval.Divide(e, c), new Interval(4.0 / 3.0, double.PositiveInfinity));86 CheckLowerAndUpperBoundOfInterval(Interval.Divide(e, c), new Interval(4.0 / 3.0, double.PositiveInfinity)); 70 87 //[-1, 1] / [0, 3] = [+Inf, -Inf] 71 Assert.AreEqual<Interval>(Interval.Divide(a, c), new Interval(double.NegativeInfinity, double.PositiveInfinity));88 CheckLowerAndUpperBoundOfInterval(Interval.Divide(a, c), new Interval(double.NegativeInfinity, double.PositiveInfinity)); 72 89 //Devision by 0 ==> IsInfiniteOrUndefined == true 73 90 Assert.IsTrue(Interval.Divide(e, c).IsInfiniteOrUndefined); 74 91 //Devision by 0 ==> IsInfiniteOrUndefined == true 75 92 Assert.IsTrue(Interval.Divide(a, c).IsInfiniteOrUndefined); 76 Assert.AreEqual<Interval>(Interval.Divide(d, b), new Interval(double.NegativeInfinity, double.PositiveInfinity));77 } 78 79 [TestMethod] 80 [TestCategory("Problems.DataAnalysis")] 81 [TestProperty("Time", "short")] 82 public void TestIntervalSineOperator() {93 CheckLowerAndUpperBoundOfInterval(Interval.Divide(d, b), new Interval(double.NegativeInfinity, double.PositiveInfinity)); 94 } 95 96 [TestMethod] 97 [TestCategory("Problems.DataAnalysis")] 98 [TestProperty("Time", "short")] 99 public void SineIntervalTest() { 83 100 //sine depends on interval 84 101 //sin([0, 2*pi]) = [-1, 1] 85 Assert.AreEqual<Interval>(Interval.Sine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1));102 CheckLowerAndUpperBoundOfInterval(Interval.Sine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1)); 86 103 //sin([-pi/2, pi/2]) = [sin(-pi/2), sin(pi/2)] 87 Assert.AreEqual<Interval>(Interval.Sine(new Interval(-1 * Math.PI / 2, Math.PI / 2)), new Interval(-1, 1));104 CheckLowerAndUpperBoundOfInterval(Interval.Sine(new Interval(-1 * Math.PI / 2, Math.PI / 2)), new Interval(-1, 1)); 88 105 //sin([0, pi/2]) = [sin(0), sin(pi/2)] 89 Assert.AreEqual<Interval>(Interval.Sine(new Interval(0, Math.PI / 2)), new Interval(0, 1));106 CheckLowerAndUpperBoundOfInterval(Interval.Sine(new Interval(0, Math.PI / 2)), new Interval(0, 1)); 90 107 //sin([pi, 3*pi/2]) = [sin(pi), sin(3*pi/2)] 91 Assert.AreEqual<Interval>(Interval.Sine(new Interval(Math.PI, 3 * Math.PI / 2)), new Interval(-1, 0));92 Assert.AreEqual<Interval>(Interval.Sine(new Interval(1, 2)), new Interval(Math.Min(Math.Sin(1), Math.Sin(2)), 1));93 Assert.AreEqual<Interval>(Interval.Sine(new Interval(1, 3)), new Interval(Math.Min(Math.Sin(1), Math.Sin(3)), 1));94 Assert.AreEqual<Interval>(Interval.Sine(new Interval(Math.PI, 5 * Math.PI / 2)), new Interval(-1, 1));95 } 96 97 [TestMethod] 98 [TestCategory("Problems.DataAnalysis")] 99 [TestProperty("Time", "short")] 100 public void TestIntervalCosineOperator() {108 CheckLowerAndUpperBoundOfInterval(Interval.Sine(new Interval(Math.PI, 3 * Math.PI / 2)), new Interval(-1, 0)); 109 CheckLowerAndUpperBoundOfInterval(Interval.Sine(new Interval(1, 2)), new Interval(Math.Min(Math.Sin(1), Math.Sin(2)), 1)); 110 CheckLowerAndUpperBoundOfInterval(Interval.Sine(new Interval(1, 3)), new Interval(Math.Min(Math.Sin(1), Math.Sin(3)), 1)); 111 CheckLowerAndUpperBoundOfInterval(Interval.Sine(new Interval(Math.PI, 5 * Math.PI / 2)), new Interval(-1, 1)); 112 } 113 114 [TestMethod] 115 [TestCategory("Problems.DataAnalysis")] 116 [TestProperty("Time", "short")] 117 public void CosineIntervalTest() { 101 118 //Cosine uses sine Interval.Sine(Interval.Subtract(a, new Interval(Math.PI / 2, Math.PI / 2))); 102 Assert.AreEqual<Interval>(Interval.Cosine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1));103 Assert.AreEqual<Interval>(new Interval(-1, 1), Interval.Cosine(new Interval(Math.PI, 4 * Math.PI / 2)));104 } 105 106 [TestMethod] 107 [TestCategory("Problems.DataAnalysis")] 108 [TestProperty("Time", "short")] 109 public void TestIntervalLogOperator() {119 CheckLowerAndUpperBoundOfInterval(Interval.Cosine(new Interval(0, 2 * Math.PI)), new Interval(-1, 1)); 120 CheckLowerAndUpperBoundOfInterval(new Interval(-1, 1), Interval.Cosine(new Interval(Math.PI, 4 * Math.PI / 2))); 121 } 122 123 [TestMethod] 124 [TestCategory("Problems.DataAnalysis")] 125 [TestProperty("Time", "short")] 126 public void LogIntervalTest() { 110 127 //Log([3, 5]) = [log(3), log(5)] 111 Assert.AreEqual<Interval>(new Interval(Math.Log(3), Math.Log(5)), Interval.Logarithm(new Interval(3, 5)));128 CheckLowerAndUpperBoundOfInterval(new Interval(Math.Log(3), Math.Log(5)), Interval.Logarithm(new Interval(3, 5))); 112 129 //Log([0.5, 1]) = [log(0.5), log(1)] 113 Assert.AreEqual<Interval>(new Interval(Math.Log(0.5), 0), Interval.Logarithm(new Interval(0.5, 1)));130 CheckLowerAndUpperBoundOfInterval(new Interval(Math.Log(0.5), 0), Interval.Logarithm(new Interval(0.5, 1))); 114 131 //Log([-1, 5]) = [NaN, log(5)] 115 132 var result = Interval.Logarithm(new Interval(-1, 5)); 116 Assert.AreEqual<Interval>(new Interval(double.NaN, Math.Log(5)),result);133 CheckLowerAndUpperBoundOfInterval(new Interval(double.NaN, Math.Log(5)),result); 117 134 Assert.IsTrue(result.IsInfiniteOrUndefined); 118 135 } … … 122 139 [TestCategory("Problems.DataAnalysis")] 123 140 [TestProperty("Time", "short")] 124 public void TestIntervalExpOperator() {141 public void ExponentialIntervalTest() { 125 142 //Exp([0, 1]) = [exp(0), exp(1)] 126 Assert.AreEqual<Interval>(new Interval(1, Math.Exp(1)), Interval.Exponential(new Interval(0, 1))); 127 } 128 129 130 [TestMethod] 131 [TestCategory("Problems.DataAnalysis")] 132 [TestProperty("Time", "short")] 133 public void TestIntervalSqrOperator() { 134 Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(1, 2))); 135 Assert.AreEqual<Interval>(new Interval(1, 4), Interval.Square(new Interval(-2, -1))); 136 Assert.AreEqual<Interval>(new Interval(0, 4), Interval.Square(new Interval(-2, 2))); 137 } 138 139 [TestMethod] 140 [TestCategory("Problems.DataAnalysis")] 141 [TestProperty("Time", "short")] 142 public void TestIntervalSqrtOperator() { 143 Assert.AreEqual<Interval>(new Interval(1, 2), Interval.SquareRoot(new Interval(1, 4))); 144 Assert.AreEqual<Interval>(new Interval(double.NaN, double.NaN), Interval.SquareRoot(new Interval(-4, -1))); 145 } 146 147 [TestMethod] 148 [TestCategory("Problems.DataAnalysis")] 149 [TestProperty("Time", "short")] 150 public void TestIntervalCubeOperator() { 151 Assert.AreEqual<Interval>(new Interval(1, 8), Interval.Cube(new Interval(1, 2))); 152 Assert.AreEqual<Interval>(new Interval(-8, -1), Interval.Cube(new Interval(-2, -1))); 153 Assert.AreEqual<Interval>(new Interval(-8, 8), Interval.Cube(new Interval(-2, 2))); 154 } 155 156 [TestMethod] 157 [TestCategory("Problems.DataAnalysis")] 158 [TestProperty("Time", "short")] 159 public void TestIntervalCbrtOperator() { 160 Assert.AreEqual<Interval>(new Interval(1, 2), Interval.CubicRoot(new Interval(1, 8))); 161 Assert.AreEqual<Interval>(new Interval(double.NaN, double.NaN), Interval.CubicRoot(new Interval(-8, -1))); 162 } 143 CheckLowerAndUpperBoundOfInterval(new Interval(1, Math.Exp(1)), Interval.Exponential(new Interval(0, 1))); 144 } 145 146 147 [TestMethod] 148 [TestCategory("Problems.DataAnalysis")] 149 [TestProperty("Time", "short")] 150 public void SquareIntervalTest() { 151 CheckLowerAndUpperBoundOfInterval(new Interval(1, 4), Interval.Square(new Interval(1, 2))); 152 CheckLowerAndUpperBoundOfInterval(new Interval(1, 4), Interval.Square(new Interval(-2, -1))); 153 CheckLowerAndUpperBoundOfInterval(new Interval(0, 4), Interval.Square(new Interval(-2, 2))); 154 } 155 156 [TestMethod] 157 [TestCategory("Problems.DataAnalysis")] 158 [TestProperty("Time", "short")] 159 public void SquarerootIntervalTest() { 160 CheckLowerAndUpperBoundOfInterval(new Interval(-2, 2), Interval.SquareRoot(new Interval(1, 4))); 161 CheckLowerAndUpperBoundOfInterval(new Interval(double.NaN, double.NaN), Interval.SquareRoot(new Interval(-4, -1))); 162 } 163 164 [TestMethod] 165 [TestCategory("Problems.DataAnalysis")] 166 [TestProperty("Time", "short")] 167 public void CubeIntervalTest() { 168 CheckLowerAndUpperBoundOfInterval(new Interval(1, 8), Interval.Cube(new Interval(1, 2))); 169 CheckLowerAndUpperBoundOfInterval(new Interval(-8, -1), Interval.Cube(new Interval(-2, -1))); 170 CheckLowerAndUpperBoundOfInterval(new Interval(-8, 8), Interval.Cube(new Interval(-2, 2))); 171 } 172 173 [TestMethod] 174 [TestCategory("Problems.DataAnalysis")] 175 [TestProperty("Time", "short")] 176 public void CubeRootIntervalTest() { 177 CheckLowerAndUpperBoundOfInterval(new Interval(1, 2), Interval.CubicRoot(new Interval(1, 8))); 178 CheckLowerAndUpperBoundOfInterval(new Interval(-2, -2), Interval.CubicRoot(new Interval(-8, -8))); 179 CheckLowerAndUpperBoundOfInterval(new Interval(-2, 2), Interval.CubicRoot(new Interval(-8, 8))); 180 Assert.AreEqual(new Interval(2, 2), Interval.CubicRoot(new Interval(8, 8))); 181 Assert.AreEqual(new Interval(-Math.Pow(6, 1.0 / 3), 2), Interval.CubicRoot(new Interval(-6, 8))); 182 Assert.AreEqual(new Interval(2, 2), Interval.CubicRoot(new Interval(8, 8))); 183 Assert.AreEqual(new Interval(-2, 0), Interval.CubicRoot(new Interval(-8, 0))); 184 } 185 186 [TestMethod] 187 [TestCategory("Problems.DataAnalysis")] 188 [TestProperty("Time", "short")] 189 public void AbsoluteIntervalTest() { 190 Assert.AreEqual(new Interval(2, 5), Interval.Absolute(new Interval(-5, -2))); 191 Assert.AreEqual(new Interval(2, 5), Interval.Absolute(new Interval(2, 5))); 192 Assert.AreEqual(new Interval(0, 3), Interval.Absolute(new Interval(-3, 0))); 193 Assert.AreEqual(new Interval(0, 5), Interval.Absolute(new Interval(0, 5))); 194 Assert.AreEqual(new Interval(0, 5), Interval.Absolute(new Interval(-2, 5))); 195 } 196 197 [TestMethod] 198 [TestCategory("Problems.DataAnalysis")] 199 [TestProperty("Time", "short")] 200 public void AnalyticalQuotientIntervalTest() { 201 //Analytical Quotient ==> a / sqrt(b^2 + 1) 202 var aPos = new Interval(3, 5); 203 var aZero = new Interval(-3, 5); 204 var aNeg = new Interval(-5, -3); 205 206 var bPos = new Interval(2, 4); 207 var bZero = new Interval(-2, 4); 208 var bNeg = new Interval(-4, -2); 209 210 //Second interval goes over zero 211 //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound), Interval.AnalyticalQuotient(aPos, bZero)); 212 //Assert.AreEqual(new Interval(aZero.LowerBound, aZero.UpperBound), Interval.AnalyticalQuotient(aZero, bZero)); 213 //Assert.AreEqual(new Interval(aNeg.LowerBound, aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bZero)); 214 ////Second interval is positive 215 //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bPos)); 216 //Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bPos)); 217 //Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bPos)); 218 ////Second interval is negative 219 //Assert.AreEqual(new Interval(aPos.LowerBound/Math.Sqrt(17), aPos.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aPos, bNeg)); 220 //Assert.AreEqual(new Interval(aZero.LowerBound/Math.Sqrt(5), aZero.UpperBound/Math.Sqrt(5)), Interval.AnalyticalQuotient(aZero, bNeg)); 221 //Assert.AreEqual(new Interval(aNeg.LowerBound/Math.Sqrt(5), aNeg.UpperBound/Math.Sqrt(17)), Interval.AnalyticalQuotient(aNeg, bNeg)); 222 Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticQuotient(aPos, bZero)); 223 Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticQuotient(aPos, bPos)); 224 Assert.AreEqual(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.AnalyticQuotient(aZero, bNeg)); 225 } 226 227 [TestMethod] 228 [TestCategory("Problems.DataAnalysis")] 229 [TestProperty("Time", "short")] 230 public void IsNegativeIntervalTest() { 231 Assert.IsTrue(new Interval(-2, -1).IsNegative); 232 Assert.IsFalse(new Interval(-2, 0).IsNegative); 233 Assert.IsFalse(new Interval(-2, 2).IsNegative); 234 Assert.IsFalse(new Interval(2, 4).IsNegative); 235 } 236 237 [TestMethod] 238 [TestCategory("Problems.DataAnalysis")] 239 [TestProperty("Time", "short")] 240 public void IsPositiveIntervalTest() { 241 Assert.IsTrue(new Interval(3, 5).IsPositive); 242 Assert.IsFalse(new Interval(0, 5).IsPositive); 243 Assert.IsFalse(new Interval(-1, 5).IsPositive); 244 Assert.IsFalse(new Interval(-5, -2).IsPositive); 245 } 246 247 [TestMethod] 248 [TestCategory("Problems.DataAnalysis")] 249 [TestProperty("Time", "short")] 250 public void IsAlmostIntervalTest() { 251 var negativeLowerBound = -2E-13; 252 var negativeUpperBound = -1E-13; 253 var positiveLowerBound = 3E-13; 254 var positiveUpperBound = 5E-13; 255 256 var negativeInterval = new Interval(negativeLowerBound, negativeUpperBound); 257 var positiveInterval = new Interval(positiveLowerBound, positiveUpperBound); 258 var zeroInterval = new Interval(negativeUpperBound, positiveLowerBound); 259 260 //Check for right-shift of negative interval 261 Assert.AreEqual(negativeUpperBound, negativeInterval.LowerBound); 262 Assert.AreEqual(negativeUpperBound, negativeInterval.UpperBound); 263 //Check for left-shift of positive interval 264 Assert.AreEqual(positiveLowerBound, positiveInterval.LowerBound); 265 Assert.AreEqual(positiveLowerBound, positiveInterval.UpperBound); 266 //Check for setting interval to zero 267 Assert.AreEqual(0, zeroInterval.LowerBound); 268 Assert.AreEqual(0, zeroInterval.UpperBound); 269 } 270 271 [TestMethod] 272 [TestCategory("Problems.DataAnalysis")] 273 [TestProperty("Time", "short")] 274 public void ContaintsTest() { 275 var negativeInterval = new Interval(-10, -5); 276 var positiveInterval = new Interval(5, 10); 277 var overZeroInterval = new Interval(-5, 5); 278 279 //Tests for negative intervals 280 Assert.AreEqual(true, negativeInterval.Contains(new Interval(-9, -7))); 281 Assert.AreEqual(false, negativeInterval.Contains(new Interval(-11, -3))); 282 Assert.AreEqual(false, negativeInterval.Contains(positiveInterval)); 283 Assert.AreEqual(false, negativeInterval.Contains(overZeroInterval)); 284 Assert.AreEqual(true, negativeInterval.Contains(-8)); 285 Assert.AreEqual(false, negativeInterval.Contains(-12)); 286 Assert.AreEqual(false, negativeInterval.Contains(0)); 287 //Testes for positive intervals 288 Assert.AreEqual(true, positiveInterval.Contains(new Interval(6, 10))); 289 Assert.AreEqual(false, positiveInterval.Contains(new Interval(6, 12))); 290 Assert.AreEqual(false, positiveInterval.Contains(negativeInterval)); 291 Assert.AreEqual(false, positiveInterval.Contains(overZeroInterval)); 292 Assert.AreEqual(true, positiveInterval.Contains(7)); 293 Assert.AreEqual(false, positiveInterval.Contains(11)); 294 Assert.AreEqual(false, positiveInterval.Contains(0)); 295 //Tests for over zero intervals 296 Assert.AreEqual(true, overZeroInterval.Contains(new Interval(-3, 3))); 297 Assert.AreEqual(true, overZeroInterval.Contains(new Interval(-4, -1))); 298 Assert.AreEqual(true, overZeroInterval.Contains(new Interval(1, 5))); 299 Assert.AreEqual(false, overZeroInterval.Contains(new Interval(-6, 0))); 300 Assert.AreEqual(false, overZeroInterval.Contains(new Interval(0, 6))); 301 Assert.AreEqual(false, overZeroInterval.Contains(new Interval(-7, 7))); 302 Assert.AreEqual(true, overZeroInterval.Contains(-3)); 303 Assert.AreEqual(true, overZeroInterval.Contains(0)); 304 Assert.AreEqual(true, overZeroInterval.Contains(3)); 305 Assert.AreEqual(false, overZeroInterval.Contains(12)); 306 Assert.AreEqual(false, overZeroInterval.Contains(-7)); 307 } 308 309 [TestMethod] 310 [TestCategory("Problems.DataAnalysis")] 311 [TestProperty("Time", "short")] 312 public void GetIntervalTest() { 313 var values = new List<double>() { -2.5, -9, 2, 7, 0 ,12, 12.4, 12.4, 9.29, 1002, -29.9}; 314 var valuesNan = new List<double>() { double.NaN, 2, 4, 19, -2, -12.2}; 315 var valuesInf = new List<double>() {double.NegativeInfinity, double.PositiveInfinity, 12, 2, -2, -12.2}; 316 317 var valuesInterval = new Interval(-29.9, 1002); 318 var valuesNanInterval = new Interval(double.NaN, double.NaN); 319 var valuesInfInterval = new Interval(double.NegativeInfinity, double.PositiveInfinity); 320 321 322 Assert.AreEqual(valuesInterval, Interval.GetInterval(values)); 323 Assert.AreEqual(valuesNanInterval, Interval.GetInterval(valuesNan)); 324 Assert.AreEqual(valuesInfInterval, Interval.GetInterval(valuesInf)); 325 } 326 327 [TestMethod] 328 [TestCategory("Problems.DataAnalysis")] 329 [TestProperty("Time", "short")] 330 public void GeometricTest() { 331 CheckLowerAndUpperBoundOfInterval(new Interval(-1, -0.936456687290796), Interval.Cosine(new Interval(3, 3.5))); 332 CheckLowerAndUpperBoundOfInterval(new Interval(-1, -0.936456687290796), Interval.Cosine(new Interval(-3.5, -3))); 333 CheckLowerAndUpperBoundOfInterval(new Interval(-1, 1), Interval.Cosine(new Interval(-3.5, 3))); 334 CheckLowerAndUpperBoundOfInterval(new Interval(-0.839071529076452, 0.843853958732493), Interval.Cosine(new Interval(10, 12))); 335 CheckLowerAndUpperBoundOfInterval(new Interval(0.136737218207833, 0.907446781450197), Interval.Cosine(new Interval(13, 14))); 336 CheckLowerAndUpperBoundOfInterval(new Interval(-0.839071529076452, 1), Interval.Cosine(new Interval(10, 14))); 337 CheckLowerAndUpperBoundOfInterval(new Interval(-1, 0.136737218207833), Interval.Cosine(new Interval(14, 16))); 338 CheckLowerAndUpperBoundOfInterval(new Interval(-0.839071529076452, 0.004425697988051), Interval.Cosine(new Interval(-11, -10))); 339 CheckLowerAndUpperBoundOfInterval(new Interval(0.136737218207833, 0.907446781450197), Interval.Cosine(new Interval(-14, -13))); 340 CheckLowerAndUpperBoundOfInterval(new Interval(-1, 0.136737218207833), Interval.Cosine(new Interval(-16, -14))); 341 CheckLowerAndUpperBoundOfInterval(new Interval(0.101585703696621, 1), Interval.Cosine(new Interval(-102, -100))); 342 CheckLowerAndUpperBoundOfInterval(new Interval(-1, 1), Interval.Cosine(new Interval(4.6e15, 4.7e15))); 343 CheckLowerAndUpperBoundOfInterval(new Interval(0.87758256189037265, 0.87758256189037276), Interval.Cosine(new Interval(0.5, 0.5))); 344 CheckLowerAndUpperBoundOfInterval(new Interval(-0.09904103659872825, 0.8775825618903728), Interval.Cosine(new Interval(0.5, 1.67))); 345 CheckLowerAndUpperBoundOfInterval(new Interval(-1.0, 0.77556587851025016), Interval.Cosine(new Interval(2.1, 5.6))); 346 CheckLowerAndUpperBoundOfInterval(new Interval(-1.0, 1.0), Interval.Cosine(new Interval(0.5, 8.5))); 347 CheckLowerAndUpperBoundOfInterval(new Interval(-1.0, -0.09904103659872801), Interval.Cosine(new Interval(1.67, 3.2))); 348 349 CheckLowerAndUpperBoundOfInterval(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(double.NegativeInfinity, double.PositiveInfinity))); 350 CheckLowerAndUpperBoundOfInterval(new Interval(0, 1.55740772465490223051), Interval.Tangens(new Interval(0, 1))); 351 CheckLowerAndUpperBoundOfInterval(new Interval(-1.55740772465490223051, 0), Interval.Tangens(new Interval(-1, 0))); 352 CheckLowerAndUpperBoundOfInterval(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(-2, -1))); 353 CheckLowerAndUpperBoundOfInterval(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(202, 203))); 354 CheckLowerAndUpperBoundOfInterval(new Interval(0.54630248984379048, 0.5463024898437906), Interval.Tangens(new Interval(0.5, 0.5))); 355 CheckLowerAndUpperBoundOfInterval(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval(0.5, 356 1.67))); 357 358 CheckLowerAndUpperBoundOfInterval(new Interval(double.NegativeInfinity, double.PositiveInfinity), Interval.Tangens(new Interval( 359 6.638314112824137, 8.38263151220128))); 360 361 CheckLowerAndUpperBoundOfInterval(new Interval(0.47942553860420295, 0.47942553860420301), Interval.Sine(new Interval(0.5, 0.5))); 362 CheckLowerAndUpperBoundOfInterval(new Interval(4.7942553860420295e-01, 1.0), Interval.Sine(new Interval(0.5, 1.67))); 363 CheckLowerAndUpperBoundOfInterval(new Interval(-5.8374143427580093e-02, 9.9508334981018021e-01), Interval.Sine(new Interval(1.67, 364 3.2))); 365 CheckLowerAndUpperBoundOfInterval(new Interval(-1.0, 0.863209366648874), Interval.Sine(new Interval(2.1, 5.6))); 366 CheckLowerAndUpperBoundOfInterval(new Interval(-1.0, 1.0), Interval.Sine(new Interval(0.5, 8.5))); 367 CheckLowerAndUpperBoundOfInterval(new Interval(-1.0, 0.9775301176650971), Interval.Sine(new Interval(-4.5, 0.1))); 368 CheckLowerAndUpperBoundOfInterval(new Interval(-1.0, 1.0), Interval.Sine(new Interval(1.3, 6.3))); 369 } 370 371 [TestMethod] 372 [TestCategory("Problems.DataAnalysis")] 373 [TestProperty("Time", "short")] 374 public void EqualsTest() { 375 var interval1 = new Interval(0, 12); 376 var interval2 = new Interval(-12, 8); 377 var interval3 = new Interval(double.NegativeInfinity, 0); 378 379 Assert.AreEqual(true, interval1.Equals(new Interval(0, 12))); 380 Assert.AreEqual(false, interval1.Equals(interval2)); 381 Assert.AreEqual(true, interval3 == new Interval(double.NegativeInfinity, 0)); 382 Assert.AreEqual(true, interval1 != interval2); 383 Assert.AreEqual(false, interval2 == interval3); 384 Assert.AreEqual(false, interval1 != new Interval(0, 12)); 385 } 386 //[TestMethod] 387 //[TestCategory("Problems.DataAnalysis")] 388 //[TestProperty("Time", "short")] 389 //public void RootTest() { 390 // var posInterval = new Interval(3, 5); 391 // var negInterval = new Interval(-6, -2); 392 // var posIntervalConst = new Interval(5, 5); 393 // var negIntervalConst = new Interval(-3, -3); 394 // var zeroIntervalConst = new Interval(0, 0); 395 // var zeroPosInterval = new Interval(0, 2); 396 // var zeroNegInterval = new Interval(-2, 0); 397 398 // var posRoot = new Interval(4, 4); 399 // var negRoot = new Interval(-4, -4); 400 // var zeroRoot = new Interval(0, 0); 401 // var oneRoot = new Interval(1, 1); 402 403 // Assert.AreEqual(Interval.Root(posInterval, posRoot), new Interval(Math.Pow(3, (1.0/4)), Math.Pow(5, (1.0/4)))); 404 // Assert.AreEqual(Interval.Root(posInterval, negRoot), new Interval(Math.Pow(5, -(1.0/4)), Math.Pow(3, -(1.0/4)))); 405 // Assert.AreEqual(Interval.Root(posInterval, zeroRoot), new Interval(double.NaN, double.NaN)); 406 // Assert.AreEqual(Interval.Root(posInterval, oneRoot), new Interval(3, 5)); 407 408 // Assert.AreEqual(Interval.Root(negInterval, posRoot), new Interval(Math.Pow(-6, (1.0 / 4)), Math.Pow(-2, (1.0 / 4)))); 409 // Assert.AreEqual(Interval.Root(negInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), Math.Pow(-6, -(1.0 / 4)))); 410 // Assert.AreEqual(Interval.Root(negInterval, zeroRoot), new Interval(double.NaN, double.NaN)); 411 // Assert.AreEqual(Interval.Root(negInterval, oneRoot), new Interval(-6, -2)); 412 413 // Assert.AreEqual(Interval.Root(posIntervalConst, posRoot), new Interval(Math.Pow(5, (1.0 / 4)), Math.Pow(5, (1.0 / 4)))); 414 // Assert.AreEqual(Interval.Root(posIntervalConst, negRoot), new Interval(Math.Pow(5, -(1.0 / 4)), Math.Pow(5, -(1.0 / 4)))); 415 // Assert.AreEqual(Interval.Root(posIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN)); 416 // Assert.AreEqual(Interval.Root(posIntervalConst, oneRoot), new Interval(5, 5)); 417 418 // Assert.AreEqual(Interval.Root(negIntervalConst, posRoot), new Interval(Math.Pow(-3, (1.0 / 4)), Math.Pow(-3, (1.0 / 4)))); 419 // Assert.AreEqual(Interval.Root(negIntervalConst, negRoot), new Interval(Math.Pow(-3, -(1.0 / 4)), Math.Pow(-3, -(1.0 / 4)))); 420 // Assert.AreEqual(Interval.Root(negIntervalConst, zeroRoot), new Interval(double.NaN, double.NaN)); 421 // Assert.AreEqual(Interval.Root(negIntervalConst, oneRoot), new Interval(-3, -3)); 422 423 // Assert.AreEqual(Interval.Root(zeroIntervalConst, posRoot), new Interval(0, 0)); 424 // //Compley Infinity https://www.wolframalpha.com/input/?i=root%28-4%2C+0%29 425 // Assert.AreEqual(Interval.Root(zeroIntervalConst, negRoot), new Interval(double.PositiveInfinity, double.PositiveInfinity)); 426 // Assert.AreEqual(Interval.Root(zeroIntervalConst, zeroRoot), new Interval(0, 0)); 427 // Assert.AreEqual(Interval.Root(zeroIntervalConst, oneRoot), new Interval(0, 0)); 428 429 // Assert.AreEqual(Interval.Root(zeroPosInterval, posRoot), new Interval(0, Math.Pow(2, (1.0 / 4)))); 430 // //Check for complex infinity 431 // Assert.AreEqual(Interval.Root(zeroPosInterval, negRoot), new Interval(Math.Pow(2, -(1.0 / 4)), double.PositiveInfinity)); 432 // Assert.AreEqual(Interval.Root(zeroPosInterval, zeroRoot), new Interval(0, 0)); 433 // Assert.AreEqual(Interval.Root(zeroPosInterval, oneRoot), new Interval(0, 2)); 434 435 // Assert.AreEqual(Interval.Root(zeroNegInterval, posRoot), new Interval(Math.Pow(-2, (1.0 / 4)),0)); 436 // //Check for complex infinity 437 // Assert.AreEqual(Interval.Root(zeroNegInterval, negRoot), new Interval(Math.Pow(-2, -(1.0 / 4)), double.PositiveInfinity)); 438 // Assert.AreEqual(Interval.Root(zeroNegInterval, zeroRoot), new Interval(double.NaN, double.NaN)); 439 // Assert.AreEqual(Interval.Root(zeroNegInterval, oneRoot), new Interval(-2, 0)); 440 //} 163 441 } 164 442 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/IntervalInterpreterTest.cs
r16769 r17928 40 40 Interval result; 41 41 if (variableRanges == null) 42 result = interpreter.GetSymbolicExpressionTreeInterval(tree, problemData.Dataset, problemData.AllIndices);42 result = interpreter.GetSymbolicExpressionTreeInterval(tree, problemData.Dataset, rows:problemData.AllIndices); 43 43 else 44 44 result = interpreter.GetSymbolicExpressionTreeInterval(tree, variableRanges); … … 163 163 } 164 164 165 [TestMethod]166 [TestCategory("Problems.DataAnalysis.Symbolic")]167 [TestProperty("Time", "short")]168 public void TestIntervalInterpreterExpRoot() {169 EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(6)), Math.Exp(Math.Sqrt(48))));170 EvaluateTest("exp(root(x1*x2, 2))", new Interval(Math.Exp(Math.Sqrt(4)), Math.Exp(Math.Sqrt(60))), variableRanges);171 }172 173 [TestMethod]174 [TestCategory("Problems.DataAnalysis.Symbolic")]175 [TestProperty("Time", "short")]176 public void TestIntervalInterpreterPower() {177 EvaluateTest("pow(x1, 2)", new Interval(Math.Pow(3, 1), Math.Pow(8, 3)));178 }179 165 } 180 166 } -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4/SymbolicDataAnalysisExpressionTreeSimplifierTest.cs
r17180 r17928 99 99 #region root rules 100 100 // cancellation 101 AssertEqualAfterSimplification("(root (variable 2.0 a) 0.0)", " 1.0");101 AssertEqualAfterSimplification("(root (variable 2.0 a) 0.0)", "NaN"); 102 102 // fixed point 103 103 AssertEqualAfterSimplification("(root (variable 2.0 a) 1.0)", "(variable 2.0 a)"); … … 269 269 270 270 #endregion 271 272 #region do not drop subtrees with small weights 273 AssertEqualAfterSimplification("(* 1e-14 (variable 1.0 a))", "(variable 1e-14 a)"); 274 AssertEqualAfterSimplification("(+ (variable 1.0 a) 1e-14)", 275 "(+ (variable 1.0 a) 1e-14)"); 276 // a scenario where a term with small weight can have large effect 277 AssertEqualAfterSimplification("(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)", 278 "(+ (* (pow (variable 1.0 a) 10) 1e-14) 1.0)"); 279 // a test case (from ticket #2985) 280 AssertEqualAfterSimplification("(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)", 281 "(+ (* (exp (variable 3.5861E+001 a)) 5.5606E-016) 5.9323E-002)"); 282 #endregion 271 283 } 272 284 -
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Tests/HeuristicLab.Tests.csproj
r17353 r17928 498 498 <Compile Include="HeuristicLab-3.3\ToStringTest.cs" /> 499 499 <Compile Include="HeuristicLab.Algorithms.DataAnalysis-3.4\GradientBoostingTest.cs" /> 500 <Compile Include="HeuristicLab.Algorithms.DataAnalysis-3.4\CrossValidationTest.cs" /> 500 501 <Compile Include="HeuristicLab.Algorithms.DataAnalysis-3.4\NcaAlgorithmTest.cs" /> 501 502 <Compile Include="HeuristicLab.Algorithms.DataAnalysis-3.4\SupportVectorMachineTest.cs" />
Note: See TracChangeset
for help on using the changeset viewer.