Changeset 16727 for branches/2994-AutoDiffForIntervals/Tests
- Timestamp:
- 03/29/19 15:01:47 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2994-AutoDiffForIntervals/Tests/AutoDiffTest.cs
r16696 r16727 76 76 var ds = new Dataset(vars, values); 77 77 var problemData = new RegressionProblemData(ds, vars, "f(x)"); 78 evaluator.Evaluate(t, ds, problemData.TrainingIndices.ToArray(), paramNodes, out double[] train, out double[,] trainJac); 78 var train = new double[problemData.TrainingIndices.Count()]; 79 var trainJac = new double[train.Length, 2]; 80 evaluator.Evaluate(t, ds, problemData.TrainingIndices.ToArray(), paramNodes, train, trainJac); 79 81 Assert.AreEqual(2, train.Length); 80 82 Assert.AreEqual(3, train[0]); … … 86 88 Assert.AreEqual(1, trainJac[1, 1]); 87 89 88 evaluator.Evaluate(t, ds, problemData.TestIndices.ToArray(), paramNodes, out double[] test, out double[,] testJac); 90 var test = new double[problemData.TestIndices.Count()]; 91 var testJac = new double[test.Length, 2]; 92 evaluator.Evaluate(t, ds, problemData.TestIndices.ToArray(), paramNodes, test, testJac); 89 93 Assert.AreEqual(3, test.Length); 90 94 Assert.AreEqual(5, test[0]); … … 124 128 } 125 129 130 { 131 // as discussed with Fabrício 132 var intervals = new Dictionary<string, Interval>(); 133 intervals.Add("x1", new Interval(60.0, 65.0)); 134 intervals.Add("x2", new Interval(30.0, 40.0)); 135 intervals.Add("x3", new Interval(5.0, 10.0)); 136 intervals.Add("x4", new Interval(0.5, 0.8)); 137 intervals.Add("x5", new Interval(0.2, 0.5)); 138 139 var parser = new InfixExpressionParser(); 140 141 var t1 = parser.Parse("x5/x4"); 142 var t2 = parser.Parse("log(x5/x4)"); 143 var t3 = parser.Parse("x3 * log(x5/x4)"); 144 var t4 = parser.Parse("x1*x2*x5"); 145 var t5 = parser.Parse("x4/x5"); 146 var t6 = parser.Parse("sqr(x4/x5)"); 147 var t7 = parser.Parse("(1 - sqr(x4/x5)) "); 148 var t8 = parser.Parse("x1*x2*x5 *(1 - sqr(x4/x5))"); 149 var t9 = parser.Parse("x1*x2*x5 *(1 - sqr(x4/x5)) + x3 * log(x5/x4)"); 150 151 var evaluator = new IntervalEvaluator(); 152 var result = evaluator.Evaluate(t1, intervals); 153 Assert.AreEqual(0.25, result.LowerBound); 154 Assert.AreEqual(1, result.UpperBound); 155 156 result = evaluator.Evaluate(t2, intervals); 157 Assert.AreEqual(-1.386294361, result.LowerBound, 1e-6); 158 Assert.AreEqual(0, result.UpperBound); 159 160 result = evaluator.Evaluate(t3, intervals); 161 Assert.AreEqual(-13.86294361, result.LowerBound, 1e-6); 162 Assert.AreEqual(0, result.UpperBound); 163 164 result = evaluator.Evaluate(t4, intervals); 165 Assert.AreEqual(360, result.LowerBound); 166 Assert.AreEqual(1300, result.UpperBound); 167 168 result = evaluator.Evaluate(t5, intervals); 169 Assert.AreEqual(1, result.LowerBound, 1e-6); 170 Assert.AreEqual(4, result.UpperBound); 171 172 result = evaluator.Evaluate(t6, intervals); 173 Assert.AreEqual(1, result.LowerBound); 174 Assert.AreEqual(16, result.UpperBound); 175 176 result = evaluator.Evaluate(t7, intervals); 177 Assert.AreEqual(-15, result.LowerBound); 178 Assert.AreEqual(0, result.UpperBound); 179 180 result = evaluator.Evaluate(t8, intervals); 181 Assert.AreEqual(-19500, result.LowerBound); 182 Assert.AreEqual(0, result.UpperBound); 183 184 result = evaluator.Evaluate(t9, intervals); 185 Assert.AreEqual(-19513.86294, result.LowerBound, 1e-3); 186 Assert.AreEqual(0, result.UpperBound); 187 188 189 } 190 126 191 } 127 192 }
Note: See TracChangeset
for help on using the changeset viewer.