当前位置: 首页>>代码示例>>Golang>>正文


Golang Expr.DerivConst方法代码示例

本文整理汇总了Golang中github.com/verdverm/go-symexpr.Expr.DerivConst方法的典型用法代码示例。如果您正苦于以下问题:Golang Expr.DerivConst方法的具体用法?Golang Expr.DerivConst怎么用?Golang Expr.DerivConst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/verdverm/go-symexpr.Expr的用法示例。


在下文中一共展示了Expr.DerivConst方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: LevmarExpr

func LevmarExpr(e expr.Expr, searchDim int, task ExprProblemType, guess []float64, train, test []*PointSet) []float64 {

	ps := train[0].NumPoints()
	PS := len(train) * ps

	c := make([]float64, len(guess))
	var cd callback_data
	cd.Train = train
	cd.Test = test
	cd.E = e
	cd.Coeff = c
	cd.Task = task
	cd.J = make([]expr.Expr, len(guess))
	for i, _ := range cd.J {
		deriv := e.DerivConst(i)
		// simp := deriv.Simplify(expr.DefaultRules())
		cd.J[i] = deriv
	}

	// c/levmar inputs
	coeff := make([]C.double, len(guess))
	for i, g := range guess {
		coeff[i] = C.double(g)
	}

	y := make([]C.double, PS)
	for i1, T := range train {
		for i2, p := range T.Points() {
			i := i1*ps + i2
			y[i] = C.double(p.Depnd(searchDim))
		}
	}
	ya := (*C.double)(unsafe.Pointer(&y[0]))
	ca := (*C.double)(unsafe.Pointer(&coeff[0]))
	ni := C.int(PS)
	mi := C.int(len(c))

	// C.levmar_dif(ya, ca, mi, ni, unsafe.Pointer(&cd))
	C.levmar_der(ya, ca, mi, ni, unsafe.Pointer(&cd))

	for i, _ := range coeff {
		c[i] = float64(coeff[i])
	}
	return c
}
开发者ID:swetz6,项目名称:go-levmar,代码行数:45,代码来源:levmar.go

示例2: StackLevmarExpr

func StackLevmarExpr(e expr.Expr, x_dims int, coeff []float64, c_ygiven, c_input []C_double) []float64 {

	// fmt.Printf("Entering Stack Levmar: \n")

	c_coeff := make([]C.double, len(coeff))
	for i, c := range coeff {
		c_coeff[i] = C.double(c)
	}
	// c_ygiven := make([]C.double, len(ygiven))
	// for i, c := range ygiven {
	// 	c_ygiven[i] = C.double(c)
	// }
	// c_input := make([]C.double, len(input))
	// for i, c := range input {
	// 	c_input[i] = C.double(c)
	// }

	cp := (*C.double)(unsafe.Pointer(&c_coeff[0]))
	mi := C.int(len(coeff))
	yp := (*C.double)(unsafe.Pointer(&c_ygiven[0]))
	ni := C.int(len(c_ygiven))

	var sd *C.StackData
	sd = new(C.StackData)
	// fmt.Printf("x_len: %d   x_dim: %d\n", len(input), x_dims)
	sd.x_len = C.int(len(c_input))
	sd.x_dim = C.int(x_dims)
	sd.x_data = (*C.double)(unsafe.Pointer(&c_input[0]))

	serial := make([]int, 0)
	serial = e.StackSerial(serial)
	// fmt.Printf("StackSerial: %v\n", serial)
	c_serial := make([]C.int, len(serial))
	for i, I := range serial {
		c_serial[i] = C.int(I)
	}
	sd.expr.serial = (*C.int)(unsafe.Pointer(&c_serial[0]))
	sd.expr.s_len = C.int(len(serial))

	// fmt.Printf("GOT HERE: %v\n", serial)

	derivs := make([]C.StackExpr, len(coeff))
	for i, _ := range coeff {
		deriv := e.DerivConst(i)
		dserial := make([]int, 0)
		dserial = deriv.StackSerial(dserial)
		d_serial := make([]C.int, len(dserial))
		for i, I := range dserial {
			d_serial[i] = C.int(I)
		}
		derivs[i].serial = (*C.int)(unsafe.Pointer(&d_serial[0]))
		derivs[i].s_len = C.int(len(d_serial))

	}
	sd.derivs = (*C.StackExpr)(unsafe.Pointer(&derivs[0]))
	sd.d_len = C.int(mi)

	// fmt.Printf("Going into stack_levmar_dif\n")
	C.stack_levmar_dif(yp, cp, mi, ni, unsafe.Pointer(sd))
	// C.stack_levmar_der(yp, cp, mi, ni, unsafe.Pointer(sd))
	// fmt.Printf("Returned from stack_levmar_dif\n")

	c := make([]float64, len(c_coeff))
	for i, _ := range c_coeff {
		c[i] = float64(c_coeff[i])
	}
	// fmt.Printf("C0: %f\n", c[0])
	return c
}
开发者ID:swetz6,项目名称:go-levmar,代码行数:69,代码来源:levmar.go


注:本文中的github.com/verdverm/go-symexpr.Expr.DerivConst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。