示例#1
0
func RegressExpr(E expr.Expr, P *probs.ExprProblem) (R *probs.ExprReport) {

	guess := make([]float64, 0)
	guess, eqn := E.ConvertToConstants(guess)

	var coeff []float64
	if len(guess) > 0 {

		// fmt.Printf("x_dims:  %d  %d\n", x_dim, x_dim2)

		// Callback version
		coeff = levmar.LevmarExpr(eqn, P.SearchVar, P.SearchType, guess, P.Train, P.Test)

		// Stack version
		// x_dim := P.Train[0].NumDim()
		// if c_input == nil {
		// 	ps := P.Train[0].NumPoints()
		// 	PS := len(P.Train) * ps
		// 	x_tot := PS * x_dim

		// 	c_input = make([]levmar.C_double, x_tot)
		// 	c_ygiven = make([]levmar.C_double, PS)

		// 	for i1, T := range P.Train {
		// 		for i2, p := range T.Points() {
		// 			i := i1*ps + i2
		// 			c_ygiven[i] = levmar.MakeCDouble(p.Depnd(P.SearchVar))
		// 			for i3, x_p := range p.Indeps() {
		// 				j := i1*ps*x_dim + i2*x_dim + i3
		// 				c_input[j] = levmar.MakeCDouble(x_p)
		// 			}
		// 		}
		// 	}
		// }
		// coeff = levmar.StackLevmarExpr(eqn, x_dim, guess, c_ygiven, c_input)

		// serial := make([]int, 0)
		// serial = eqn.StackSerial(serial)
		// fmt.Printf("StackSerial: %v\n", serial)
		// fmt.Printf("%v\n%v\n%v\n\n", eqn, coeff, steff)
	}

	R = new(probs.ExprReport)
	R.SetExpr(eqn) /*.ConvertToConstantFs(coeff)*/
	R.SetCoeff(coeff)
	R.Expr().CalcExprStats()

	// hitsL1, hitsL2, evalCnt, nanCnt, infCnt, l1_err, l2_err := scoreExpr(E, P, coeff)
	_, _, _, trnNanCnt, _, trn_l1_err, _ := scoreExpr(E, P, P.Train, coeff)
	_, _, tstEvalCnt, tstNanCnt, _, tst_l1_err, tst_l2_err := scoreExpr(E, P, P.Test, coeff)

	R.SetTrainScore(trnNanCnt)
	R.SetTrainError(trn_l1_err)

	R.SetPredScore(tstNanCnt)
	R.SetTestScore(tstEvalCnt)
	R.SetTestError(tst_l1_err)
	R.SetPredError(tst_l2_err)

	return R
}