def tps_cost(lin_ag, trans_g, w_ng, x_na, y_ng, bend_coef, K_nn=None, return_tuple=False, wt_n = None):
    D = lin_ag.shape[0]
    if K_nn is None: K_nn = tps_kernel_matrix(x_na)
    if wt_n is None: wt_n = np.ones(len(x_na))
    ypred_ng = np.dot(K_nn, w_ng) + np.dot(x_na, lin_ag) + trans_g[None,:]
    res_cost = (wt_n[:,None] * (ypred_ng - y_ng)**2).sum()
    bend_cost = bend_coef * sum(np.dot(w_ng[:,g], np.dot(K_nn, w_ng[:,g])) for g in xrange(D))
    if return_tuple:
        return res_cost, bend_cost, res_cost + bend_cost
    else:
        return res_cost + bend_cost
XXX doesn't include rotation cost
dataset/ETHPy150Open rll/lfd/lfd/tpsopt/tps.py/tps_cost