Exemplo n.º 1
0
func OptimizeGrad(function common.UniObjGrad, initialLocation float64, settings GradSettings, method GradMethod) (optValue float64, optLocation float64, result *GradResult, err error) {

	/*
		if settings == nil {
			settings = DefaultGradSettings
		}
	*/
	if method == nil {
		method = NewCubic()
	}

	optimizer := newGradOptimizer()
	optCommon := common.NewOptCommon()

	optimizer.fun = newModdedFun(function, optimizer.loc, optimizer.obj, optimizer.grad, optCommon.FunEvals)
	optimizer.SetSettings(settings)
	optimizer.method = method
	optimizer.loc.Initial = initialLocation

	commonResult, err := common.OptimizeOpter(optimizer, optCommon, settings.CommonSettings, function)

	result = optimizer.Result(commonResult)

	return result.Objective.Optimum, result.Location.Optimum, result, err
}
Exemplo n.º 2
0
func newUniGradStruct() *uniGradStruct {
	m := &uniGradStruct{
		OptCommon: common.NewOptCommon(),
		loc:       uni.NewLocation(),
		obj:       uni.NewObjective(),
		grad:      uni.NewGradient(),
		result:    &UniGradResult{},
	}
	// TODO: Something about settings
	return m
}