func (PS *PgeSearch) GenInitExprMethod1() *probs.ReportQueue { fmt.Printf("generating initial expressions\n") GP := PS.cnfg.treecfg fmt.Printf("%v\n", GP) eList := make([]expr.Expr, 0) for _, T := range GP.Roots { switch T.ExprType() { case expr.ADD: eList = append(eList, PS.GenInitExprAddMethod1()[:]...) case expr.MUL: eList = append(eList, PS.GenInitExprMulMethod1()[:]...) case expr.DIV: eList = append(eList, PS.GenInitExprDivMethod1()[:]...) default: fmt.Printf("Error in GenInitExpr: unknown ROOT %d\n", T) } } exprs := probs.NewReportQueue() // exprs.SetSort(PS.cnfg.sortType) exprs.SetSort(probs.PESORT_PARETO_TST_ERR) for i, e := range eList { fmt.Printf("%d: %v\n", i, e) serial := make([]int, 0, 64) serial = e.Serial(serial) PS.Trie.InsertSerial(serial) // on train data re := RegressExpr(e, PS.prob) re.SetUnitID(i) exprs.Push(re) } exprs.Sort() return exprs }
// This is the FFXish style init function func (PS *PgeSearch) GenInitExprMethod3() *probs.ReportQueue { fmt.Printf("generating initial expressions\n") GP := PS.cnfg.treecfg fmt.Printf("%v\n", GP) bases := make([]expr.Expr, 0) // single constant bases = append(bases, expr.NewConstant(-1)) // c*x_i for _, v := range PS.prob.UsableVars { mul := expr.NewMul() mul.Insert(expr.NewConstant(-1)) mul.Insert(expr.NewVar(v)) bases = append(bases, mul) } // c*x_i^p & c*x_i^-p for p := 2; p <= 4; p++ { for _, v := range PS.prob.UsableVars { // positive powers mul := expr.NewMul() mul.Insert(expr.NewConstant(-1)) mul.Insert(expr.NewPowI(expr.NewVar(v), p)) bases = append(bases, mul) // negative powers nul := expr.NewMul() nul.Insert(expr.NewConstant(-1)) nul.Insert(expr.NewPowI(expr.NewVar(v), -p)) bases = append(bases, nul) } } // c*N(d*x_i) for _, N := range PS.GenNodes { if N.ExprType() == expr.DIV || N.ExprType() == expr.ADD || N.ExprType() == expr.MUL { continue } for _, v := range PS.prob.UsableVars { // positive powers mul := expr.NewMul() mul.Insert(expr.NewConstant(-1)) nul := expr.NewMul() nul.Insert(expr.NewConstant(-1)) nul.Insert(expr.NewVar(v)) n := N.Clone() p := 1 n.SetExpr(&p, nul) mul.Insert(n) bases = append(bases, mul) } } // copy bases for use later in expand PS.ffxBases = make([]expr.Expr, len(bases)) for i, b := range bases { PS.ffxBases[i] = b.Clone() } exprs := probs.NewReportQueue() // exprs.SetSort(PS.cnfg.sortType) exprs.SetSort(probs.PESORT_PARETO_TST_ERR) for i, e := range bases { fmt.Printf("%d: %v\n", i, e) serial := make([]int, 0, 64) serial = e.Serial(serial) PS.Trie.InsertSerial(serial) // on train data re := RegressExpr(e, PS.prob) re.SetUnitID(i) exprs.Push(re) } exprs.Sort() return exprs }
func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) { fmt.Printf("Init'n PGE\n") // setup data // open logs PS.initLogs(logdir) // copy in common config options PS.prob = prob if PS.cnfg.treecfg == nil { PS.cnfg.treecfg = PS.prob.TreeCfg.Clone() } srules := expr.DefaultRules() srules.ConvertConsts = true PS.cnfg.simprules = srules fmt.Println("Roots: ", PS.cnfg.treecfg.RootsS) fmt.Println("Nodes: ", PS.cnfg.treecfg.NodesS) fmt.Println("Leafs: ", PS.cnfg.treecfg.LeafsS) fmt.Println("NonTrig: ", PS.cnfg.treecfg.NonTrigS) PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots)) for i := 0; i < len(PS.GenRoots); i++ { PS.GenRoots[i] = PS.cnfg.treecfg.Roots[i].Clone() } PS.GenNodes = make([]expr.Expr, len(PS.cnfg.treecfg.Nodes)) for i := 0; i < len(PS.GenNodes); i++ { PS.GenNodes[i] = PS.cnfg.treecfg.Nodes[i].Clone() } PS.GenNonTrig = make([]expr.Expr, len(PS.cnfg.treecfg.NonTrig)) for i := 0; i < len(PS.GenNonTrig); i++ { PS.GenNonTrig[i] = PS.cnfg.treecfg.NonTrig[i].Clone() } PS.GenLeafs = make([]expr.Expr, 0) for _, t := range PS.cnfg.treecfg.LeafsT { switch t { case expr.TIME: PS.GenLeafs = append(PS.GenLeafs, expr.NewTime()) case expr.VAR: fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars) for _, i := range PS.cnfg.treecfg.UsableVars { PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i)) } case expr.SYSTEM: for i := 0; i < PS.prob.Train[0].NumSys(); i++ { PS.GenLeafs = append(PS.GenLeafs, expr.NewSystem(i)) } } } /*** FIX ME PS.GenLeafs = make([]expr.Expr, len(PS.cnfg.treecfg.Leafs)) for i := 0; i < len(PS.GenLeafs); i++ { PS.GenLeafs[i] = PS.cnfg.treecfg.Leafs[i].Clone() } ***/ fmt.Println("Roots: ", PS.GenRoots) fmt.Println("Nodes: ", PS.GenNodes) fmt.Println("Leafs: ", PS.GenLeafs) fmt.Println("NonTrig: ", PS.GenNonTrig) // setup communication struct PS.commup = input.(*probs.ExprProblemComm) // initialize bbq PS.Trie = new(IpreNode) PS.Trie.val = -1 PS.Trie.next = make(map[int]*IpreNode) PS.Best = probs.NewReportQueue() PS.Best.SetSort(probs.GPSORT_PARETO_TST_ERR) PS.Queue = PS.GenInitExpr() PS.Queue.SetSort(probs.PESORT_PARETO_TST_ERR) PS.neqns = PS.Queue.Len() PS.minError = math.Inf(1) PS.eval_in = make(chan expr.Expr, 4048) PS.eval_out = make(chan *probs.ExprReport, 4048) for i := 0; i < PS.cnfg.evalrCount; i++ { go PS.Evaluate() } }