python - Adding weights when using lmfit to fit a 3D line on a cloud of points -


i using following code fit 3d line on cloud of 3d points. using least squares method of lmfit minimize.

i need add weights different points, not know how when using array (and not scalar) distance output. problem when using scalar is not when using array. assume because of larger number of variables.

so question - there way add weights each element of array minimizer? using nelder w/scaral input not perform 3d fit well.

from lmfit import minimize, parameters, parameter,report_fit,fit_report, minimizer, printfuncs import numpy np  #parameters params = parameters() params.add('y1',   value= 0) params.add('x0',   value= 129) params.add('x1',   value= 0) params.add('y0',   value= 129) params.add('y1',   value= 0)  #function calculating point-line distance def fun(params,x,y,z):     x0 = params['x0'].value; x1 = params['x1'].value; y0 = params['y0'].value; y1 = params['y1'].value      distance = []     #parametric equations     v0 = np.array([x0, y0, 0])     v1 = np.array([x0+x1,y0+ y1, 1])      #for loop on 3d points calculate distance     point in range(len(x)):         p = np.array([x[point], y[point], z[point]])         distance.append(np.linalg.norm(np.cross(v0-p,v0-v1)))            return distance  result = minimize(fun, params,args=(x,y,z)) print(fit_report(result))  theta = np.arccos(1/ np.sqrt(result.params['x1']*result.params['x1']+result.params['y1']*result.params['y1']+1)) 

i suppose read documentation on how write objective function (this link provided in 1 of other questions)? if so, part of description there not clear and/or did try , didn't work?

in example generate array called distance, same (model-data) in documentation. want add here eps, scale residual uncertainty in data.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -