Changeset 16230 for branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge
- Timestamp:
- 10/11/18 11:37:54 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/pge/pge_search.go
r16080 r16230 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.peelCnt 155 } 153 156 func (PS *PgeSearch) SetMaxIter(iter int) { 154 157 PS.cnfg.maxGen = iter … … 180 183 181 184 func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) { 182 fmt.Printf("Init'n PGE\n") 185 186 //fmt.Printf("Init'n PGE\n") 183 187 // setup data 184 188 185 189 // open logs 186 190 PS.initLogs(logdir) 191 192 PS.stop = false 187 193 188 194 // copy in common config options … … 195 201 PS.cnfg.simprules = srules 196 202 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)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) 201 207 202 208 PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots)) … … 212 218 PS.GenNonTrig[i] = PS.cnfg.treecfg.NonTrig[i].Clone() 213 219 } 220 221 fmt.Printf("Init1 %v\n", len(PS.cnfg.treecfg.LeafsT)) 214 222 215 223 PS.GenLeafs = make([]expr.Expr, 0) … … 220 228 221 229 case expr.VAR: 222 fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)230 //fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars) 223 231 for _, i := range PS.cnfg.treecfg.UsableVars { 224 232 PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i)) … … 232 240 } 233 241 } 242 fmt.Printf("Init2\n") 234 243 /*** FIX ME 235 244 PS.GenLeafs = make([]expr.Expr, len(PS.cnfg.treecfg.Leafs)) … … 238 247 } 239 248 ***/ 240 241 fmt.Println("Roots: ", PS.GenRoots) 242 fmt.Println("Nodes: ", PS.GenNodes) 243 fmt.Println("Leafs: ", PS.GenLeafs) 244 fmt.Println("NonTrig: ", PS.GenNonTrig) 249 250 fmt.Printf("Init3\n") 251 252 //fmt.Println("Roots: ", PS.GenRoots) 253 //fmt.Println("Nodes: ", PS.GenNodes) 254 //fmt.Println("Leafs: ", PS.GenLeafs) 255 //fmt.Println("NonTrig: ", PS.GenNonTrig) 245 256 246 257 // setup communication struct … … 254 265 PS.Best = probs.NewReportQueue() 255 266 PS.Best.SetSort(probs.GPSORT_PARETO_TST_ERR) 267 fmt.Printf("Init4\n") 268 256 269 PS.Queue = PS.GenInitExpr() 257 270 PS.Queue.SetSort(probs.PESORT_PARETO_TST_ERR) … … 264 277 PS.eval_out = make(chan *probs.ExprReport, 4048) 265 278 279 fmt.Printf("Init5a\n") 266 280 for i := 0; i < PS.cnfg.evalrCount; i++ { 267 281 go PS.Evaluate() 268 282 } 283 fmt.Printf("Init5\n") 269 284 } 270 285 … … 276 291 continue 277 292 } 278 PS.eval_out <- RegressExpr(e, PS.prob) 293 re := RegressExpr(e, PS.prob) 294 //fmt.Printf("reg: %v\n", re) 295 PS.eval_out <- re 279 296 } 280 297 … … 284 301 fmt.Printf("Running PGE\n") 285 302 286 PS. loop()303 PS.Loop() 287 304 288 305 fmt.Println("PGE exitting") … … 292 309 } 293 310 294 func (PS *PgeSearch) loop() {311 func (PS *PgeSearch) Loop() { 295 312 296 313 PS.checkMessages() … … 298 315 299 316 fmt.Println("in: PS.step() ", PS.iter) 300 PS. step()317 PS.Step() 301 318 302 319 // if PS.iter%PS.cnfg.pgeRptEpoch == 0 { … … 348 365 } 349 366 350 func (PS *PgeSearch) step() { 351 367 func (PS *PgeSearch) Step() { 352 368 loop := 0 353 369 eval_cnt := 0 // for channeled eval … … 429 445 // } // for sequential eval 430 446 PS.Queue.Sort() 431 432 447 } 433 448 … … 435 450 es := make([]*probs.ExprReport, PS.cnfg.peelCnt) 436 451 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ { 437 438 452 e := PS.Queue.Pop().(*probs.ExprReport) 439 440 453 bPush := true 441 454 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon { … … 446 459 447 460 if bPush { 448 fmt.Printf("pop/push (%d,%d): %v\n", p, PS.Best.Len(), e.Expr())461 fmt.Printf("pop/push DO(%d,%d): %v\n", p, PS.Best.Len(), e.Expr()) 449 462 PS.Best.Push(e) 450 463 } … … 466 479 return es 467 480 } 481 482 483 type PeelResult struct { 484 Es *probs.ExprReport 485 486 Nobestpush bool 487 BestNewMinErr bool 488 489 Bestlen1 int 490 Bestlen2 int 491 492 Coeff []float64 493 TestScore int 494 495 Expre expr.Expr 496 ExpreRe *probs.ExprReport 497 } 498 499 //Problem 500 func (PS *PgeSearch) SingleStep() []*PeelResult { 501 if os.Getenv("PGEDEBUG") == "1" { 502 fmt.Printf("Init PgeSearch: %#v \n", PS) 503 fmt.Printf("Init PgeProblem: %#v \n", PS.prob) 504 } 505 506 507 loop := 0 508 eval_cnt := 0 509 PR := PS.peelRes() 510 511 es := make([]*probs.ExprReport, len(PR)) 512 513 for i, elem := range PR { 514 if(elem != nil) { 515 es[i] = elem.ExpreRe 516 //} else { 517 // es[i] = new(probs.ExprReport) 518 } 519 } 520 521 ex := PS.expandPeeled(es) 522 523 for cnt := range ex { 524 E := ex[cnt] 525 if E == nil { 526 continue 527 } 528 for _, e := range E { 529 if e == nil { 530 continue 531 } 532 if !PS.cnfg.treecfg.CheckExpr(e) { 533 continue 534 } 535 serial := make([]int, 0, 64) 536 serial = e.Serial(serial) 537 ins := PS.Trie.InsertSerial(serial) 538 539 if !ins { 540 continue 541 } 542 PS.eval_in <- e 543 eval_cnt++ 544 } 545 } 546 for i := 0; i < eval_cnt; i++ { 547 re := <-PS.eval_out 548 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) { 549 continue 550 } 551 if re.TestError() < PS.minError { 552 PS.minError = re.TestError() 553 } 554 doIns := true 555 for _, c := range re.Coeff() { 556 if math.Abs(c) < PS.cnfg.zeroEpsilon { 557 doIns = false 558 break 559 } 560 } 561 if doIns { 562 re.SetProcID(PS.id) 563 re.SetIterID(PS.iter) 564 re.SetUnitID(loop) 565 re.SetUniqID(PS.neqns) 566 loop++ 567 PS.neqns++ 568 PS.Queue.Push(re) 569 } 570 } 571 PS.Queue.Sort() 572 573 PS.reportExpr() 574 PS.iter++ 575 576 return PR 577 } 578 579 //Problem 580 func (PS *PgeSearch) peelRes() []*PeelResult { 581 //es := make([]*probs.ExprReport, PS.cnfg.peelCnt) 582 PRes := make([]*PeelResult, PS.cnfg.peelCnt) 583 584 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ { 585 PR := new(PeelResult) 586 587 PR.BestNewMinErr = false 588 PR.Nobestpush = false 589 590 e := PS.Queue.Pop().(*probs.ExprReport) 591 592 bPush := true 593 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon { 594 //fmt.Println("No Best Push") 595 PR.Nobestpush = true 596 p-- 597 continue 598 } 599 600 if bPush { 601 //fmt.Printf("pop/push (%d,%d): %v\n", p, PS.Best.Len(), e.Expr()) 602 PS.Best.Push(e) 603 } 604 605 //es[p] = e 606 PR.Bestlen1 = p 607 PR.Bestlen2 = PS.Best.Len() 608 PR.Expre = e.Expr() 609 PR.ExpreRe = e 610 PR.Es = e 611 PR.Coeff = e.Coeff() 612 PR.TestScore = e.TestScore() 613 614 615 if e.TestScore() > PS.maxScore { 616 PS.maxScore = e.TestScore() 617 } 618 if e.TestError() < PS.minError { 619 PS.minError = e.TestError() 620 PR.BestNewMinErr = true 621 //fmt.Printf("Best New Min Error: %v\n", e) 622 } 623 if e.Size() > PS.maxSize { 624 PS.maxSize = e.Size() 625 } 626 627 PRes[p] = PR 628 } 629 630 return PRes 631 } 632 468 633 469 634 func (PS *PgeSearch) expandPeeled(es []*probs.ExprReport) [][]expr.Expr { … … 487 652 // fmt.Println() 488 653 } 489 fmt.Println("\n")490 654 return eqns 491 655 } … … 523 687 524 688 func (PS *PgeSearch) Clean() { 525 // fmt.Printf("Cleaning PGE\n")526 527 689 PS.errLogBuf.Flush() 528 690 PS.mainLogBuf.Flush() … … 530 692 PS.fitnessLogBuf.Flush() 531 693 PS.ipreLogBuf.Flush() 532 533 694 } 534 695 … … 605 766 if len(guess) > 0 { 606 767 607 // fmt.Printf("x_dims: %d %d\n", x_dim, x_dim2) 768 //fmt.Printf("IMREGEXP %v %v\n", P.SearchType, P.SearchVar) 769 //fmt.Printf("REGPTrain %T | %#v | %v\n", P.Train, P.Train, P.Train) 770 //fmt.Printf("eqn %T | %#v | %v\n", eqn, eqn, eqn) 771 //fmt.Printf("guess %T | %#v | %v\n", guess, guess, guess) 608 772 609 773 // Callback version 774 775 610 776 coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test) 777 611 778 612 779 // Stack version … … 641 808 R = new(probs.ExprReport) 642 809 R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/ 810 643 811 R.SetCoeff(coeff) 644 812 R.Expr().CalcExprStats() … … 707 875 return 708 876 } 877 878 func (PS *PgeSearch) CreateDS(maxGen int, pgeRptEpoch int, pgeRptCount int, pgeArchiveCap int, peelCnt int, evalrCount int, zeroEpsilon float64, initMethod string, growMethod string, sortType int) { 879 PS.id = 0 //maxGen 880 881 var PC PgeConfig 882 883 PC.pgeRptEpoch = pgeRptEpoch 884 PC.pgeRptCount = pgeRptCount 885 PC.pgeArchiveCap = pgeArchiveCap 886 PC.peelCnt = peelCnt 887 PC.evalrCount = evalrCount 888 PC.zeroEpsilon = zeroEpsilon 889 PC.initMethod = initMethod 890 PC.growMethod = growMethod 891 892 if sortType == 1 { 893 PC.sortType = probs.PESORT_PARETO_TRN_ERR 894 } else { 895 PC.sortType = probs.PESORT_PARETO_TST_ERR 896 } 897 898 PC.maxGen = maxGen 899 PS.cnfg = PC 900 901 PS.iter = 0 902 } 903 904 func (PS *PgeSearch) SetProb(ep *probs.ExprProblem) { 905 PS.prob = ep 906 } 907 func (PS *PgeSearch) GetIter() int { 908 return PS.iter 909 }
Note: See TracChangeset
for help on using the changeset viewer.