本文整理汇总了Golang中github.com/verdverm/go-symexpr.Expr.Eval方法的典型用法代码示例。如果您正苦于以下问题:Golang Expr.Eval方法的具体用法?Golang Expr.Eval怎么用?Golang Expr.Eval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/verdverm/go-symexpr.Expr
的用法示例。
在下文中一共展示了Expr.Eval方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenBenchData
func GenBenchData(e expr.Expr, vars []BenchmarkVar, samples int) (pts []Point) {
pts = make([]Point, 0)
if vars[0].Rtype == Uniform {
for i := 0; i < samples; i++ {
input := make([]float64, len(vars))
retry:
for j, v := range vars {
r := rand.Float64()
input[j] = (r * (v.H - v.L)) + v.L
}
out := e.Eval(0, input, nil, nil)
if math.IsNaN(out) || math.IsInf(out, 0) || math.Abs(out) > 100000.0 {
goto retry
}
var pnt Point
pnt.SetIndeps(input)
pnt.SetDepnds([]float64{out})
pts = append(pts, pnt)
}
} else { // RangeType == Equal
counter := make([]float64, len(vars))
for j, v := range vars {
counter[j] = v.L
}
L1, L2 := len(vars)-1, vars[len(vars)-1].L
for counter[L1] <= L2 {
input := make([]float64, len(vars))
copy(input, counter)
out := e.Eval(0, input, nil, nil)
var pnt Point
pnt.SetIndeps(input)
pnt.SetDepnds([]float64{out})
pts = append(pts, pnt)
// increment counter
for j, v := range vars {
counter[j] += v.S
if counter[j] > v.H {
counter[j] = v.L
} else {
break
}
}
}
}
return
}
示例2: scoreExpr
func scoreExpr(e expr.Expr, P *probs.ExprProblem, dataSets []*probs.PointSet, coeff []float64) (hitsL1, hitsL2, evalCnt, nanCnt, infCnt int, l1_err, l2_err float64) {
var l1_sum, l2_sum float64
for _, PS := range dataSets {
for _, p := range PS.Points() {
y := p.Depnd(P.SearchVar)
var out float64
if P.SearchType == probs.ExprBenchmark {
out = e.Eval(0, p.Indeps(), coeff, PS.SysVals())
} else if P.SearchType == probs.ExprDiffeq {
out = e.Eval(p.Indep(0), p.Indeps()[1:], coeff, PS.SysVals())
}
if math.IsNaN(out) {
nanCnt++
continue
} else if math.IsInf(out, 0) {
infCnt++
continue
} else {
evalCnt++
}
diff := out - y
l1_val := math.Abs(diff)
l2_val := diff * diff
l1_sum += l1_val
l2_sum += l2_val
if l1_val < P.HitRatio {
hitsL1++
}
if l2_val < P.HitRatio {
hitsL2++
}
}
}
if evalCnt == 0 {
l1_err = math.NaN()
l2_err = math.NaN()
} else {
fEvalCnt := float64(evalCnt + 1)
l1_err = l1_sum / fEvalCnt
l2_err = math.Sqrt(l2_sum / fEvalCnt)
}
return
}