Example #1
0
func OptimizeGrad(function optimize.UniObjGrad, initialLocation float64, settings *UniGradSettings, optimizer UniGradOptimizer) (optValue float64, optLocation float64, result *UniGradResult, err error) {

	if settings == nil {
		settings = NewUniGradSettings()
	}

	if optimizer == nil {
		optimizer = NewCubic()
	}

	m := newUniGradStruct()

	m.fun = newModdedFun(function, m.loc, m.obj, m.grad, m.FunEvals)
	m.settings = settings
	m.optimizer = optimizer

	m.loc.SetInit(initialLocation)
	err = optimize.OptimizeOpter(m, function)
	//m.result.Status = c
	return m.obj.Opt(), m.loc.Opt(), m.Result(), err
}
Example #2
0
func OptimizeGrad(function optimize.MultiObjGrad, initialLocation []float64, settings *MultiGradSettings, optimizer MultiGradOptimizer) (optValue float64, optLocation []float64, result *MultiGradResult, err error) {

	if settings == nil {
		settings = NewMultiGradSettings()
	}

	if optimizer == nil {
		optimizer = NewLbfgs()
	}

	m := newMultiGradStruct()
	//m.fun = function
	m.fun = newModdedFun(function, m.loc, m.obj, m.grad, m.FunEvals)
	m.settings = settings
	m.optimizer = optimizer

	m.loc.SetInit(initialLocation)
	err = optimize.OptimizeOpter(m, function)

	return m.obj.Opt(), m.loc.Opt(), m.Result(), err
}