Example #1
0
def test_calibration():

    space = odl.uniform_discr(min_pt=[-1],
                              max_pt=[1],
                              shape=[128],
                              dtype='float32',
                              interp='linear')

    cell_side = space.cell_sides

    #kernel = get_kernel(space)
    kernel = get_kernel_gauss(space, 0.2)

    def product(f, g):
        return struct.scalar_product_structured(f, g, kernel)

    #points = space.points()[::2].T
    points = np.array([[
        -0.75,
        0.0,
        0.2,
        0.5,
    ]])
    vectors = np.array([[
        0.3,
        0.0,
        0,
        1,
    ]])
    original = struct.create_structured(points, vectors)
    g = group.Translation(space)

    translation = np.array([1.0])
    translated = action.apply_element_to_field(g, translation, original)

    covariance_matrix = struct.make_covariance_matrix(space.points().T, kernel)
    noise_l2 = odl.phantom.noise.white_noise(space) * 0.05
    decomp = np.linalg.cholesky(covariance_matrix +
                                1e-5 * np.identity(len(covariance_matrix)))
    noise_rkhs = np.dot(decomp, noise_l2)

    get_unstructured = struct.get_from_structured_to_unstructured(
        space, kernel)
    noisy = space.tangent_bundle.element(
        get_unstructured(translated) + noise_rkhs)

    def act(element, struct):
        return action.apply_element_to_field(g, element, struct)

    result_calibration = calib.calibrate(original, noisy, g, act, product,
                                         struct.scalar_product_unstructured)

    estimated_translated = get_unstructured(act(result_calibration.x,
                                                original))
    print('real = {}, computed ={} , log diff = {}'.format(
        translation, result_calibration.x,
        np.log10(np.abs(translation[0] - result_calibration.x[0]))))
Example #2
0
def iterative_scheme(solve_regression, calibration, action, g, kernel,
                     field_list, sigma0, sigma1, points, nb_iteration):
    nb_data = len(field_list)
    eval_kernel = struct.make_covariance_matrix(points, kernel)
    dim, nb_points = points.shape

    def product(vect0, vect1):
        return struct.scalar_product_structured(vect0, vect1, kernel)

    # initialization with a structured version of first vector field (NOT GOOD)
    group_element_init = g.identity
    vectors_original = solve_regression(g, [group_element_init],
                                        [field_list[0]], sigma0, sigma1,
                                        points, eval_kernel)
    vectors_original_struct = struct.get_structured_vectors_from_concatenated(
        vectors_original, nb_points, dim)
    original = struct.create_structured(points, vectors_original_struct)
    get_unstructured_op = struct.get_from_structured_to_unstructured(
        field_list[0].space[0], kernel)
    get_unstructured_op(original).show('initialisation')

    for k in range(nb_iteration):
        velocity_list = calibrate_list(original, field_list, calibration)
        group_element_list = [
            g.exponential(velocity_list[i]) for i in range(nb_data)
        ]
        vectors_original = solve_regression(g, group_element_list, field_list,
                                            sigma0, sigma1, points,
                                            eval_kernel)
        vectors_original_struct = struct.get_structured_vectors_from_concatenated(
            vectors_original, nb_points, dim)
        original = struct.create_structured(points, vectors_original_struct)
        print('iteration {}'.format(k))
        get_unstructured_op(original).show('iteration {}'.format(k))

    return [original, group_element_list]
Example #3
0
#nb_bc_orth = int(2*width / sigma) +1
#

#points_temp, vectors_temp = cmp.compute_pointsvectors_2articulations_nb(a_list[0], b_list[0], c_list[0], width, sigma, nb_ab, nb_ab_orth, nb_bc, nb_bc_orth)
nb_vectors = len(vectors_list[0][0])
nb_points = len(points_list[0][0])

dim = 2


# Create list of structured and unstructured
def kernel(x, y):
    return np.exp(-sum([(xi - yi)**2 for xi, yi in zip(x, y)]) / (sigma**2))


get_unstructured_op = struct.get_from_structured_to_unstructured(space, kernel)
structured_list = []
unstructured_list = []

for i in range(nbdata):
    points = points_list[i].copy()
    vectors = vectors_list[i].copy()
    #points, vectors = cmp.compute_pointsvectors_2articulations_nb(a_list[i], b_list[i], c_list[i], width, sigma, nb_ab, nb_ab_orth, nb_bc, nb_bc_orth)
    eval_field = np.array([
        space.element(vector_fields_list[i][:, :, u]).interpolation(points)
        for u in range(dim)
    ]).copy()

    vector_syst = np.zeros(dim * nb_points)
    basis = np.identity(dim)
solve_regression = reg.solve_regression
calibration = cali.calibrate


def action(group_element, structured_field):
    return act.apply_element_to_field(g, group_element, structured_field)


def product(vect0, vect1):
    return struct.scalar_product_structured(vect0, vect1, kernel)


pairing = struct.scalar_product_unstructured

#%% define calibration
get_unstructured_op = struct.get_from_structured_to_unstructured(space, kernel)

#mg = space.meshgrid
#def get_unstructured_op(structured_field):
#    dim_double, nb_points = structured_field.shape
#    points = struct.get_points(structured_field)
#    vectors = struct.get_vectors(structured_field)
#    unstructured = space.tangent_bundle.zero()
#
#    for k in range(nb_points):
#        def kern_app_point(x):
#            return kernel(proj([xu - pu for xu, pu in zip(x, points[:, k])]) , [0])
#
#        kern_discr = kern_app_point(mg)
#
#        unstructured += space.tangent_bundle.element([kern_discr * vect for vect in vectors[:, k]]).copy()
 def __init__(self, space, kernel):
     self.space = space
     self.unstructured_op = struct.get_from_structured_to_unstructured(space, kernel)
Example #6
0
 def __init__(self, space, kernel):
     self.space = space
     self.extent = space.max_pt[0] - space.min_pt[0]
     self.k = 1
     self.unstructured_op = struct.get_from_structured_to_unstructured(
         space, kernel)