Changeset 16615 for branches/2929_PrioritizedGrammarEnumeration
- Timestamp:
- 02/19/19 18:04:42 (6 years ago)
- Location:
- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge.go
r16510 r16615 7 7 "fmt" 8 8 rt "runtime" 9 rand "math/rand"9 //rand "math/rand" 10 10 "strings" 11 11 probs "github.com/verdverm/go-pge/problems" … … 51 51 trainDatasN = 0 52 52 nLastResults = 0 53 53 54 cps.CreateDS(maxGen, pgeRptEpoch, pgeRptCount, pgeArchiveCap, peelCnt, evalrCount, zeroEpsilon, goInitMethod, goGrowMethod, sortType) 54 55 … … 60 61 61 62 //export InitTreeParams 62 func InitTreeParams(Roots *C.char, Nodes *C.char, NonTrig *C.char, Leafs *C.char, UsableVars unsafe.Pointer,nUseableVars int, MaxSize int, MinSize int, MaxDepth int, MinDepth int) {63 func InitTreeParams(Roots *C.char, Nodes *C.char, NonTrig *C.char, Leafs *C.char, nUseableVars int, MaxSize int, MinSize int, MaxDepth int, MinDepth int) { 63 64 tp = new(probs.TreeParams) 64 65 goRoots := C.GoString(Roots) … … 66 67 goNonTrig := C.GoString(NonTrig) 67 68 goLeafs := C.GoString(Leafs) 68 goUsableVars := C IntArrayToSlice(UsableVars,nUseableVars)69 goUsableVars := CreateUsableVars(nUseableVars) 69 70 tp.CreateTreeParams(goRoots, goNodes, goNonTrig, goLeafs, goUsableVars, MaxSize, MinSize, MaxDepth, MinDepth) 70 71 } … … 72 73 //export AddTrainData 73 74 func AddTrainData(indepNames *C.char, depndNames *C.char, matrix unsafe.Pointer, nEntries int) { 74 trainDatas = make([]*probs.PointSet, 1) //wieso bin i do und ned im initsearch oda so !!75 trainDatas = make([]*probs.PointSet, 1) 75 76 trainData = new(probs.PointSet) 76 77 … … 96 97 97 98 testData.InitTrainData(goIndepNames, goDepndNames, matrix, nEntries) 99 98 100 testDatas[testDatasN] = testData 99 101 testDatasN++ … … 103 105 func InitProblem(Name *C.char, MaxIter int, HitRatio float64, SearchVar int, ProblemTypeString *C.char, numProcs int) { 104 106 ep = new(probs.ExprProblem) 105 106 //SysNames []string 107 //VarNames []string 108 107 109 108 ep.IndepNames = probIndepNames 110 109 ep.DepndNames = probDepndNames … … 124 123 125 124 initDone := make(chan int) 125 126 126 rt.GOMAXPROCS(numProcs) 127 rand.Seed(rand.Int63())127 //rand.Seed(rand.Int63()) 128 128 129 129 epcomm = new(probs.ExprProblemComm) … … 131 131 epcomm.Cmds = make(chan int) 132 132 epcomm.Rpts = make(chan *probs.ExprReportArray, 64) 133 epcomm.Res = make(chan *probs.ExprReportArray, 64) //Stops at 64 if nothing gets retrieved 133 134 epcomm.Gen = make(chan [2]int, 64) 134 135 … … 183 184 184 185 //export GetStepResult 185 func GetStepResult(nobestpush *int, bestnewminerr *int, bestlen1 *int, bestlen2 *int, testscore *int, ncoeff *int) *C.char { // coeff unsafe.Pointer 186 *nobestpush = 0 187 *bestnewminerr = 0 188 *bestlen1 = 0 189 *bestlen2 = 0 186 func GetStepResult(testscore *int, ncoeff *int) *C.char { 190 187 *testscore = 0 191 188 … … 194 191 resultNr++ 195 192 lastStepRes = elem 196 *bestlen1 = len(stepResult)197 193 if(elem != nil) { 198 //if elem.Nobestpush { 199 // *nobestpush = 1; 200 //} else { 201 // if elem.BestNewMinErr { 202 *bestnewminerr = int(elem.TestError()) 203 // } 204 *testscore = elem.TestScore() 205 *ncoeff = len(elem.Coeff()) 206 nCurrentCoeff = 0 207 nMaxCoeff = len(elem.Coeff()) 208 //*bestlen1 = 0 //elem.Bestlen1 209 *bestlen2 = 0 //elem.Bestlen2 210 return C.CString(elem.Expr().String()) 211 //} 194 *testscore = elem.TestScore() 195 *ncoeff = len(elem.Coeff()) 196 nCurrentCoeff = 0 197 nMaxCoeff = len(elem.Coeff()) 198 return C.CString(elem.Expr().String()) 212 199 } 213 200 } … … 218 205 func GetCoeffResult() float64 { 219 206 var res float64 = 0 220 if nCurrentCoeff < nMaxCoeff { 221 //item := (*float64) (unsafe.Pointer( uintptr(unsafe.Pointer(coeff)) + unsafe.Sizeof(float64(0)) * uintptr(i) )) 222 //*item = elem.Coeff[i] 223 207 if nCurrentCoeff < nMaxCoeff { 224 208 coeffs := lastStepRes.Coeff() 225 209 res = coeffs[nCurrentCoeff] … … 235 219 nRes := cps.Step() 236 220 237 resu, ok := <-epcomm.Rpts 238 239 //_ = ok 240 221 resu, ok := <- epcomm.Res 241 222 resultNr = nLastResults 242 223 … … 244 225 if ok && resu != nil { 245 226 stepResult = *resu 246 nNew = nRes // - nLastResults247 nLastResults = 0 //nRes227 nNew = nRes 228 nLastResults = 0 248 229 } 249 230 250 231 return nNew 232 } 233 234 //export Clear 235 func Clear() { 236 cps.Stop() 251 237 } 252 238 … … 257 243 } 258 244 return false 245 } 246 247 func CreateUsableVars(nEntries int) []int { 248 res := make([]int, nEntries) 249 for i := 0; i < nEntries; i++ { 250 res[i] = i 251 fmt.Printf("USEVARnew: %v\n", i) 252 } 253 return res 259 254 } 260 255 -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_init_method_1.go
r16231 r16615 12 12 13 13 GP := PS.cnfg.treecfg 14 fmt.Printf("%v\n", GP)15 14 16 15 eList := make([]expr.Expr, 0) … … 32 31 // exprs.SetSort(PS.cnfg.sortType) 33 32 exprs.SetSort(probs.PESORT_PARETO_TST_ERR) 34 33 35 34 for i, e := range eList { 36 35 fmt.Printf("%d: %v\n", i, e) 36 37 37 serial := make([]int, 0, 64) 38 38 serial = e.Serial(serial) 39 39 PS.Trie.InsertSerial(serial) 40 40 // on train data 41 re := RegressExpr(e, PS.prob) 41 42 //fmt.Printf("RegressExpr: e: %v || PS.prob: %v\n", e, PS.prob) 43 re := RegressExpr(e, PS.prob) //DER DO 44 //fmt.Printf("RegressExpr: e: %v || PS.prob: %v || %v \n", e, PS.prob, re) 45 42 46 re.SetUnitID(i) 43 47 exprs.Push(re) 44 48 } 49 45 50 exprs.Sort() 46 51 return exprs -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go
r16510 r16615 184 184 func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) { 185 185 186 //fmt.Printf("Init'n PGE\n")186 fmt.Printf("Init'n PGE\n") 187 187 // setup data 188 188 … … 201 201 PS.cnfg.simprules = srules 202 202 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)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) 207 207 208 208 PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots)) … … 228 228 229 229 case expr.VAR: 230 //fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)230 fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars) 231 231 for _, i := range PS.cnfg.treecfg.UsableVars { 232 232 PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i)) … … 284 284 } 285 285 286 func (PS *PgeSearch) Stop() { 287 PS.stop = true 288 } 289 286 290 func (PS *PgeSearch) Evaluate() { 287 291 … … 291 295 continue 292 296 } 293 re := RegressExpr(e, PS.prob)294 // //fmt.Printf("reg: %v\n", re)295 PS.eval_out <- re297 //re := 298 //fmt.Printf("reg: %v\n", re) 299 PS.eval_out <- RegressExpr(e, PS.prob) 296 300 } 297 301 … … 382 386 } 383 387 384 func (PS *PgeSearch) SingleStep2() { 388 389 func (PS *PgeSearch) Step() int { 390 385 391 loop := 0 386 392 eval_cnt := 0 // for channeled eval … … 389 395 390 396 ex := PS.expandPeeled(es) 391 397 398 cnt_ins := 0 399 400 inserts := make(probs.ExprReportArray, 0) 392 401 for cnt := range ex { 393 402 E := ex[cnt] … … 414 423 415 424 // for serial eval 416 // re := RegressExpr(e, PS.prob) 417 418 // start channeled eval 419 PS.eval_in <- e 420 eval_cnt++ 421 } 422 } 423 for i := 0; i < eval_cnt; i++ { 424 re := <-PS.eval_out 425 // end channeled eval 426 427 // check for NaN/Inf in re.error and if so, skip 428 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) { 429 // fmt.Printf("Bad Error\n%v\n", re) 430 continue 431 } 432 433 if re.TestError() < PS.minError { 434 PS.minError = re.TestError() 435 } 436 437 // check for coeff == 0 438 doIns := true 439 for _, c := range re.Coeff() { 440 // i > 0 for free coeff 441 if math.Abs(c) < PS.cnfg.zeroEpsilon { 442 doIns = false 443 break 444 } 445 } 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++ 425 //re := RegressExpr(e, PS.prob) //needed for TestScore calc via RegressExpr 426 //inserts = append(inserts, re) 454 427 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 eval464 PS.Queue.Sort()465 }466 467 //Problem468 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 := 0476 eval_cnt := 0477 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.ExpreRe484 //} 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 continue495 }496 for _, e := range E {497 if e == nil {498 continue499 }500 if !PS.cnfg.treecfg.CheckExpr(e) {501 continue502 }503 serial := make([]int, 0, 64)504 serial = e.Serial(serial)505 ins := PS.Trie.InsertSerial(serial)506 507 if !ins {508 continue509 }510 PS.eval_in <- e511 eval_cnt++512 }513 }514 for i := 0; i < eval_cnt; i++ {515 re := <-PS.eval_out516 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) {517 continue518 }519 if re.TestError() < PS.minError {520 PS.minError = re.TestError()521 }522 doIns := true523 for _, c := range re.Coeff() {524 if math.Abs(c) < PS.cnfg.zeroEpsilon {525 doIns = false526 break527 }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 PR545 }546 547 //Problem548 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 = false556 PR.Nobestpush = false557 558 e := PS.Queue.Pop().(*probs.ExprReport)559 560 bPush := true561 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon {562 //fmt.Println("No Best Push")563 PR.Nobestpush = true564 p--565 continue566 }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] = e574 PR.Bestlen1 = p575 PR.Bestlen2 = PS.Best.Len()576 PR.Expre = e.Expr()577 PR.ExpreRe = e578 PR.Es = e579 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 = true589 //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] = PR596 }597 598 return PRes599 }600 601 func (PS *PgeSearch) Step() int {602 603 loop := 0604 eval_cnt := 0 // for channeled eval605 606 es := PS.peel()607 608 ex := PS.expandPeeled(es)609 610 cnt_ins := 0611 612 for cnt := range ex {613 E := ex[cnt]614 615 if E == nil {616 continue617 }618 619 for _, e := range E {620 if e == nil {621 continue622 }623 if !PS.cnfg.treecfg.CheckExpr(e) {624 continue625 }626 627 // check ipre_trie628 serial := make([]int, 0, 64)629 serial = e.Serial(serial)630 ins := PS.Trie.InsertSerial(serial)631 if !ins {632 continue633 }634 635 // for serial eval636 // re := RegressExpr(e, PS.prob)637 638 428 // start channeled eval 639 429 PS.eval_in <- e … … 681 471 cnt_ins++ 682 472 PS.Queue.Push(re) 683 } 684 } 685 // } // for sequential eval 686 PS.Queue.Sort() 687 473 //fmt.Printf("Testscore: %v\n", re.TestScore()) 474 //PS.commup.Rpts <- &re //sort missing! > 3 ergs 475 } 476 } 477 478 PS.Queue.Sort() //3 besten werden beim naechsten peel ausgegeben 479 480 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ { 481 val := PS.Queue.Pop().(*probs.ExprReport) 482 inserts = append(inserts, val) 483 } 484 485 for _, e := range inserts { 486 PS.Queue.Push(e) 487 } 488 489 PS.Queue.Sort() 490 491 PS.commup.Res <- &inserts 492 493 PS.reportExpr() 688 494 PS.iter++ 689 PS.reportExpr() //new690 return 3495 496 return len(inserts) 691 497 } 692 498 … … 702 508 bPush := true 703 509 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon { 704 ////fmt.Println("No Best Push")510 fmt.Println("No Best Push") 705 511 p-- 706 512 continue … … 716 522 717 523 if e.TestScore() > PS.maxScore { 524 fmt.Printf("Testscore: %v\n", e.TestScore()) 718 525 PS.maxScore = e.TestScore() 719 526 } 720 527 if e.TestError() < PS.minError { 721 528 PS.minError = e.TestError() 722 ////fmt.Printf("Best New Min Error: %v\n", e)529 fmt.Printf("Best New Min Error: %v\n", e) 723 530 } 724 531 if e.Size() > PS.maxSize { … … 727 534 728 535 } 729 PS.commup.Rpts <- &rpt 536 537 //fmt.Printf("sand %d best pushes in peel\n", len(rpt)) 538 //PS.commup.Res <- &rpt 539 540 _ = rpt 541 730 542 return es 731 543 } … … 755 567 } 756 568 757 //Hier ist das pgeRpt problem, liefert immer die besten pgerpt cnt ergebnisse zur ck und ich schneide aus arrazy, werden auch unsortiert569 //Hier ist das pgeRpt problem, liefert immer die besten pgerpt cnt ergebnisse zurueck 758 570 // //* 759 func (PS *PgeSearch) reportExpr() int{760 //PS.cnfg.pgeRptCount++ 571 func (PS *PgeSearch) reportExpr() { 572 761 573 cnt := PS.cnfg.pgeRptCount 762 //*PS.Best.Sort()574 PS.Best.Sort() 763 575 764 576 // repot best equations 765 577 rpt := make(probs.ExprReportArray, cnt) 766 //*if PS.Best.Len() < cnt {767 //*cnt = PS.Best.Len()768 //*}578 if PS.Best.Len() < cnt { 579 cnt = PS.Best.Len() 580 } 769 581 copy(rpt, PS.Best.GetQueue()[:cnt]) 770 582 … … 779 591 } 780 592 781 ////fmt.Printf("Iter: %d %f %f\n", PS.iter, errSum/float64(errCnt), PS.minError)593 PS.mainLog.Printf("Iter: %d %f %f\n", PS.iter, errSum/float64(errCnt), PS.minError) 782 594 783 595 PS.ipreLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst) … … 785 597 786 598 //PS.commup.Rpts <- &rpt 787 788 return errCnt 599 600 } 601 602 func (PS *PgeSearch) FirstPeel() { 603 PS.peel() 789 604 } 790 605 … … 869 684 if len(guess) > 0 { 870 685 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) 686 // fmt.Printf("x_dims: %d %d\n", x_dim, x_dim2) 875 687 876 688 // Callback version 877 878 879 689 coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test) 880 881 690 882 691 // Stack version … … 911 720 R = new(probs.ExprReport) 912 721 R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/ 913 914 722 R.SetCoeff(coeff) 915 723 R.Expr().CalcExprStats() … … 980 788 981 789 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 790 PS.id = 0 //maxGen ? wieso steht des do, id -> procId bei multi searches 983 791 984 792 var PC PgeConfig … … 1001 809 PC.maxGen = maxGen 1002 810 PS.cnfg = PC 1003 //PS.Stop = falseis in init811 PS.stop = false //is in init 1004 812 PS.iter = 0 1005 813 } … … 1011 819 return PS.iter 1012 820 } 821 822 823 824 825 /********************** DELETED ************************/ 826 827 828 func (PS *PgeSearch) SingleStep22() { 829 loop := 0 830 eval_cnt := 0 // for channeled eval 831 832 es := PS.peel() 833 834 ex := PS.expandPeeled(es) 835 836 for cnt := range ex { 837 E := ex[cnt] 838 839 if E == nil { 840 continue 841 } 842 843 for _, e := range E { 844 if e == nil { 845 continue 846 } 847 if !PS.cnfg.treecfg.CheckExpr(e) { 848 continue 849 } 850 851 // check ipre_trie 852 serial := make([]int, 0, 64) 853 serial = e.Serial(serial) 854 ins := PS.Trie.InsertSerial(serial) 855 if !ins { 856 continue 857 } 858 859 // for serial eval 860 // re := RegressExpr(e, PS.prob) 861 862 // start channeled eval 863 PS.eval_in <- e 864 eval_cnt++ 865 } 866 } 867 for i := 0; i < eval_cnt; i++ { 868 re := <-PS.eval_out 869 // end channeled eval 870 871 // check for NaN/Inf in re.error and if so, skip 872 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) { 873 // fmt.Printf("Bad Error\n%v\n", re) 874 continue 875 } 876 877 if re.TestError() < PS.minError { 878 PS.minError = re.TestError() 879 } 880 881 // check for coeff == 0 882 doIns := true 883 for _, c := range re.Coeff() { 884 // i > 0 for free coeff 885 if math.Abs(c) < PS.cnfg.zeroEpsilon { 886 doIns = false 887 break 888 } 889 } 890 891 if doIns { 892 re.SetProcID(PS.id) 893 re.SetIterID(PS.iter) 894 re.SetUnitID(loop) 895 re.SetUniqID(PS.neqns) 896 loop++ 897 PS.neqns++ 898 899 //fmt.Printf("SS2Queue.Push(): %v\n%v\n\n", re.Expr(), serial) 900 ////fmt.Printf("INSQueue.Push(): %v\n", re) 901 ////fmt.Printf("INSQueue.Push(): %v\n", re.Expr()) 902 903 PS.Queue.Push(re) 904 905 } 906 } 907 // } // for sequential eval 908 PS.Queue.Sort() 909 } 910 911 //Problem 912 func (PS *PgeSearch) SingleStep2() []*PeelResult { 913 if os.Getenv("PGEDEBUG") == "1" { 914 fmt.Printf("Init PgeSearch: %#v \n", PS) 915 fmt.Printf("Init PgeProblem: %#v \n", PS.prob) 916 } 917 918 919 loop := 0 920 eval_cnt := 0 921 PR := PS.peelRes2() 922 923 es := make([]*probs.ExprReport, len(PR)) 924 925 for i, elem := range PR { 926 if(elem != nil) { 927 es[i] = elem.ExpreRe 928 //} else { 929 // es[i] = new(probs.ExprReport) 930 } 931 } 932 933 ex := PS.expandPeeled(es) 934 935 for cnt := range ex { 936 E := ex[cnt] 937 if E == nil { 938 continue 939 } 940 for _, e := range E { 941 if e == nil { 942 continue 943 } 944 if !PS.cnfg.treecfg.CheckExpr(e) { 945 continue 946 } 947 serial := make([]int, 0, 64) 948 serial = e.Serial(serial) 949 ins := PS.Trie.InsertSerial(serial) 950 951 if !ins { 952 continue 953 } 954 PS.eval_in <- e 955 eval_cnt++ 956 } 957 } 958 for i := 0; i < eval_cnt; i++ { 959 re := <-PS.eval_out 960 if math.IsNaN(re.TestError()) || math.IsInf(re.TestError(), 0) { 961 continue 962 } 963 if re.TestError() < PS.minError { 964 PS.minError = re.TestError() 965 } 966 doIns := true 967 for _, c := range re.Coeff() { 968 if math.Abs(c) < PS.cnfg.zeroEpsilon { 969 doIns = false 970 break 971 } 972 } 973 if doIns { 974 re.SetProcID(PS.id) 975 re.SetIterID(PS.iter) 976 re.SetUnitID(loop) 977 re.SetUniqID(PS.neqns) 978 loop++ 979 PS.neqns++ 980 PS.Queue.Push(re) 981 } 982 } 983 PS.Queue.Sort() 984 985 PS.reportExpr() 986 PS.iter++ 987 988 return PR 989 } 990 991 //Problem 992 func (PS *PgeSearch) peelRes2() []*PeelResult { 993 //es := make([]*probs.ExprReport, PS.cnfg.peelCnt) 994 PRes := make([]*PeelResult, PS.cnfg.peelCnt) 995 996 for p := 0; p < PS.cnfg.peelCnt && PS.Queue.Len() > 0; p++ { 997 PR := new(PeelResult) 998 999 PR.BestNewMinErr = false 1000 PR.Nobestpush = false 1001 1002 e := PS.Queue.Pop().(*probs.ExprReport) 1003 1004 bPush := true 1005 if len(e.Coeff()) == 1 && math.Abs(e.Coeff()[0]) < PS.cnfg.zeroEpsilon { 1006 //fmt.Println("No Best Push") 1007 PR.Nobestpush = true 1008 p-- 1009 continue 1010 } 1011 1012 if bPush { 1013 //fmt.Printf("pop/push (%d,%d): %v\n", p, PS.Best.Len(), e.Expr()) 1014 PS.Best.Push(e) 1015 } 1016 1017 //es[p] = e 1018 PR.Bestlen1 = p 1019 PR.Bestlen2 = PS.Best.Len() 1020 PR.Expre = e.Expr() 1021 PR.ExpreRe = e 1022 PR.Es = e 1023 PR.Coeff = e.Coeff() 1024 PR.TestScore = e.TestScore() 1025 1026 1027 if e.TestScore() > PS.maxScore { 1028 PS.maxScore = e.TestScore() 1029 } 1030 if e.TestError() < PS.minError { 1031 PS.minError = e.TestError() 1032 PR.BestNewMinErr = true 1033 //fmt.Printf("Best New Min Error: %v\n", e) 1034 } 1035 if e.Size() > PS.maxSize { 1036 PS.maxSize = e.Size() 1037 } 1038 1039 PRes[p] = PR 1040 } 1041 1042 return PRes 1043 }
Note: See TracChangeset
for help on using the changeset viewer.