我想用sympy来构建一个cython,它可以用来评估损失/雅各布/黑森。损失函数(由于SO上缺少latex而定义为python函数)如下所示
def loss(omega, tau, x, w):
# omega: [j, 3, 3] a stack of rotations
# tau : [j, 3] a stack of translations
# x : [i, j, 3] a matrix of 3d image points
# w : [i ,3] a stack of corresponding 3d world points
total_loss = 0.
for a in range(x.shape[0]):
for b in range(x.shape[1]):
z = np.matmul(omega[b], w[a]) + tau[b]
z /= np.linalg.norm(z)
total_loss += np.dot(x[a, b], z)
return total_loss
这是equation 7来自运动纸的这个结构。在
当只考虑单个点和转换时,我可以在sypy中构建适当的函数i=j=
,如下所示:
但是我希望能够构建一个函数,它将处理i
和{IndexedBase
sympy对象,除了最基本的示例之外,我似乎什么也做不了。如何使用IndexedBase
对象来构建适当的表达式?在
我最终放弃了辛普森,因为它的麻烦大于它的价值。我建议你用微分来结束。下面是创建方程(7)的hessian的脚本。在
相关问题 更多 >
编程相关推荐