1 | package pge |
---|
2 | |
---|
3 | import ( |
---|
4 | "fmt" |
---|
5 | |
---|
6 | probs "go-pge/problems" |
---|
7 | expr "go-symexpr" |
---|
8 | ) |
---|
9 | |
---|
10 | // This is the FFXish style init function |
---|
11 | func (PS *PgeSearch) GenInitExprMethod3() *probs.ReportQueue { |
---|
12 | fmt.Printf("generating initial expressions\n") |
---|
13 | |
---|
14 | GP := PS.cnfg.treecfg |
---|
15 | fmt.Printf("%v\n", GP) |
---|
16 | |
---|
17 | bases := make([]expr.Expr, 0) |
---|
18 | |
---|
19 | // single constant |
---|
20 | bases = append(bases, expr.NewConstant(-1)) |
---|
21 | |
---|
22 | // c*x_i |
---|
23 | for _, v := range PS.prob.UsableVars { |
---|
24 | mul := expr.NewMul() |
---|
25 | mul.Insert(expr.NewConstant(-1)) |
---|
26 | mul.Insert(expr.NewVar(v)) |
---|
27 | bases = append(bases, mul) |
---|
28 | } |
---|
29 | |
---|
30 | // c*x_i^p & c*x_i^-p |
---|
31 | for p := 2; p <= 4; p++ { |
---|
32 | for _, v := range PS.prob.UsableVars { |
---|
33 | // positive powers |
---|
34 | mul := expr.NewMul() |
---|
35 | mul.Insert(expr.NewConstant(-1)) |
---|
36 | mul.Insert(expr.NewPowI(expr.NewVar(v), p)) |
---|
37 | bases = append(bases, mul) |
---|
38 | |
---|
39 | // negative powers |
---|
40 | nul := expr.NewMul() |
---|
41 | nul.Insert(expr.NewConstant(-1)) |
---|
42 | nul.Insert(expr.NewPowI(expr.NewVar(v), -p)) |
---|
43 | bases = append(bases, nul) |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | // c*N(d*x_i) |
---|
48 | for _, N := range PS.GenNodes { |
---|
49 | if N.ExprType() == expr.DIV || N.ExprType() == expr.ADD || N.ExprType() == expr.MUL { |
---|
50 | continue |
---|
51 | } |
---|
52 | for _, v := range PS.prob.UsableVars { |
---|
53 | // positive powers |
---|
54 | mul := expr.NewMul() |
---|
55 | mul.Insert(expr.NewConstant(-1)) |
---|
56 | |
---|
57 | nul := expr.NewMul() |
---|
58 | nul.Insert(expr.NewConstant(-1)) |
---|
59 | nul.Insert(expr.NewVar(v)) |
---|
60 | |
---|
61 | n := N.Clone() |
---|
62 | p := 1 |
---|
63 | n.SetExpr(&p, nul) |
---|
64 | mul.Insert(n) |
---|
65 | bases = append(bases, mul) |
---|
66 | } |
---|
67 | } |
---|
68 | |
---|
69 | // copy bases for use later in expand |
---|
70 | PS.ffxBases = make([]expr.Expr, len(bases)) |
---|
71 | for i, b := range bases { |
---|
72 | PS.ffxBases[i] = b.Clone() |
---|
73 | } |
---|
74 | |
---|
75 | exprs := probs.NewReportQueue() |
---|
76 | // exprs.SetSort(PS.cnfg.sortType) |
---|
77 | exprs.SetSort(probs.PESORT_PARETO_TST_ERR) |
---|
78 | |
---|
79 | for i, e := range bases { |
---|
80 | fmt.Printf("%d: %v\n", i, e) |
---|
81 | serial := make([]int, 0, 64) |
---|
82 | serial = e.Serial(serial) |
---|
83 | PS.Trie.InsertSerial(serial) |
---|
84 | // on train data |
---|
85 | re := RegressExpr(e, PS.prob) |
---|
86 | re.SetUnitID(i) |
---|
87 | exprs.Push(re) |
---|
88 | } |
---|
89 | exprs.Sort() |
---|
90 | |
---|
91 | return exprs |
---|
92 | } |
---|