Changeset 16231 for branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code
- Timestamp:
- 10/17/18 04:47:09 (6 years ago)
- Location:
- branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code
- Files:
-
- 10 added
- 10 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/bbsr.go
r16191 r16231 10 10 11 11 func (PS *PgeSearch) GenInitExpr() *probs.ReportQueue { 12 13 fmt.Println("Call gen method")14 15 16 12 switch PS.cnfg.initMethod { 17 13 case "method1": -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge.go
r16230 r16231 32 32 var probDepndNames []string 33 33 34 var stepResult []*pge.PeelResult35 var lastStepRes *p ge.PeelResult34 var stepResult probs.ExprReportArray 35 var lastStepRes *probs.ExprReport 36 36 var resultNr int 37 37 38 38 var nCurrentCoeff int 39 39 var nMaxCoeff int 40 41 var nLastResults int 40 42 41 43 //export InitSearch … … 48 50 testDatasN = 0 49 51 trainDatasN = 0 50 52 nLastResults = 0 51 53 cps.CreateDS(maxGen, pgeRptEpoch, pgeRptCount, pgeArchiveCap, peelCnt, evalrCount, zeroEpsilon, goInitMethod, goGrowMethod, sortType) 52 54 … … 79 81 probDepndNames = goDepndNames 80 82 81 trainData.InitTrainData F(goIndepNames, goDepndNames, matrix, nEntries)83 trainData.InitTrainData(goIndepNames, goDepndNames, matrix, nEntries) 82 84 83 85 trainDatas[trainDatasN] = trainData … … 93 95 goDepndNames := strings.Split(C.GoString(depndNames), " ") 94 96 95 testData.InitT estDataF(goIndepNames, goDepndNames, matrix, nEntries)97 testData.InitTrainData(goIndepNames, goDepndNames, matrix, nEntries) 96 98 testDatas[testDatasN] = testData 97 99 testDatasN++ … … 135 137 epcomm.Rpts = make(chan *probs.ExprReportArray, 64) 136 138 epcomm.Gen = make(chan [2]int, 64) 139 137 140 fmt.Printf("6\n") 138 141 … … 195 198 *testscore = 0 196 199 197 if resultNr < cps.GetPeelCount(){200 if resultNr < len(stepResult) && stepResult != nil { 198 201 elem := stepResult[resultNr] 199 202 resultNr++ 200 203 lastStepRes = elem 204 *bestlen1 = len(stepResult) 201 205 if(elem != nil) { 202 if elem.Nobestpush {203 *nobestpush = 1;204 } else {205 if elem.BestNewMinErr {206 *bestnewminerr = 1207 }208 *testscore = elem.TestScore 209 *ncoeff = len(elem.Coeff )206 //if elem.Nobestpush { 207 // *nobestpush = 1; 208 //} else { 209 // if elem.BestNewMinErr { 210 *bestnewminerr = int(elem.TestError()) 211 // } 212 *testscore = elem.TestScore() 213 *ncoeff = len(elem.Coeff()) 210 214 nCurrentCoeff = 0 211 nMaxCoeff = len(elem.Coeff )212 *bestlen1 =elem.Bestlen1213 *bestlen2 = elem.Bestlen2214 return C.CString(elem.Expr e.String())215 }215 nMaxCoeff = len(elem.Coeff()) 216 //*bestlen1 = 0 //elem.Bestlen1 217 *bestlen2 = 0 //elem.Bestlen2 218 return C.CString(elem.Expr().String()) 219 //} 216 220 } 217 221 } … … 226 230 //*item = elem.Coeff[i] 227 231 228 res = lastStepRes.Coeff[nCurrentCoeff] 232 coeffs := lastStepRes.Coeff() 233 res = coeffs[nCurrentCoeff] 229 234 } 230 235 nCurrentCoeff++ … … 233 238 234 239 //export StepW 235 func StepW() {240 func StepW() int { 236 241 resultNr = 0 237 stepResult = cps.SingleStep() 242 stepResult = nil 243 nRes := cps.Step() 244 245 resu, ok := <-epcomm.Rpts 246 247 //_ = ok 248 249 resultNr = nLastResults 250 251 nNew := 0 252 if ok && resu != nil { 253 stepResult = *resu 254 nNew = nRes - nLastResults 255 nLastResults = nRes 256 } 257 258 return nNew 238 259 } 239 260 -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_init_method_1.go
r16191 r16231 12 12 13 13 GP := PS.cnfg.treecfg 14 fmt.Printf("%v\n", GP) 14 15 15 16 eList := make([]expr.Expr, 0) … … 31 32 // exprs.SetSort(PS.cnfg.sortType) 32 33 exprs.SetSort(probs.PESORT_PARETO_TST_ERR) 33 34 34 35 for i, e := range eList { 35 36 fmt.Printf("%d: %v\n", i, e) 36 37 serial := make([]int, 0, 64) 37 38 serial = e.Serial(serial) 38 39 PS.Trie.InsertSerial(serial) 39 40 // on train data 40 41 //fmt.Printf("RegressExpr: e: %v || PS.prob: %v\n", e, PS.prob) 42 re := RegressExpr(e, PS.prob) //DER DO 43 //fmt.Printf("RegressExpr: e: %v || PS.prob: %v || %v \n", e, PS.prob, re) 44 41 re := RegressExpr(e, PS.prob) 45 42 re.SetUnitID(i) 46 43 exprs.Push(re) 47 44 } 48 49 45 exprs.Sort() 50 46 return exprs -
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 } -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/benchmarks.go
r16080 r16231 3 3 import ( 4 4 // "fmt" 5 expr "github.com /verdverm/go-symexpr"5 expr "github.com_del/verdverm/go-symexpr" 6 6 "math" 7 7 "math/rand" -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/data.go
r16230 r16231 8 8 "math/rand" 9 9 "os" 10 "C"11 "unsafe"12 10 ) 13 11 … … 128 126 } 129 127 130 func (trainData *PointSet) InitTrainDataF(indepNames []string, depndNames []string, matrix unsafe.Pointer, nEntries int) {131 trainData.ReadPointSet("C:/Users/Hansi/Desktop/Data.trn")132 }133 134 func (trainData *PointSet) InitTestDataF(indepNames []string, depndNames []string, matrix unsafe.Pointer, nEntries int) {135 trainData.ReadPointSet("C:/Users/Hansi/Desktop/Data.tst")136 }137 138 func (trainData *PointSet) InitTrainData(indepNames []string, depndNames []string, matrix unsafe.Pointer, nEntries int) {139 trainData.indepNames = indepNames //First line in .trn file140 trainData.numDim = len(trainData.indepNames)141 trainData.depndNames = depndNames //Second line in .trn file142 143 fmt.Printf("Var Names = %v | %v\n", trainData.depndNames, trainData.indepNames)144 var nClum int = len(indepNames) + len(depndNames)145 146 for i := 0; i < nEntries; i++ {147 var pnt Point148 for j := 0; j < len(trainData.indepNames); j++ {149 elemNr := i * nClum + j150 item := (*float64) (unsafe.Pointer( uintptr(unsafe.Pointer(matrix)) + unsafe.Sizeof(float64(0)) * uintptr(elemNr) ))151 pnt.indep = append(pnt.indep, *item)152 153 if os.Getenv("PGEDEBUG") == "1" {154 fmt.Printf("Adding independend Test/Train Data (%v,%v): %v\n", i, j, *item)155 }156 }157 158 for j := len(trainData.indepNames); j < (len(trainData.indepNames) + len(trainData.depndNames)); j++ {159 elemNr := i * nClum + j160 item := (*float64) (unsafe.Pointer( uintptr(unsafe.Pointer(matrix)) + unsafe.Sizeof(float64(0)) * uintptr(elemNr) ))161 pnt.depnd = append(pnt.depnd, *item )162 163 if os.Getenv("PGEDEBUG") == "1" {164 fmt.Printf("Adding dependend (right side) Test/Train Data (%v, %v): %v\n", i, j, *item)165 }166 }167 168 if len(pnt.indep) > 0 {169 trainData.dataPoints = append(trainData.dataPoints, pnt)170 }171 }172 fmt.Printf("Num Points: %v\n", len(trainData.dataPoints))173 174 //if os.Getenv("PGEDEBUG") == "2" {175 // DebugPrint(trainData)176 //}177 }178 179 //func (trainData *PointSet) DebugPrint() {180 // for index, elem in range181 //}182 183 128 func (d *PointSet) ReadPointSet(filename string) { 184 129 ftotal, err := os.OpenFile(filename, os.O_RDONLY, 0) -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/problem.go
r16183 r16231 7 7 "strings" 8 8 9 expr "github.com /verdverm/go-symexpr"9 expr "github.com_del/verdverm/go-symexpr" 10 10 ) 11 11 … … 166 166 return list[0:i] 167 167 } 168 169 170 func (ep *ExprProblem) CreatePS(Name string, MaxIter int, HitRatio float64, SearchVar int, ProblemTypeString string) { //IndepNames []string, DepndNames []string, SysNames []string171 ep.SearchType = ProblemTypeFromString(ProblemTypeString)172 ep.Name = Name173 174 ep.TrainFns = append(ep.TrainFns, "dummy")175 ep.TestFns = append(ep.TestFns, "dummy")176 177 ep.MaxIter = MaxIter178 ep.HitRatio = HitRatio179 ep.SearchVar = SearchVar180 } -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/report.go
r16080 r16231 4 4 "container/list" 5 5 "fmt" 6 expr "github.com /verdverm/go-symexpr"6 expr "github.com_del/verdverm/go-symexpr" 7 7 "sort" 8 8 ) -
branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/problems/treeparams.go
r16183 r16231 8 8 "strings" 9 9 10 expr "github.com /verdverm/go-symexpr"10 expr "github.com_del/verdverm/go-symexpr" 11 11 ) 12 12 … … 297 297 tp.TmpMinSize, tp.TmpMinDepth = tp.MinSize, tp.MinDepth 298 298 } 299 300 301 func (TP *TreeParams) CreateTreeParams(Roots string, Nodes string, NonTrig string, Leafs string, UsableVars []int, MaxSize int, MinSize int, MaxDepth int, MinDepth int) {302 TP.RootsS = strings.Fields(Roots)303 TP.RootsT, TP.Roots = fillExprStuff(TP.RootsS)304 305 TP.NodesS = strings.Fields(Nodes)306 TP.NodesT, TP.Nodes = fillExprStuff(TP.NodesS)307 308 TP.NonTrigS = strings.Fields(NonTrig)309 TP.NonTrigT, TP.NonTrig = fillExprStuff(TP.NonTrigS)310 311 TP.LeafsS = strings.Fields(Leafs)312 TP.LeafsT, TP.Leafs = fillExprStuff(TP.LeafsS)313 314 TP.UsableVars = UsableVars315 316 TP.MaxSize = MaxSize317 TP.MinSize = MinSize318 TP.MaxDepth = MaxDepth319 TP.MinDepth = MinDepth320 }
Note: See TracChangeset
for help on using the changeset viewer.