0

给定优化问题 (1),如下所示,其中p_ip'_i给出w_jii=0,...,6889我想使用 Levenberg-Marquardt 方法来找到R_jv_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

编辑:这现在是正确的结果。

4

1 回答 1

1

使用您的原件fun(但给它一个更好的名称)

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

对其进行闭包,以便它接受单个输入(您正在求解的变量):

old_points = ...
new_points = ...
weights = ...
rv = ...
n_joints = ...
def cont_function(x):
    return fun(x, old_points, new_points, weights, rv, n_joints)

现在尝试cost_function使用roots

于 2019-06-11T10:04:04.553 回答