我正在尝试出于三边测量的目的执行非线性最小二乘拟合 LMFIT:
- LMFIT
- 信标包括信标位置 x,y,z
Parameters()
包括Xinit
要估计的位置。tag_distances[i]
包括测量值(从标签到 的距离beacon[i]
)
我收到此错误:
raise TypeError('Improper input: N=%s must not超过 M=%s' % (n, m)) TypeError: Improper input: N=3 must not超过 M=1
import numpy as np
from math import pow
from lmfit import minimize, Parameters
beacons=np.array([[0.,0.,5.],
[0.,15.,5.],
[15.,0.,5.],
[15.,15.,5.]])
tag=np.array([0,15,0])
tag_distances=np.arange(float(beacons.shape[0]))
xinit=np.array([5.,5.,2.])
def distance (p1, p2):
s=0
for i in range (0,3):
s+=(p1[i]-p2[i])**2
return s**.5
for i in range (0,beacons.shape[0]):
tag_distances[i]=distance(beacons[i,:],tag)
tag_distances= tag_distances.reshape(beacons.shape[0], 1)
def residual(params, measures , beacons, eps_data):
x=np.array([ params['x'].value,
params['y'].value,
params['z'].value])
s=0
for i in range (0,beacons.shape[0]):
s+=(measures[i,0]-distance(beacons[i,:],x))**2
return s
params = Parameters()
params.add('x', value=xinit[0])
params.add('y', value=xinit[1])
params.add('z', value=xinit[2])
eps_data=np.array([1.0,1.0,1.0,1.0])
out = minimize(residual, params, args=(tag_distances, beacons, eps_data))