【发布时间】:2019-06-11 09:17:47
【问题描述】:
鉴于优化问题 (1) 如下所示,其中i=0,...,6889 给出了p_i、p'_i 和w_ji,我想使用 Levenberg-Marquardt 方法找到R_j 的最优解和v_j 使用scipy.optimize.root(我愿意接受任何其他建议)。
但是,我不知道如何设置需要传递给root 的可调用函数。到目前为止,我所拥有的只是这显然是错误的。
def fun(x, (old_points, new_points, weights, n_joints)):
"""
:param x: variable to optimize. It is supposed to encapsulate R and v from (1)
:param old_points: original vertex positions, (6890,3) numpy array
:param new_points: transformed vertex positions, (6890,3) numpy array
:param weights: weight matrix obtained from spectral clustering, (n_joints, 6890) numpy array
:param n_joints: number of joints
:return: non-linear cost function to find the root of
"""
# Extract rotations and offsets
R = np.array([(np.array(x[j * 15:j * 15 + 9]).reshape(3, 3)) for j in range(n_joints)])
v = np.array([(np.array(x[j * 15 + 9:j * 15 + 12])) for j in range(n_joints)])
# Use equation (1) for the non-linear pass.
# R_j p_i
Rp = np.einsum('jkl,il', x, old_points) # x shall replace R
# w_ji (Rp_ij + v_j)
wRpv = np.einsum('ji,ijk->ik', weights, Rp + x) # x shall replace v
# Set up a non-linear cost function, then compute the squared norm.
d = new_points - wRpv
result = np.einsum('ik,ik', d, d)
return result
编辑:现在这是正确的结果。
【问题讨论】:
-
您要优化哪些
x, old_points, new_points, weights, rv, n_joints?关闭其他人。 -
我正在尝试优化
x,因为我不知道如何将其纳入问题中。据我了解,(1)中的R_j和v_j是x,而代码中的rv是我最初的猜测。 -
那么
x是唯一的未知数? -
是的。另外,提前谢谢你!
标签: python optimization scipy levenberg-marquardt