go-hep.org/x/hep@v0.38.1/fit/curve1d.go (about) 1 // Copyright ©2017 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package fit 6 7 import ( 8 "gonum.org/v1/gonum/optimize" 9 ) 10 11 // Curve1D returns the result of a non-linear least squares to fit 12 // a function f to the underlying data with method m. 13 func Curve1D(f Func1D, settings *optimize.Settings, m optimize.Method) (*optimize.Result, error) { 14 f.init() 15 16 p := optimize.Problem{ 17 Func: f.fct, 18 Grad: f.grad, 19 Hess: f.hess, 20 } 21 22 if m == nil { 23 m = &optimize.NelderMead{} 24 } 25 26 p0 := make([]float64, len(f.Ps)) 27 copy(p0, f.Ps) 28 return optimize.Minimize(p, p0, settings, m) 29 }