Changeset 16510 for branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code
- Timestamp:
- 01/07/19 06:59:25 (6 years ago)
- Location:
- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge.go
r16231 r16510 72 72 //export AddTrainData 73 73 func AddTrainData(indepNames *C.char, depndNames *C.char, matrix unsafe.Pointer, nEntries int) { 74 trainDatas = make([]*probs.PointSet, 1) 74 trainDatas = make([]*probs.PointSet, 1) //wieso bin i do und ned im initsearch oda so !! 75 75 trainData = new(probs.PointSet) 76 76 … … 112 112 goName := C.GoString(Name) 113 113 goProblemTypeString := C.GoString(ProblemTypeString) 114 fmt.Printf("1\n")115 114 116 115 ep.CreatePS(goName, MaxIter, HitRatio, SearchVar, goProblemTypeString) 117 116 ep.TreeCfg = tp; 118 117 ep.UsableVars = tp.UsableVars 119 fmt.Printf("2\n")120 118 121 119 cps.SetMaxIter(MaxIter) 122 120 per_eqns = make([]*probs.ExprReportArray, 1) 123 fmt.Printf("3\n")124 121 125 122 ep.Train = trainDatas 126 123 ep.Test = testDatas 127 fmt.Printf("4\n")128 124 129 125 initDone := make(chan int) 130 126 rt.GOMAXPROCS(numProcs) 131 127 rand.Seed(rand.Int63()) 132 fmt.Printf("5\n")133 128 134 129 epcomm = new(probs.ExprProblemComm) … … 138 133 epcomm.Gen = make(chan [2]int, 64) 139 134 140 fmt.Printf("6\n")141 142 135 cps.SetProb(ep) 143 cps.Init(initDone, ep, "dummy", epcomm) 144 fmt.Printf("7\n") 136 cps.Init(initDone, ep, "", epcomm) 145 137 } 146 138 … … 252 244 if ok && resu != nil { 253 245 stepResult = *resu 254 nNew = nRes - nLastResults255 nLastResults = nRes246 nNew = nRes // - nLastResults 247 nLastResults = 0 //nRes 256 248 } 257 249 -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go
r16231 r16510 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 368 type PeelResult struct { 369 Es *probs.ExprReport 370 371 Nobestpush bool 372 BestNewMinErr bool 373 374 Bestlen1 int 375 Bestlen2 int 376 377 Coeff []float64 378 TestScore int 379 380 Expre expr.Expr 381 ExpreRe *probs.ExprReport 382 } 383 384 func (PS *PgeSearch) SingleStep2() { 352 385 loop := 0 353 386 eval_cnt := 0 // for channeled eval … … 411 444 } 412 445 } 413 446 447 if doIns { 448 re.SetProcID(PS.id) 449 re.SetIterID(PS.iter) 450 re.SetUnitID(loop) 451 re.SetUniqID(PS.neqns) 452 loop++ 453 PS.neqns++ 454 455 //fmt.Printf("SS2Queue.Push(): %v\n%v\n\n", re.Expr(), serial) 456 ////fmt.Printf("INSQueue.Push(): %v\n", re) 457 ////fmt.Printf("INSQueue.Push(): %v\n", re.Expr()) 458 459 PS.Queue.Push(re) 460 461 } 462 } 463 // } // for sequential eval 464 PS.Queue.Sort() 465 } 466 467 //Problem 468 func (PS *PgeSearch) SingleStep() []*PeelResult { 469 if os.Getenv("PGEDEBUG") == "1" { 470 fmt.Printf("Init PgeSearch: %#v \n", PS) 471 fmt.Printf("Init PgeProblem: %#v \n", PS.prob) 472 } 473 474 475 loop := 0 476 eval_cnt := 0 477 PR := PS.peelRes() 478 479 es := make([]*probs.ExprReport, len(PR)) 480 481 for i, elem := range PR { 482 if(elem != nil) { 483 es[i] = elem.ExpreRe 484 //} else { 485 // es[i] = new(probs.ExprReport) 486 } 487 } 488 489 ex := PS.expandPeeled(es) 490 491 for cnt := range ex { 492 E := ex[cnt] 493 if E == nil { 494 continue 495 } 496 for _, e := range E { 497 if e == nil { 498 continue 499 } 500 if !PS.cnfg.treecfg.CheckExpr(e) { 501 continue 502 } 503 serial := make([]int, 0, 64) 504 serial = e.Serial(serial) 505 ins := PS.Trie.InsertSerial(serial) 506 507 if !ins { 508 continue 509 } 510 PS.eval_in <- e 511 eval_cnt++ 512 } 513 } 514 for i := 0; i < eval_cnt; i++ { 515 re := <-PS.eval_out 516 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) { 517 continue 518 } 519 if re.TestError() < PS.minError { 520 PS.minError = re.TestError() 521 } 522 doIns := true 523 for _, c := range re.Coeff() { 524 if math.Abs(c) < PS.cnfg.zeroEpsilon { 525 doIns = false 526 break 527 } 528 } 529 if doIns { 530 re.SetProcID(PS.id) 531 re.SetIterID(PS.iter) 532 re.SetUnitID(loop) 533 re.SetUniqID(PS.neqns) 534 loop++ 535 PS.neqns++ 536 PS.Queue.Push(re) 537 } 538 } 539 PS.Queue.Sort() 540 541 PS.reportExpr() 542 PS.iter++ 543 544 return PR 545 } 546 547 //Problem 548 func (PS *PgeSearch) peelRes() []*PeelResult { 549 //es := make([]*probs.ExprReport, PS.cnfg.peelCnt) 550 PRes := make([]*PeelResult, PS.cnfg.peelCnt) 551 552 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ { 553 PR := new(PeelResult) 554 555 PR.BestNewMinErr = false 556 PR.Nobestpush = false 557 558 e := PS.Queue.Pop().(*probs.ExprReport) 559 560 bPush := true 561 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon { 562 //fmt.Println("No Best Push") 563 PR.Nobestpush = true 564 p-- 565 continue 566 } 567 568 if bPush { 569 //fmt.Printf("pop/push (%d,%d): %v\n", p, PS.Best.Len(), e.Expr()) 570 PS.Best.Push(e) 571 } 572 573 //es[p] = e 574 PR.Bestlen1 = p 575 PR.Bestlen2 = PS.Best.Len() 576 PR.Expre = e.Expr() 577 PR.ExpreRe = e 578 PR.Es = e 579 PR.Coeff = e.Coeff() 580 PR.TestScore = e.TestScore() 581 582 583 if e.TestScore() > PS.maxScore { 584 PS.maxScore = e.TestScore() 585 } 586 if e.TestError() < PS.minError { 587 PS.minError = e.TestError() 588 PR.BestNewMinErr = true 589 //fmt.Printf("Best New Min Error: %v\n", e) 590 } 591 if e.Size() > PS.maxSize { 592 PS.maxSize = e.Size() 593 } 594 595 PRes[p] = PR 596 } 597 598 return PRes 599 } 600 601 func (PS *PgeSearch) Step() int { 602 603 loop := 0 604 eval_cnt := 0 // for channeled eval 605 606 es := PS.peel() 607 608 ex := PS.expandPeeled(es) 609 610 cnt_ins := 0 611 612 for cnt := range ex { 613 E := ex[cnt] 614 615 if E == nil { 616 continue 617 } 618 619 for _, e := range E { 620 if e == nil { 621 continue 622 } 623 if !PS.cnfg.treecfg.CheckExpr(e) { 624 continue 625 } 626 627 // check ipre_trie 628 serial := make([]int, 0, 64) 629 serial = e.Serial(serial) 630 ins := PS.Trie.InsertSerial(serial) 631 if !ins { 632 continue 633 } 634 635 // for serial eval 636 // re := RegressExpr(e, PS.prob) 637 638 // start channeled eval 639 PS.eval_in <- e 640 eval_cnt++ 641 } 642 } 643 644 for i := 0; i < eval_cnt; i++ { 645 re := <-PS.eval_out 646 // end channeled eval 647 648 // check for NaN/Inf in re.error and if so, skip 649 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) { 650 // fmt.Printf("Bad Error\n%v\n", re) 651 continue 652 } 653 654 if re.TestError() < PS.minError { 655 PS.minError = re.TestError() 656 } 657 658 // check for coeff == 0 659 doIns := true 660 for _, c := range re.Coeff() { 661 // i > 0 for free coeff 662 if math.Abs(c) < PS.cnfg.zeroEpsilon { 663 doIns = false 664 break 665 } 666 } 667 668 //fmt.Printf("StepQueue.Push(): %v\n", re) 669 //fmt.Printf("StepQueue.Push(): %v\n", re.Expr()) 670 414 671 if doIns { 415 672 re.SetProcID(PS.id) … … 422 679 // fmt.Printf("Queue.Push(): %v\n", re) 423 680 // fmt.Printf("Queue.Push(): %v\n", re.Expr()) 424 681 cnt_ins++ 425 682 PS.Queue.Push(re) 426 427 683 } 428 684 } … … 430 686 PS.Queue.Sort() 431 687 688 PS.iter++ 689 PS.reportExpr() //new 690 return 3 432 691 } 433 692 434 693 func (PS *PgeSearch) peel() []*probs.ExprReport { 435 694 es := make([]*probs.ExprReport, PS.cnfg.peelCnt) 695 696 rpt := make(probs.ExprReportArray, 0) 697 436 698 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ { 437 699 … … 440 702 bPush := true 441 703 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon { 442 fmt.Println("No Best Push")704 ////fmt.Println("No Best Push") 443 705 p-- 444 706 continue … … 446 708 447 709 if bPush { 448 fmt.Printf(" pop/push(%d,%d): %v\n", p, PS.Best.Len(), e.Expr())710 fmt.Printf("BEST PUSH/push(%d,%d): %v\n", p, PS.Best.Len(), e.Expr()) 449 711 PS.Best.Push(e) 712 rpt = append(rpt, e) 450 713 } 451 714 … … 457 720 if e.TestError() < PS.minError { 458 721 PS.minError = e.TestError() 459 fmt.Printf("Best New Min Error: %v\n", e)722 ////fmt.Printf("Best New Min Error: %v\n", e) 460 723 } 461 724 if e.Size() > PS.maxSize { 462 725 PS.maxSize = e.Size() 463 726 } 464 465 } 727 728 } 729 PS.commup.Rpts <- &rpt 466 730 return es 467 731 } … … 491 755 } 492 756 493 func (PS *PgeSearch) reportExpr() { 494 757 //Hier ist das pgeRpt problem, liefert immer die besten pgerpt cnt ergebnisse zurck und ich schneide aus arrazy, werden auch unsortiert 758 // //* 759 func (PS *PgeSearch) reportExpr() int { 760 //PS.cnfg.pgeRptCount++ 495 761 cnt := PS.cnfg.pgeRptCount 496 PS.Best.Sort()762 //*PS.Best.Sort() 497 763 498 764 // repot best equations 499 765 rpt := make(probs.ExprReportArray, cnt) 500 if PS.Best.Len() < cnt {501 cnt = PS.Best.Len()502 }766 //*if PS.Best.Len() < cnt { 767 //* cnt = PS.Best.Len() 768 //*} 503 769 copy(rpt, PS.Best.GetQueue()[:cnt]) 504 770 … … 513 779 } 514 780 515 PS.mainLog.Printf("Iter: %d %f %f\n", PS.iter, errSum/float64(errCnt), PS.minError)781 ////fmt.Printf("Iter: %d %f %f\n", PS.iter, errSum/float64(errCnt), PS.minError) 516 782 517 783 PS.ipreLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst) 518 784 PS.fitnessLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst, errSum/float64(errCnt), PS.minError) 519 785 520 PS.commup.Rpts <- &rpt 521 786 //PS.commup.Rpts <- &rpt 787 788 return errCnt 522 789 } 523 790 524 791 func (PS *PgeSearch) Clean() { 525 // fmt.Printf("Cleaning PGE\n")526 527 792 PS.errLogBuf.Flush() 528 793 PS.mainLogBuf.Flush() … … 530 795 PS.fitnessLogBuf.Flush() 531 796 PS.ipreLogBuf.Flush() 532 533 797 } 534 798 … … 605 869 if len(guess) > 0 { 606 870 607 // fmt.Printf("x_dims: %d %d\n", x_dim, x_dim2) 871 //fmt.Printf("IMREGEXP %v %v\n", P.SearchType, P.SearchVar) 872 //fmt.Printf("REGPTrain %T | %#v | %v\n", P.Train, P.Train, P.Train) 873 //fmt.Printf("eqn %T | %#v | %v\n", eqn, eqn, eqn) 874 //fmt.Printf("guess %T | %#v | %v\n", guess, guess, guess) 608 875 609 876 // Callback version 877 878 610 879 coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test) 880 611 881 612 882 // Stack version … … 641 911 R = new(probs.ExprReport) 642 912 R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/ 913 643 914 R.SetCoeff(coeff) 644 915 R.Expr().CalcExprStats() … … 707 978 return 708 979 } 980 981 func (PS *PgeSearch) CreateDS(maxGen int, pgeRptEpoch int, pgeRptCount int, pgeArchiveCap int, peelCnt int, evalrCount int, zeroEpsilon float64, initMethod string, growMethod string, sortType int) { 982 PS.id = 0 //maxGen 983 984 var PC PgeConfig 985 986 PC.pgeRptEpoch = pgeRptEpoch 987 PC.pgeRptCount = pgeRptCount 988 PC.pgeArchiveCap = pgeArchiveCap 989 PC.peelCnt = peelCnt 990 PC.evalrCount = evalrCount 991 PC.zeroEpsilon = zeroEpsilon 992 PC.initMethod = initMethod 993 PC.growMethod = growMethod 994 995 if sortType == 1 { 996 PC.sortType = probs.PESORT_PARETO_TRN_ERR 997 } else { 998 PC.sortType = probs.PESORT_PARETO_TST_ERR 999 } 1000 1001 PC.maxGen = maxGen 1002 PS.cnfg = PC 1003 //PS.Stop = false is in init 1004 PS.iter = 0 1005 } 1006 1007 func (PS *PgeSearch) SetProb(ep *probs.ExprProblem) { 1008 PS.prob = ep 1009 } 1010 func (PS *PgeSearch) GetIter() int { 1011 return PS.iter 1012 }
Note: See TracChangeset
for help on using the changeset viewer.