Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/pge/pge_init_method_1.go @ 16231

Last change on this file since 16231 was 16231, checked in by hmaislin, 6 years ago

#2929: Fixed result error

File size: 2.4 KB
Line 
1package pge
2
3import (
4  "fmt"
5
6  probs "github.com/verdverm/go-pge/problems"
7  expr "github.com/verdverm/go-symexpr"
8)
9
10func (PS *PgeSearch) GenInitExprMethod1() *probs.ReportQueue {
11  fmt.Printf("generating initial expressions\n")
12
13  GP := PS.cnfg.treecfg
14  fmt.Printf("%v\n", GP)
15
16  eList := make([]expr.Expr, 0)
17
18  for _, T := range GP.Roots {
19    switch T.ExprType() {
20    case expr.ADD:
21      eList = append(eList, PS.GenInitExprAddMethod1()[:]...)
22    case expr.MUL:
23      eList = append(eList, PS.GenInitExprMulMethod1()[:]...)
24    case expr.DIV:
25      eList = append(eList, PS.GenInitExprDivMethod1()[:]...)
26    default:
27      fmt.Printf("Error in GenInitExpr: unknown ROOT %d\n", T)
28    }
29  }
30
31  exprs := probs.NewReportQueue()
32  // exprs.SetSort(PS.cnfg.sortType)
33  exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
34
35  for i, e := range eList {
36    fmt.Printf("%d:  %v\n", i, e)
37    serial := make([]int, 0, 64)
38    serial = e.Serial(serial)
39    PS.Trie.InsertSerial(serial)
40    // on train data
41    re := RegressExpr(e, PS.prob)
42    re.SetUnitID(i)
43    exprs.Push(re)
44  }
45  exprs.Sort()
46  return exprs
47}
48
49func (PS *PgeSearch) GenInitExprAddMethod1() []expr.Expr {
50
51  exprs := make([]expr.Expr, 0)
52
53  // WARNING adding a single coefficient results in the same traversal but with the added extra coefficient
54  cf := new(expr.Constant)
55  cf.P = 1
56  af := new(expr.Add)
57  af.Insert(cf)
58  exprs = append(exprs, af)
59
60  for _, i := range PS.cnfg.treecfg.UsableVars {
61    c := new(expr.Constant)
62    c.P = -1
63    v := new(expr.Var)
64    v.P = i
65
66    m := expr.NewMul()
67    m.Insert(c)
68    m.Insert(v)
69
70    a := expr.NewAdd()
71    a.Insert(m)
72    exprs = append(exprs, a)
73  }
74
75  fmt.Println("Initial Add:  ", exprs)
76  return exprs
77}
78
79func (PS *PgeSearch) GenInitExprMulMethod1() []expr.Expr {
80  exprs := make([]expr.Expr, 0)
81
82  for _, i := range PS.cnfg.treecfg.UsableVars {
83    c := new(expr.Constant)
84    c.P = -1
85    v := new(expr.Var)
86    v.P = i
87
88    m := expr.NewMul()
89    m.Insert(c)
90    m.Insert(v)
91
92    exprs = append(exprs, m)
93  }
94
95  fmt.Println("Initial Mul:  ", exprs)
96  return exprs
97}
98
99func (PS *PgeSearch) GenInitExprDivMethod1() []expr.Expr {
100  exprs := make([]expr.Expr, 0)
101
102  for _, i := range PS.cnfg.treecfg.UsableVars {
103    c := new(expr.Constant)
104    c.P = -1
105    v := new(expr.Var)
106    v.P = i
107
108    d := new(expr.Div)
109    d.Numer = c
110    d.Denom = v
111
112    exprs = append(exprs, d)
113  }
114
115  fmt.Println("Initial Div:  ", exprs)
116  return exprs
117}
Note: See TracBrowser for help on using the repository browser.