Changeset 16690 for branches/2974_Constants_Optimization/UnitTests
- Timestamp:
- 03/16/19 12:51:33 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2974_Constants_Optimization/UnitTests/ConstantsOptimizationTests.cs
r16507 r16690 47 47 var new_result = LMConstantsOptimizer.OptimizeConstants(new_optimizedTree, problemData.Dataset, problemData.TargetVariable, problemData.TrainingIndices, applyLinearScaling, maxIterations: 10); 48 48 49 //check R² values 50 //Assert.AreEqual(old_result, new_result); 51 52 //check numeric values of constants 49 // extract constants 53 50 var old_constants = Util.ExtractConstants(old_optimizedTree, applyLinearScaling); 54 51 var new_constants = Util.ExtractConstants(new_optimizedTree, applyLinearScaling); 55 //Assert.IsTrue(old_constants.SequenceEqual(new_constants)); 56 52 53 { 54 // consistency with old ConstOpt style 55 var initalR2 = SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.Calculate( 56 new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), 57 tree, double.MinValue, double.MaxValue, problemData, problemData.TrainingIndices, applyLinearScaling); 58 59 // LMConstantsOptimizer returns 0 if optimization was not successful 60 if (initalR2 - new_result > 0.001) { 61 new_result = initalR2; 62 new_constants = old_constants; 63 } 64 } 65 66 //check R² values 67 Assert.AreEqual(old_result, new_result, 1E-6); 68 69 //check numeric values of constants 57 70 for (int i = 0; i < old_constants.Length; i++) { 58 Assert.AreEqual(old_constants[i], new_constants[i], 0.00000001); 71 if (old_constants[i] == 0) { 72 Assert.AreEqual(old_constants[i], new_constants[i], 1E-8); // check absolute error 73 } else { 74 Assert.AreEqual(0.0, 1.0 - new_constants[i] / old_constants[i], 1E-6); // check percentual error 75 } 59 76 } 60 77 } … … 147 164 [TestProperty("Time", "short")] 148 165 public void ConstantsOptimizationTest_Nguyen07() { 149 var problemData = new NguyenFunction Five(seed).GenerateRegressionData();166 var problemData = new NguyenFunctionSeven(seed).GenerateRegressionData(); 150 167 var modelTemplate = "({0}) * LOG(({1})*X + ({2})) + ({3}) * LOG(({4})*X*X + ({5})) + ({6})"; 151 168 … … 162 179 modelString = string.Format(modelTemplate, constants); 163 180 modelTree = new InfixExpressionParser().Parse(modelString); 181 // This test fails not because of a problem in ConstOpt but because of the code in 182 // OnlinePearsonsRCalculator 183 // double xVar = sxCalculator.PopulationVariance; 184 // double yVar = syCalculator.PopulationVariance; 185 // if (xVar.IsAlmost(0.0) || yVar.IsAlmost(0.0)) { 186 // return 0.0; 187 // } else { ... 188 // PopulationVariance might become close to zero, but the result of cov / (sqrt(xvar) * sqrt(yvar) might still be correct. 189 // Currently, we just return 0. Which means that we reset optimized constants to initial values 164 190 CompareConstantsOptimizationResults(problemData, modelTree); 165 191 … … 223 249 CompareConstantsOptimizationResults(problemData, modelTree); 224 250 } 251 252 [TestInitialize] 253 public void InitEnvironment() { 254 System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture; 255 } 225 256 } 226 257 }
Note: See TracChangeset
for help on using the changeset viewer.