Exemplo n.º 1
0
def test_translation_action():
    space = odl.uniform_discr(min_pt=[-1],
                              max_pt=[1],
                              shape=[128],
                              dtype='float32',
                              interp='linear')

    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)
    translation_action = get_action(space)

    translation = np.array([1.0])
    expected = translation_action(translation, original)

    g = group.Translation(space)

    computed = action.apply_element_to_field(g, translation, original)

    npt.assert_allclose(computed, expected)
Exemplo n.º 2
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]))))
def action(group_element, structured_field):
    return act.apply_element_to_field(g, group_element, structured_field)
Exemplo n.º 4
0
 def act(element, struct):
     return action.apply_element_to_field(g, element, struct)