def fun2_xy(xx, ct, bt): x_n, y_n, a_k, b_k = xx[:NN], xx[NN:2 * NN], xx[2 * NN:2 * NN + K**2 - 2], xx[2 * NN + K**2 - 2:] a_k = np.concatenate(([ 0, ], a_k[:K - 1], [ 0, ], a_k[K - 1:])).reshape((K, K)) b_k = np.concatenate(([0, 0], b_k)).reshape((K, K)) # cost: # (features[k] = n, xi, yi, m, xj, yj) # x_m - x_n + x_i - x_j + ux(x_i, y_i) - ux(x_j, y_j) = 0 # y_m - y_n + y_i - y_j + uy(x_i, y_i) - uy(x_j, y_j) = 0 temp1 = x_n[pos_inv[fes[:, 3].astype(np.int)]] - x_n[pos_inv[fes[:, 0].astype(np.int)]] \ + fes[:, 1] - fes[:, 4] \ + polyval2d((fes[:, 1]+xmin)/float(xmax-xmin), (fes[:, 2]+ymin)/float(ymax-ymin), a_k) \ - polyval2d((fes[:, 4]+xmin)/float(xmax-xmin), (fes[:, 5]+ymin)/float(ymax-ymin), a_k) temp2 = y_n[pos_inv[fes[:, 3].astype(np.int)]] - y_n[pos_inv[fes[:, 0].astype(np.int)]] \ + fes[:, 2] - fes[:, 5] \ + polyval2d((fes[:, 1]+xmin)/float(xmax-xmin), (fes[:, 2]+ymin)/float(ymax-ymin), b_k) \ - polyval2d((fes[:, 4]+xmin)/float(xmax-xmin), (fes[:, 5]+ymin)/float(ymax-ymin), b_k) cost = np.sum(temp1**2 + temp2**2) # integrate: ct = poly_utils.polymul2d(a_k, a_k, ct) cost += str_sm * poly_utils.polyint2d(ct, bt, -1., 1., -1., 1.) ct = poly_utils.polymul2d(b_k, b_k, ct) cost += str_sm * poly_utils.polyint2d(ct, bt, -1., 1., -1., 1.) return cost
def fun2_xy(xx, ct, bt, ax, ay, a, dist): x_n, y_n, a_k = xx[:NN], xx[NN:2 * NN], xx[2 * NN:] a[mask] = xx[2 * NN:] ax = poly_utils.polyder2d(a, ax, 0) ay = poly_utils.polyder2d(a, ay, 1) # cost: # (features[k] = n, xi, yi, m, xj, yj) # x_m - x_n + x_i - x_j + ux(x_i, y_i) - ux(x_j, y_j) = 0 # y_m - y_n + y_i - y_j + uy(x_i, y_i) - uy(x_j, y_j) = 0 temp1 = x_n[pos_inv[fes[:, 3].astype(np.int)]] - x_n[pos_inv[fes[:, 0].astype(np.int)]] \ + fes[:, 1] - fes[:, 4] \ + polyval2d((fes[:, 1]+xmin)/float(xmax), (fes[:, 2]+ymin)/float(ymax), ax) \ - polyval2d((fes[:, 4]+xmin)/float(xmax), (fes[:, 5]+ymin)/float(ymax), ax) temp2 = y_n[pos_inv[fes[:, 3].astype(np.int)]] - y_n[pos_inv[fes[:, 0].astype(np.int)]] \ + fes[:, 2] - fes[:, 5] \ + polyval2d((fes[:, 1]+xmin)/float(xmax), (fes[:, 2]+ymin)/float(ymax), ay) \ - polyval2d((fes[:, 4]+xmin)/float(xmax), (fes[:, 5]+ymin)/float(ymax), ay) cost = np.sum((temp1**2 + temp2**2) * reg) # integrate: ct = poly_utils.polymul2d(a, a, ct) cost += str_sm * poly_utils.polyint2d(ct, bt, -1., 1., -1., 1.) return cost
def err_poly(xx, ct, bt, ax, ay, a): x_n, y_n, a_k = xx[:NN], xx[NN:2 * NN], xx[2 * NN:] a[mask] = xx[2 * NN:] ax = poly_utils.polyder2d(a, ax, 0) ay = poly_utils.polyder2d(a, ay, 1) ct = poly_utils.polymul2d(a, a, ct) cost = str_sm * poly_utils.polyint2d(ct, bt, -1., 1., -1., 1.) return cost