Changeset 15438 for branches/MCTS-SymbReg-2796/Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/MctsSymbolicRegressionTest.cs
- Timestamp:
- 10/28/17 19:56:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MCTS-SymbReg-2796/Tests/HeuristicLab.Algorithms.DataAnalysis-3.4/MctsSymbolicRegressionTest.cs
r15437 r15438 3 3 using System.Linq; 4 4 using System.Threading; 5 using HeuristicLab.Algorithms.DataAnalysis.MctsSymbolicRegression.Policies;6 5 using HeuristicLab.Algorithms.DataAnalysis.MCTSSymbReg; 7 6 using HeuristicLab.Data; … … 260 259 } 261 260 262 Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, c, z) > 0.05);263 Assert.IsTrue(Heuristics.CorrelationForInteraction(x, y, z, z) < 0.05);261 Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, c, t) > 0.05); 262 Assert.IsTrue(Heuristics.CorrelationForInteraction(x, y, z, t) < 0.05); 264 263 265 264 /* we might see correlations when only using one of the two relevant factors. … … 271 270 Assert.IsTrue(Heuristics.CorrelationForInteraction(b, y, z) < 0.05); 272 271 */ 273 Console.WriteLine("a,b: {0:N3}\tx,y: {1:N3}\ta,x: {2:N3}\tb,x: {3:N3}\ta,y: {4:N3}\tb,y: {5:N3}\tcov(a,b): {6:N3}", 274 Heuristics.CorrelationForInteraction(a, b, z), 275 Heuristics.CorrelationForInteraction(x, y, z), 276 Heuristics.CorrelationForInteraction(a, x, z), 277 Heuristics.CorrelationForInteraction(b, x, z), 278 Heuristics.CorrelationForInteraction(a, y, z), 279 Heuristics.CorrelationForInteraction(b, y, z), 280 alglib.cov2(a, b) 272 Console.WriteLine("a,b,c: {0:N3}\tx,y,z: {1:N3}\ta,b,x: {2:N3}\tb,c,x: {3:N3}", 273 Heuristics.CorrelationForInteraction(a, b, c, t), 274 Heuristics.CorrelationForInteraction(x, y, z, t), 275 Heuristics.CorrelationForInteraction(a, b, x, t), 276 Heuristics.CorrelationForInteraction(b, c, x, t) 281 277 ); 282 278 } 279 } 280 } 281 282 [TestMethod] 283 [TestCategory("Algorithms.DataAnalysis")] 284 [TestProperty("Time", "short")] 285 public void TestPoly10Interactions() { 286 { 287 alglib.hqrndstate randState; 288 alglib.hqrndseed(1234, 31415, out randState); 289 290 int N = 25000; // large sample size to make sure the test thresholds hold 291 double[] a = new double[N]; 292 double[] b = new double[N]; 293 double[] c = new double[N]; 294 double[] d = new double[N]; 295 double[] e = new double[N]; 296 double[] f = new double[N]; 297 double[] g = new double[N]; 298 double[] h = new double[N]; 299 double[] i = new double[N]; 300 double[] j = new double[N]; 301 double[] y = new double[N]; 302 303 for(int k=0;k<N;k++) { 304 a[k] = alglib.hqrnduniformr(randState) * 2 - 1; 305 b[k] = alglib.hqrnduniformr(randState) * 2 - 1; 306 c[k] = alglib.hqrnduniformr(randState) * 2 - 1; 307 d[k] = alglib.hqrnduniformr(randState) * 2 - 1; 308 e[k] = alglib.hqrnduniformr(randState) * 2 - 1; 309 f[k] = alglib.hqrnduniformr(randState) * 2 - 1; 310 g[k] = alglib.hqrnduniformr(randState) * 2 - 1; 311 h[k] = alglib.hqrnduniformr(randState) * 2 - 1; 312 i[k] = alglib.hqrnduniformr(randState) * 2 - 1; 313 j[k] = alglib.hqrnduniformr(randState) * 2 - 1; 314 y[k] = a[k] * b[k] + c[k] * d[k] + e[k] * f[k] + a[k] * g[k] * i[k] + c[k] * f[k] * j[k]; 315 } 316 317 var x = new[] { a, b, c, d, e, f, g, h, i, j }; 318 var all2Combinations = HeuristicLab.Common.EnumerableExtensions.Combinations(new[] {1,2,3,4,5,6,7,8,9,10}, 2); 319 320 var resultList = new List<Tuple<string, double>>(); 321 foreach(var entry in all2Combinations) { 322 var aIdx = entry.First(); 323 var bIdx = entry.Skip(1).First(); 324 resultList.Add(Tuple.Create(aIdx + " " + bIdx, Heuristics.CorrelationForInteraction(x[aIdx - 1], x[bIdx - 1], y))); 325 } 326 327 foreach(var entry in resultList.OrderByDescending(t => t.Item2)) { 328 Console.WriteLine("{0} {1:N3}", entry.Item1, entry.Item2); 329 } 330 331 var all3Combinations = HeuristicLab.Common.EnumerableExtensions.Combinations(new[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }, 3); 332 333 resultList = new List<Tuple<string, double>>(); 334 foreach (var entry in all3Combinations) { 335 var aIdx = entry.First(); 336 var bIdx = entry.Skip(1).First(); 337 var cIdx = entry.Skip(2).First(); 338 resultList.Add(Tuple.Create(aIdx + " " + bIdx + " " + cIdx, Heuristics.CorrelationForInteraction(x[aIdx - 1], x[bIdx - 1], x[cIdx - 1], y))); 339 } 340 341 // Y = X1*X2 + X3*X4 + X5*X6 + X1*X7*X9 + X3*X6*X10 342 343 foreach (var entry in resultList.OrderByDescending(t => t.Item2)) { 344 Console.WriteLine("{0} {1:N3}", entry.Item1, entry.Item2); 345 } 346 347 348 Assert.IsTrue(Heuristics.CorrelationForInteraction(a, b, y) > 0.01); 349 Assert.IsTrue(Heuristics.CorrelationForInteraction(b, a, y) > 0.01); 350 Assert.IsTrue(Heuristics.CorrelationForInteraction(c, d, y) > 0.01); 351 Assert.IsTrue(Heuristics.CorrelationForInteraction(d, c, y) > 0.01); 352 Assert.IsTrue(Heuristics.CorrelationForInteraction(e, f, y) > 0.01); 353 Assert.IsTrue(Heuristics.CorrelationForInteraction(f, e, y) > 0.01); 354 Assert.IsTrue(Heuristics.CorrelationForInteraction(a, g, i, y) > 0.01); 355 Assert.IsTrue(Heuristics.CorrelationForInteraction(a, i, g, y) > 0.01); 356 Assert.IsTrue(Heuristics.CorrelationForInteraction(g, a, i, y) > 0.01); 357 Assert.IsTrue(Heuristics.CorrelationForInteraction(g, i, a, y) > 0.01); 358 Assert.IsTrue(Heuristics.CorrelationForInteraction(i, g, a, y) > 0.01); 359 Assert.IsTrue(Heuristics.CorrelationForInteraction(i, a, g, y) > 0.01); 360 361 Assert.IsTrue(Heuristics.CorrelationForInteraction(c, f, j, y) > 0.01); 362 Assert.IsTrue(Heuristics.CorrelationForInteraction(c, j, f, y) > 0.01); 363 Assert.IsTrue(Heuristics.CorrelationForInteraction(f, c, j, y) > 0.01); 364 Assert.IsTrue(Heuristics.CorrelationForInteraction(f, j, c, y) > 0.01); 365 Assert.IsTrue(Heuristics.CorrelationForInteraction(j, c, f, y) > 0.01); 366 Assert.IsTrue(Heuristics.CorrelationForInteraction(j, f, c, y) > 0.01); 283 367 } 284 368 }
Note: See TracChangeset
for help on using the changeset viewer.