Free cookie consent management tool by TermsFeed Policy Generator

source: branches/MCTS-SymbReg-2796/HeuristicLab.Algorithms.DataAnalysis/3.4/Heuristics.cs @ 15426

Last change on this file since 15426 was 15426, checked in by gkronber, 7 years ago

#2796 testing interaction heuristics

File size: 2.1 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Problems.DataAnalysis;
7
8namespace HeuristicLab.Algorithms.DataAnalysis.MCTSSymbReg {
9  // experimenting with heuristics
10  //
11  // question: how can relevant interacting terms be reliably detected?
12  //           - is this even feasible?
13  //           - even if variables are colinear?
14  //           - even for non-linear transformations
15
16  // assuming we interactions of have scaled/shifted variables (x + xo) * (y + yo) with constant xo and yo
17  // this leads to: x y + x yo + y xo + yo xo.
18  // We only need to identify the x y as we assume that all other terms are accounted for
19  public static class Heuristics {
20    public static double CorrelationForInteraction(double[] a, double[] b, double[] c, double[] target) {
21      return 0.0;
22    }
23    public static double CorrelationForInteraction(double[] a, double[] b, double[] z) {
24      //
25      var am = a.Average();
26      var bm = b.Average();
27      var p1 = Enumerable.Range(0, a.Length).Where(i => a[i] < am);
28      var p2 = Enumerable.Range(0, a.Length).Where(i => a[i] > am);
29      var p3 = Enumerable.Range(0, a.Length).Where(i => b[i] < bm);
30      var p4 = Enumerable.Range(0, a.Length).Where(i => b[i] > bm);
31
32      return 1.0 / (p1.Count() + p2.Count() + p3.Count() + p4.Count()) *
33             (p1.Count() * CorrelForPartition(b, z, p1) +
34             p2.Count() * CorrelForPartition(b, z, p2) +
35             p3.Count() * CorrelForPartition(a, z, p3) +
36             p4.Count() * CorrelForPartition(a, z, p4));
37    }
38
39    public static double CorrelForPartition(double[] a, double[] z, IEnumerable<int> idx) {
40      var zp = new List<double>();
41      var ap = new List<double>();
42      foreach (var i in idx) {
43        zp.Add(z[i]);
44        ap.Add(a[i]);
45      }
46      OnlineCalculatorError error;
47      var r = SpearmansRankCorrelationCoefficientCalculator.CalculateSpearmansRank(zp, ap, out error);
48      if (error != OnlineCalculatorError.None) r = 0;
49      return r * r;
50    }
51  }
52}
Note: See TracBrowser for help on using the repository browser.