【发布时间】:2011-12-15 22:10:44
【问题描述】:
我正在进行一个本地化项目,并使用最小二乘估计来确定发射器的位置。我需要一种方法来统计地描述我的解决方案在我的程序中的“适合度”,这可以用来告诉我我是否有一个好的答案,或者我需要额外的测量,或者有坏的数据。我已经阅读了一些有关使用“确定系数”或 R 平方的信息,但找不到任何好的示例。任何关于如何表征我是否有一个好的解决方案或需要额外测量的想法将不胜感激。
谢谢!
我的代码给了我以下输出,
grid_lat 和 grid_lon 对应于可能目标位置网格的经纬度坐标
grid_lat = [[ 38.16755799 38.16755799 38.16755799 38.16755799 38.16755799
38.16755799]
[ 38.17717199 38.17717199 38.17717199 38.17717199 38.17717199
38.17717199]
[ 38.186786 38.186786 38.186786 38.186786 38.186786 38.186786 ]
[ 38.1964 38.1964 38.1964 38.1964 38.1964 38.1964 ]
[ 38.20601401 38.20601401 38.20601401 38.20601401 38.20601401
38.20601401]
[ 38.21562801 38.21562801 38.21562801 38.21562801 38.21562801
38.21562801]
[ 38.22524202 38.22524202 38.22524202 38.22524202 38.22524202
38.22524202]]
grid_lon = [[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
-75.79807588]
[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
-75.79807588]
[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
-75.79807588]
[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
-75.79807588]
[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
-75.79807588]
[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
-75.79807588]
[-75.83805812 -75.83006167 -75.82206522 -75.81406878 -75.80607233
-75.79807588]]
grid_error 对应于每个点的解决方案的“好”程度。如果我们有 0.0 的误差,我们就有一个完美的解决方案。网格误差针对网格上的每个点计算到每个测量位置(下面测量中的轨迹)。每个测量位置都有一个到发射器的估计范围。 “误差”对应于从测量到发射机的估计范围,减去在测量范围位置和网格点之间计算的实际范围。误差越小,我们越接近实际发射器位置
# Calculate distance between every grid point and every measurement in meters
measured_distance = spatial.distance.cdist(grid_ecef_array, measurement_ecef_array, 'euclidean')
measurement_error = [pow((measurement - estimated_distance),2) for measurement in measured_distance]
mean_squared_error = [numpy.sqrt(numpy.mean(measurement)) for measurement in measurement_error]
# Find minimum solution
# Convert array of mean_squared_errors to 2D grid for graphing
N3, N4 = numpy.array(grid_lon).shape
grid_error = numpy.array(mean_squared_error).reshape((N3, N4))
grid_error = [[ 2.33608445 2.02805063 1.85638288 1.84620283 2.02757163 2.38035108]
[ 1.73675429 1.40649524 1.21799211 1.06503271 1.27373554 1.74265406]
[ 1.44967789 0.96835022 0.62667257 0.52804942 0.91189678 1.50067864]
[ 1.70155286 1.24024402 0.9642869 1.00517531 1.32606411 1.81754752]
[ 2.40218247 2.07449106 1.91044903 1.94272889 2.15511638 2.51683715]
[ 3.29679348 3.05353929 2.93662134 2.95839307 3.11583615 3.39320682]
[ 4.27303679 4.08195869 3.99203754 4.00926823 4.13247105 4.35378011]]
# Generate the 3D plot with the Z coordinate being the mean squared error estimate
plot3Dcoordinates(grid_lon, grid_lat, grid_error)
# Generic function using matplotlib to plot coordinates
def plot3Dcoordinates(X, Y, Z):
fig = plt.figure()
ax = Axes3D(fig)
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet,
linewidth=0, antialiased=False)
fig.colorbar(surf, shrink=0.5, aspect=5)
这是在更大的网格上处理算法的示例图像。我可以直观地看出我有一个很好的解决方案,因为形状平滑地收敛在一个最小点(解决方案)上,看起来有点像倒置的女巫帽。
第二张图片显示了所有测量值和位置,解决方案绘制在顶部,最小点作为解决方案(红色 x)。
【问题讨论】:
-
究竟是什么问题?您似乎通过
grid_error回答了您自己的问题。你的细节和情节很棒,但我们不知道你的程序是什么以及它是如何工作的。我们只看到输入及其输出。 -
Steve- 我可以直观地看出我有一个很好的答案,你会看到干净的置信区间远离红色 X,这与我们远离目标时增加的均方误差直接相关观点。我面临的挑战是如何在不需要人工观察的情况下确定我有一个好的解决方案还是没有编程方式
-
添加了一些代码(就在 grid_error 定义之上)以显示如何生成错误估计
标签: python optimization numpy statistics scipy