[15425] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Threading.Tasks;
|
---|
| 6 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 7 |
|
---|
| 8 | namespace 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[] z) {
|
---|
| 21 | //
|
---|
| 22 | var am = a.Average();
|
---|
| 23 | var bm = b.Average();
|
---|
| 24 | var p1 = Enumerable.Range(0, a.Length).Where(i => a[i] < am);
|
---|
| 25 | var p2 = Enumerable.Range(0, a.Length).Where(i => a[i] > am);
|
---|
| 26 | var p3 = Enumerable.Range(0, a.Length).Where(i => b[i] < bm);
|
---|
| 27 | var p4 = Enumerable.Range(0, a.Length).Where(i => b[i] > bm);
|
---|
| 28 |
|
---|
| 29 | return 1.0 / (p1.Count() + p2.Count() + p3.Count() + p4.Count()) *
|
---|
| 30 | (p1.Count() * CorrelForPartition(b, z, p1) +
|
---|
| 31 | p2.Count() * CorrelForPartition(b, z, p2) +
|
---|
| 32 | p3.Count() * CorrelForPartition(a, z, p3) +
|
---|
| 33 | p4.Count() * CorrelForPartition(a, z, p4));
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public static double CorrelForPartition(double[] a, double[] z, IEnumerable<int> idx) {
|
---|
| 37 | var zp = new List<double>();
|
---|
| 38 | var ap = new List<double>();
|
---|
| 39 | foreach (var i in idx) {
|
---|
| 40 | zp.Add(z[i]);
|
---|
| 41 | ap.Add(a[i]);
|
---|
| 42 | }
|
---|
| 43 | OnlineCalculatorError error;
|
---|
| 44 | var r = SpearmansRankCorrelationCoefficientCalculator.CalculateSpearmansRank(zp, ap, out error);
|
---|
| 45 | if (error != OnlineCalculatorError.None) r = 0;
|
---|
| 46 | return r * r;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 | }
|
---|