Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16615


Ignore:
Timestamp:
02/19/19 18:04:42 (5 years ago)
Author:
hmaislin
Message:

#2929: Added updated go and plugin files

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  
    77  "fmt"
    88  rt "runtime"
    9   rand "math/rand"
     9  //rand "math/rand"
    1010  "strings"
    1111  probs "github.com/verdverm/go-pge/problems"
     
    5151  trainDatasN = 0
    5252  nLastResults = 0
     53
    5354  cps.CreateDS(maxGen, pgeRptEpoch, pgeRptCount, pgeArchiveCap, peelCnt, evalrCount, zeroEpsilon, goInitMethod, goGrowMethod, sortType)
    5455 
     
    6061
    6162//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) {
     63func InitTreeParams(Roots *C.char, Nodes *C.char, NonTrig *C.char, Leafs *C.char, nUseableVars int, MaxSize int, MinSize int, MaxDepth int, MinDepth int) {
    6364  tp = new(probs.TreeParams)
    6465  goRoots := C.GoString(Roots)
     
    6667  goNonTrig := C.GoString(NonTrig)
    6768  goLeafs := C.GoString(Leafs)
    68   goUsableVars := CIntArrayToSlice(UsableVars, nUseableVars)
     69  goUsableVars := CreateUsableVars(nUseableVars)
    6970  tp.CreateTreeParams(goRoots, goNodes, goNonTrig, goLeafs, goUsableVars, MaxSize, MinSize, MaxDepth, MinDepth)
    7071}
     
    7273//export AddTrainData
    7374func 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)
    7576  trainData = new(probs.PointSet)
    7677 
     
    9697 
    9798  testData.InitTrainData(goIndepNames, goDepndNames, matrix, nEntries)
     99 
    98100  testDatas[testDatasN] = testData
    99101  testDatasN++
     
    103105func InitProblem(Name *C.char, MaxIter int, HitRatio float64, SearchVar int, ProblemTypeString *C.char, numProcs int) {
    104106  ep = new(probs.ExprProblem)
    105  
    106   //SysNames   []string
    107   //VarNames []string
    108  
     107   
    109108  ep.IndepNames = probIndepNames
    110109  ep.DepndNames = probDepndNames
     
    124123 
    125124  initDone := make(chan int)
     125 
    126126  rt.GOMAXPROCS(numProcs)
    127   rand.Seed(rand.Int63())
     127  //rand.Seed(rand.Int63())
    128128 
    129129  epcomm = new(probs.ExprProblemComm)
     
    131131  epcomm.Cmds = make(chan int)
    132132    epcomm.Rpts = make(chan *probs.ExprReportArray, 64)
     133  epcomm.Res = make(chan *probs.ExprReportArray, 64) //Stops at 64 if nothing gets retrieved
    133134  epcomm.Gen = make(chan [2]int, 64)
    134135 
     
    183184
    184185//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
     186func GetStepResult(testscore *int, ncoeff *int) *C.char {
    190187  *testscore = 0
    191188 
     
    194191    resultNr++
    195192    lastStepRes = elem
    196     *bestlen1 = len(stepResult)
    197193    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())
    212199    }
    213200  }
     
    218205func GetCoeffResult() float64 {
    219206  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 {   
    224208    coeffs := lastStepRes.Coeff()
    225209    res = coeffs[nCurrentCoeff]
     
    235219  nRes := cps.Step()
    236220 
    237   resu, ok := <-epcomm.Rpts
    238  
    239   //_ = ok
    240  
     221  resu, ok := <- epcomm.Res
    241222  resultNr = nLastResults
    242223 
     
    244225  if ok && resu != nil {
    245226    stepResult = *resu
    246     nNew = nRes // - nLastResults
    247     nLastResults = 0 //nRes
     227    nNew = nRes
     228    nLastResults = 0
    248229  }
    249230   
    250231  return nNew
     232}
     233
     234//export Clear
     235func Clear() {
     236  cps.Stop()
    251237}
    252238
     
    257243  }
    258244  return false 
     245}
     246
     247func 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
    259254}
    260255
  • branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_init_method_1.go

    r16231 r16615  
    1212
    1313  GP := PS.cnfg.treecfg
    14   fmt.Printf("%v\n", GP)
    1514
    1615  eList := make([]expr.Expr, 0)
     
    3231  // exprs.SetSort(PS.cnfg.sortType)
    3332  exprs.SetSort(probs.PESORT_PARETO_TST_ERR)
    34 
     33 
    3534  for i, e := range eList {
    3635    fmt.Printf("%d:  %v\n", i, e)
     36   
    3737    serial := make([]int, 0, 64)
    3838    serial = e.Serial(serial)
    3939    PS.Trie.InsertSerial(serial)
    4040    // 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   
    4246    re.SetUnitID(i)
    4347    exprs.Push(re)
    4448  }
     49
    4550  exprs.Sort()
    4651  return exprs
  • branches/2929_PrioritizedGrammarEnumeration/HeuristicLab.Algorithms.DataAnalysis.PGE/3.3/go-code/go-pge/plug/pge_search.go

    r16510 r16615  
    184184func (PS *PgeSearch) Init(done chan int, prob *probs.ExprProblem, logdir string, input interface{}) {
    185185
    186   //fmt.Printf("Init'n PGE\n")
     186  fmt.Printf("Init'n PGE\n")
    187187  // setup data
    188188
     
    201201  PS.cnfg.simprules = srules
    202202
    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)
    207207
    208208  PS.GenRoots = make([]expr.Expr, len(PS.cnfg.treecfg.Roots))
     
    228228
    229229    case expr.VAR:
    230       //fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)
     230      fmt.Println("Use Vars: ", PS.cnfg.treecfg.UsableVars)
    231231      for _, i := range PS.cnfg.treecfg.UsableVars {
    232232        PS.GenLeafs = append(PS.GenLeafs, expr.NewVar(i))
     
    284284}
    285285
     286func (PS *PgeSearch) Stop() {
     287  PS.stop = true
     288}
     289
    286290func (PS *PgeSearch) Evaluate() {
    287291
     
    291295      continue
    292296    }
    293     re := RegressExpr(e, PS.prob)
    294     ////fmt.Printf("reg: %v\n", re)
    295     PS.eval_out <- re
     297    //re :=
     298    //fmt.Printf("reg: %v\n", re)
     299    PS.eval_out <- RegressExpr(e, PS.prob)
    296300  }
    297301
     
    382386}
    383387
    384 func (PS *PgeSearch) SingleStep2() {
     388
     389func (PS *PgeSearch) Step() int {
     390
    385391  loop := 0
    386392  eval_cnt := 0 // for channeled eval
     
    389395
    390396  ex := PS.expandPeeled(es)
    391 
     397 
     398  cnt_ins := 0
     399
     400  inserts := make(probs.ExprReportArray, 0)
    392401  for cnt := range ex {
    393402    E := ex[cnt]
     
    414423
    415424      // 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)
    454427     
    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 
    638428      // start channeled eval
    639429      PS.eval_in <- e
     
    681471      cnt_ins++
    682472      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()
    688494  PS.iter++
    689   PS.reportExpr() //new
    690   return 3
     495 
     496  return len(inserts)
    691497}
    692498
     
    702508    bPush := true
    703509    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")
    705511      p--
    706512      continue
     
    716522
    717523    if e.TestScore() > PS.maxScore {
     524      fmt.Printf("Testscore: %v\n", e.TestScore())
    718525      PS.maxScore = e.TestScore()
    719526    }
    720527    if e.TestError() < PS.minError {
    721528      PS.minError = e.TestError()
    722       ////fmt.Printf("Best New Min Error:  %v\n", e)
     529      fmt.Printf("Best New Min Error:  %v\n", e)
    723530    }
    724531    if e.Size() > PS.maxSize {
     
    727534   
    728535  }
    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 
    730542  return es
    731543}
     
    755567}
    756568
    757 //Hier ist das pgeRpt problem, liefert immer die besten pgerpt cnt ergebnisse zurck und ich schneide aus arrazy, werden auch unsortiert
     569//Hier ist das pgeRpt problem, liefert immer die besten pgerpt cnt ergebnisse zurueck
    758570// //*
    759 func (PS *PgeSearch) reportExpr() int {
    760   //PS.cnfg.pgeRptCount++
     571func (PS *PgeSearch) reportExpr() {
     572
    761573  cnt := PS.cnfg.pgeRptCount
    762   //*PS.Best.Sort()
     574  PS.Best.Sort()
    763575
    764576  // repot best equations
    765577  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  }
    769581  copy(rpt, PS.Best.GetQueue()[:cnt])
    770582
     
    779591  }
    780592
    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)
    782594
    783595  PS.ipreLog.Println(PS.iter, PS.neqns, PS.Trie.cnt, PS.Trie.vst)
     
    785597
    786598  //PS.commup.Rpts <- &rpt
    787  
    788   return errCnt
     599
     600}
     601
     602func (PS *PgeSearch) FirstPeel() {
     603  PS.peel()
    789604}
    790605
     
    869684  if len(guess) > 0 {
    870685
    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)
    875687
    876688    // Callback version
    877    
    878    
    879689    coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test)
    880    
    881690
    882691    // Stack version
     
    911720  R = new(probs.ExprReport)
    912721  R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/
    913 
    914722  R.SetCoeff(coeff)
    915723  R.Expr().CalcExprStats()
     
    980788
    981789func (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
    983791 
    984792  var PC PgeConfig
     
    1001809  PC.maxGen = maxGen
    1002810  PS.cnfg = PC
    1003   //PS.Stop = false is in init
     811  PS.stop = false //is in init
    1004812  PS.iter = 0
    1005813}
     
    1011819  return PS.iter
    1012820}
     821
     822
     823
     824
     825/********************** DELETED ************************/
     826
     827
     828func (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
     912func (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
     992func (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.