Beispiel #1
0
def ppm_em_experiment(seed, image_idx, SNR, Ncopy, Ndir, use_sPCA,
                      use_signal_prior, gamma, BW, path_learning, P):
    Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data(
        Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA)
    image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean)

    TT = time()
    Coeff_s, est_rotations = synchronize_2d(Coeff, Freqs, Ndir)
    t_synch = time() - TT

    x_s = np.expand_dims(np.mean(Coeff_s, axis=-1), axis=-1)
    x = align_image(x_s, Coeff_raw, Freqs)
    imager = recover_image(x, Phi_ns, Freqs, r_max, Mean)
    err_synch = np.sqrt(
        np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) /
        np.sum(np.sum(image0**2, axis=-1), axis=0))

    x, num_iter_synch_em, t_synch_em = EM_General_Prior(Coeff,
                                                        Freqs,
                                                        sigma,
                                                        Ndir,
                                                        1 / Ndir * np.ones(
                                                            (Ndir, 1)),
                                                        Ndir,
                                                        0,
                                                        Coeff_raw,
                                                        use_signal_prior,
                                                        uniform=False)
    x = align_image(x, Coeff_raw, Freqs)
    imager = recover_image(x, Phi_ns, Freqs, r_max, Mean)
    err_synch_em = np.sqrt(
        np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) /
        np.sum(np.sum(image0**2, axis=-1), axis=0))

    results = pd.DataFrame()
    results = results.append(
        {
            'use_signal_prior': use_signal_prior,
            'use_sPCA': use_sPCA,
            'seed': seed,
            'SNR': SNR,
            'sigma': sigma,
            'N': Ncopy,
            'L': Coeff.shape[0],
            'image_idx': image_idx,
            'err': err_synch_em,
            'num_iter': num_iter_synch_em,
            'BW': BW,
            'gamma': gamma,
            't': t_synch + t_synch_em,
            't_synch': t_synch,
            't_em': t_synch_em,
            'err_synch': err_synch
        },
        ignore_index=True)

    return results
Beispiel #2
0
def synchronize_and_match_experiment(seed, image_idx, SNR, Ncopy, Ndir,
                                     use_sPCA, P):
    Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data(
        Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA)
    image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean)

    TT = time()
    Coeff_s, est_rotations = synchronize_and_match_2d(Coeff,
                                                      Freqs,
                                                      P=P,
                                                      L=Ndir)
    t_synch = time() - TT

    h, bin_edges = np.histogram((est_rotations - rotations) % 360,
                                bins=np.arange(-0.5, 360 + 0.5))
    measured_rho = np.expand_dims(h / np.sum(h), axis=-1)
    x_s = np.expand_dims(np.mean(Coeff_s, axis=-1), axis=-1)

    x = align_image(x_s, Coeff_raw, Freqs)
    imager = recover_image(x, Phi_ns, Freqs, r_max, Mean)
    err_synch = np.sqrt(
        np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) /
        np.sum(np.sum(image0**2, axis=-1), axis=0))
    print('#### synchronize and match ####')
    print('e = %f' % err_synch)

    results = pd.DataFrame()
    results = results.append(
        {
            'use_sPCA': use_sPCA,
            'seed': seed,
            'SNR': SNR,
            'sigma': sigma,
            'N': Ncopy,
            'L': Coeff.shape[0],
            'image_idx': image_idx,
            'rho': measured_rho,
            'err': err_synch,
            'num_iter': 0,
            't': t_synch
        },
        ignore_index=True)
    return results
Beispiel #3
0
def known_rotations_experiment(seed, image_idx, SNR, Ncopy, Ndir, use_sPCA):
    Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data(
        Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA)
    image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean)

    est_rotations = rotations
    Coeff_s = np.zeros_like(Coeff)
    for i in range(Ncopy):
        Coeff_s[:, i] = Coeff[:, i] * np.exp(
            -1j * 2 * np.pi * est_rotations[i] / 360 * Freqs)

    t_synch = 0
    h, bin_edges = np.histogram((est_rotations - rotations) % 360,
                                bins=np.arange(-0.5, 360 + 0.5))
    measured_rho = np.expand_dims(h / np.sum(h), axis=-1)
    x_s = np.expand_dims(np.mean(Coeff_s, axis=-1), axis=-1)

    x = align_image(x_s, Coeff_raw, Freqs)
    imager = recover_image(x, Phi_ns, Freqs, r_max, Mean)
    err_synch = np.sqrt(
        np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) /
        np.sum(np.sum(image0**2, axis=-1), axis=0))
    print('#### oracle ####')
    print('e = %f' % err_synch)

    results = pd.DataFrame()
    results = results.append(
        {
            'use_sPCA': use_sPCA,
            'seed': seed,
            'SNR': SNR,
            'sigma': sigma,
            'N': Ncopy,
            'L': Coeff.shape[0],
            'image_idx': image_idx,
            'rho': measured_rho,
            'err': err_synch,
            'num_iter': 0,
            't': t_synch
        },
        ignore_index=True)

    return results
Beispiel #4
0
def standard_em_experiment(seed, image_idx, SNR, Ncopy, Ndir, use_sPCA,
                           use_signal_prior):
    Coeff, Freqs, rad_freqs, Mean, Phi_ns, sigma, Coeff_raw, rotations = make_data(
        Ncopy=Ncopy, SNR=SNR, seed=seed, image_idx=image_idx, sPCA=use_sPCA)
    image0 = recover_image(Coeff_raw, Phi_ns, Freqs, r_max, Mean)

    x, num_iter_em_uniform, t_em_uniform = EM_General_Prior(Coeff,
                                                            Freqs,
                                                            sigma,
                                                            Ndir,
                                                            1 / Ndir * np.ones(
                                                                (Ndir, 1)),
                                                            Ndir,
                                                            0,
                                                            Coeff_raw,
                                                            use_signal_prior,
                                                            uniform=True)
    x = align_image(x, Coeff_raw, Freqs)
    imager = recover_image(x, Phi_ns, Freqs, r_max, Mean)
    err_em_uniform = np.sqrt(
        np.sum(np.sum((image0 - imager)**2, axis=-1), axis=0) /
        np.sum(np.sum(image0**2, axis=-1), axis=0))

    results = pd.DataFrame()
    results = results.append(
        {
            'use_signal_prior': use_signal_prior,
            'use_sPCA': use_sPCA,
            'seed': seed,
            'SNR': SNR,
            'sigma': sigma,
            'N': Ncopy,
            'L': Coeff.shape[0],
            'image_idx': image_idx,
            'err': err_em_uniform,
            'num_iter': num_iter_em_uniform,
            't': t_em_uniform
        },
        ignore_index=True)

    return results