Changeset 16231 for branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go
- Timestamp:
- 10/17/18 04:47:09 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go
r16191 r16231 17 17 ) 18 18 19 type PgeConfig struct {19 type pgeConfig struct { 20 20 // search params 21 21 maxGen int … … 40 40 func pgeConfigParser(field, value string, config interface{}) (err error) { 41 41 42 PC := config.(* PgeConfig)42 PC := config.(*pgeConfig) 43 43 44 44 switch strings.ToUpper(field) { … … 92 92 type PgeSearch struct { 93 93 id int 94 cnfg PgeConfig94 cnfg pgeConfig 95 95 prob *probs.ExprProblem 96 96 iter int … … 151 151 return PS.cnfg.maxGen 152 152 } 153 func (PS *PgeSearch) GetPeelCount() int {154 return PS.cnfg.peelCnt155 }156 153 func (PS *PgeSearch) SetMaxIter(iter int) { 157 154 PS.cnfg.maxGen = iter … … 183 180 184 181 func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) { 185 186 //fmt.Printf("Init'n PGE\n") 182 fmt.Printf("Init'n PGE\n") 187 183 // setup data 188 184 189 185 // open logs 190 186 PS.initLogs(logdir) 191 192 PS.stop = false193 187 194 188 // copy in common config options … … 201 195 PS.cnfg.simprules = srules 202 196 203 //fmt.Println("Roots: ", PS.cnfg.treecfg.RootsS)204 //fmt.Println("Nodes: ", PS.cnfg.treecfg.NodesS)205 //fmt.Println("Leafs: ", PS.cnfg.treecfg.LeafsS)206 //fmt.Println("NonTrig: ", PS.cnfg.treecfg.NonTrigS)197 fmt.Println("Roots: ", PS.cnfg.treecfg.RootsS) 198 fmt.Println("Nodes: ", PS.cnfg.treecfg.NodesS) 199 fmt.Println("Leafs: ", PS.cnfg.treecfg.LeafsS) 200 fmt.Println("NonTrig: ", PS.cnfg.treecfg.NonTrigS) 207 201 208 202 PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots)) … … 226 220 227 221 case expr.VAR: 228 //fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)222 fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars) 229 223 for _, i := range PS.cnfg.treecfg.UsableVars { 230 224 PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i)) … … 245 239 ***/ 246 240 247 //fmt.Println("Roots: ", PS.GenRoots)248 //fmt.Println("Nodes: ", PS.GenNodes)249 //fmt.Println("Leafs: ", PS.GenLeafs)250 //fmt.Println("NonTrig: ", PS.GenNonTrig)241 fmt.Println("Roots: ", PS.GenRoots) 242 fmt.Println("Nodes: ", PS.GenNodes) 243 fmt.Println("Leafs: ", PS.GenLeafs) 244 fmt.Println("NonTrig: ", PS.GenNonTrig) 251 245 252 246 // setup communication struct … … 260 254 PS.Best = probs.NewReportQueue() 261 255 PS.Best.SetSort(probs.GPSORT_PARETO_TST_ERR) 262 263 256 PS.Queue = PS.GenInitExpr() 264 257 PS.Queue.SetSort(probs.PESORT_PARETO_TST_ERR) … … 283 276 continue 284 277 } 285 re := RegressExpr(e, PS.prob) 286 //fmt.Printf("reg: %v\n", re) 287 PS.eval_out <- re 278 PS.eval_out <- RegressExpr(e, PS.prob) 288 279 } 289 280 … … 293 284 fmt.Printf("Running PGE\n") 294 285 295 PS. Loop()286 PS.loop() 296 287 297 288 fmt.Println("PGE exitting") … … 301 292 } 302 293 303 func (PS *PgeSearch) Loop() {294 func (PS *PgeSearch) loop() { 304 295 305 296 PS.checkMessages() … … 307 298 308 299 fmt.Println("in: PS.step() ", PS.iter) 309 PS. Step()300 PS.step() 310 301 311 302 // if PS.iter%PS.cnfg.pgeRptEpoch == 0 { … … 357 348 } 358 349 359 func (PS *PgeSearch) Step() { 350 func (PS *PgeSearch) step() { 351 360 352 loop := 0 361 353 eval_cnt := 0 // for channeled eval … … 437 429 // } // for sequential eval 438 430 PS.Queue.Sort() 431 439 432 } 440 433 … … 442 435 es := make([]*probs.ExprReport, PS.cnfg.peelCnt) 443 436 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ { 437 444 438 e := PS.Queue.Pop().(*probs.ExprReport) 439 445 440 bPush := true 446 441 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon { … … 451 446 452 447 if bPush { 453 fmt.Printf("pop/push DO(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())448 fmt.Printf("pop/push(%d,%d): %v\n", p, PS.Best.Len(), e.Expr()) 454 449 PS.Best.Push(e) 455 450 } … … 471 466 return es 472 467 } 473 474 475 type PeelResult struct {476 Es *probs.ExprReport477 478 Nobestpush bool479 BestNewMinErr bool480 481 Bestlen1 int482 Bestlen2 int483 484 Coeff []float64485 TestScore int486 487 Expre expr.Expr488 ExpreRe *probs.ExprReport489 }490 491 492 func (PS *PgeSearch) SingleStep() []*PeelResult {493 loop := 0494 eval_cnt := 0495 PR := PS.peelRes()496 497 es := make([]*probs.ExprReport, len(PR))498 499 for i, elem := range PR {500 es[i] = elem.ExpreRe501 }502 503 ex := PS.expandPeeled(es)504 505 for cnt := range ex {506 E := ex[cnt]507 if E == nil {508 continue509 }510 for _, e := range E {511 if e == nil {512 continue513 }514 if !PS.cnfg.treecfg.CheckExpr(e) {515 continue516 }517 serial := make([]int, 0, 64)518 serial = e.Serial(serial)519 ins := PS.Trie.InsertSerial(serial)520 521 if !ins {522 continue523 }524 PS.eval_in <- e525 eval_cnt++526 }527 }528 for i := 0; i < eval_cnt; i++ {529 re := <-PS.eval_out530 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) {531 continue532 }533 if re.TestError() < PS.minError {534 PS.minError = re.TestError()535 }536 doIns := true537 for _, c := range re.Coeff() {538 if math.Abs(c) < PS.cnfg.zeroEpsilon {539 doIns = false540 break541 }542 }543 if doIns {544 re.SetProcID(PS.id)545 re.SetIterID(PS.iter)546 re.SetUnitID(loop)547 re.SetUniqID(PS.neqns)548 loop++549 PS.neqns++550 PS.Queue.Push(re)551 }552 }553 PS.Queue.Sort()554 555 PS.reportExpr()556 PS.iter++557 558 return PR559 }560 561 func (PS *PgeSearch) peelRes() []*PeelResult {562 //es := make([]*probs.ExprReport, PS.cnfg.peelCnt)563 PRes := make([]*PeelResult, PS.cnfg.peelCnt)564 565 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ {566 PR := new(PeelResult)567 568 PR.BestNewMinErr = false569 PR.Nobestpush = false570 571 e := PS.Queue.Pop().(*probs.ExprReport)572 573 bPush := true574 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {575 //fmt.Println("No Best Push")576 PR.Nobestpush = true577 p--578 continue579 }580 581 if bPush {582 //fmt.Printf("pop/push (%d,%d): %v\n", p, PS.Best.Len(), e.Expr())583 PR.Bestlen1 = p584 PR.Bestlen2 = PS.Best.Len()585 PR.Expre = e.Expr()586 PR.ExpreRe = e587 PS.Best.Push(e)588 }589 590 //es[p] = e591 PR.Es = e592 PR.Coeff = e.Coeff()593 PR.TestScore = e.TestScore()594 595 596 if e.TestScore() > PS.maxScore {597 PS.maxScore = e.TestScore()598 }599 if e.TestError() < PS.minError {600 PS.minError = e.TestError()601 PR.BestNewMinErr = true602 //fmt.Printf("Best New Min Error: %v\n", e)603 }604 if e.Size() > PS.maxSize {605 PS.maxSize = e.Size()606 }607 608 PRes[p] = PR609 }610 611 return PRes612 }613 614 468 615 469 func (PS *PgeSearch) expandPeeled(es []*probs.ExprReport) [][]expr.Expr { … … 633 487 // fmt.Println() 634 488 } 489 fmt.Println("\n") 635 490 return eqns 636 491 } … … 668 523 669 524 func (PS *PgeSearch) Clean() { 525 // fmt.Printf("Cleaning PGE\n") 526 670 527 PS.errLogBuf.Flush() 671 528 PS.mainLogBuf.Flush() … … 673 530 PS.fitnessLogBuf.Flush() 674 531 PS.ipreLogBuf.Flush() 532 675 533 } 676 534 … … 747 605 if len(guess) > 0 { 748 606 749 //fmt.Printf("IMREGEXP %v %v\n", P.SearchType, P.SearchVar) 750 //fmt.Printf("REGPTrain %T | %#v | %v\n", P.Train, P.Train, P.Train) 751 //fmt.Printf("eqn %T | %#v | %v\n", eqn, eqn, eqn) 752 //fmt.Printf("guess %T | %#v | %v\n", guess, guess, guess) 607 // fmt.Printf("x_dims: %d %d\n", x_dim, x_dim2) 753 608 754 609 // Callback version 755 756 757 610 coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test) 758 759 611 760 612 // Stack version … … 789 641 R = new(probs.ExprReport) 790 642 R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/ 791 792 643 R.SetCoeff(coeff) 793 644 R.Expr().CalcExprStats() … … 856 707 return 857 708 } 858 859 func (PS *PgeSearch) CreateDS(maxGen int, pgeRptEpoch int, pgeRptCount int, pgeArchiveCap int, peelCnt int, evalrCount int, zeroEpsilon float64, initMethod string, growMethod string, sortType int) {860 PS.id = 0 //maxGen861 862 var PC PgeConfig863 864 PC.pgeRptEpoch = pgeRptEpoch865 PC.pgeRptCount = pgeRptCount866 PC.pgeArchiveCap = pgeArchiveCap867 PC.peelCnt = peelCnt868 PC.evalrCount = evalrCount869 PC.zeroEpsilon = zeroEpsilon870 PC.initMethod = initMethod871 PC.growMethod = growMethod872 873 if sortType == 1 {874 PC.sortType = probs.PESORT_PARETO_TRN_ERR875 } else {876 PC.sortType = probs.PESORT_PARETO_TST_ERR877 }878 879 PC.maxGen = maxGen880 PS.cnfg = PC881 882 PS.iter = 0883 }884 885 func (PS *PgeSearch) SetProb(ep *probs.ExprProblem) {886 PS.prob = ep887 }888 func (PS *PgeSearch) GetIter() int {889 return PS.iter890 }
Note: See TracChangeset
for help on using the changeset viewer.