Пример #1
0
    """
    Q, R = randomized_range_finder(A, l=l)
    return direct_svd(A, Q)


def algo_3(A, l=8, method='srft', verbose=False):
    """
    Computes the third algorithm
    """
    if verbose:
        print "Computing Fast Randomized Range Finder"
    Q, _ = fast_randomized_range_finder(A, l=l, method=method)
    if verbose:
        print "Compute direct SVD"
#    return row_extraction_svd(A, Q)
    return direct_svd(A, Q)


U1, S1, V1 = mem.cache(algo_1)(gaussian)
U2, S2, V2 = mem.cache(algo_2)(gaussian, l=100)
U3, S3, V3 = mem.cache(algo_3)(gaussian, l=100)

draw_plots([S_ground_truth[:100], S1[:100], S2[:100], S3[:100]],
     legend=('Ground truth', 'Algo1', 'Algo2', 'Algo3'),
     logscale=False)
draw_plots([error(S_ground_truth[:100], S1[:100]),
      error(S_ground_truth[:100], S2[:100]),
      error(S_ground_truth[:100], S3[:100])],
      legend=('Error 1', 'Error 2', 'Error 3'))
Пример #2
0
pca = PCA(n_components=100)
pca.fit(data)
p0 = pca.explained_variance_

rpca = RandomizedPCA(n_components=100, iterated_power=1)
rpca.fit(data)
p1 = rpca.explained_variance_

rpca = RandomizedPCA(n_components=100, iterated_power=2)
rpca.fit(data)
p2 = rpca.explained_variance_

rpca = RandomizedPCA(n_components=100, iterated_power=3)
rpca.fit(data)
p3 = rpca.explained_variance_

draw_plots([gt[:100], e0[:100], e1[:100], e2[:100], e3[:100]],
           legend=('grountruth', 'q=0', 'q=1', 'q=2', 'q=3'))
draw_plots([error(gt[:100], e0[:100]),
           error(gt[:100], e1[:100]),
            error(gt[:100], e2[:100]),
            error(gt[:100], e3[:100])],
            legend=('Error 1', 'Error 2', 'Error 3', 'Error 4'))

draw_plots([p0[:100], p1[:100], p2[:100], p3[:100]],
           legend=('grountruth', 'q=0', 'q=1', 'q=2', 'q=3'))
draw_plots([error(p0[:100], p1[:100]),
           error(p0[:100], p2[:100]),
            error(p0[:100], p3[:100])],
            legend=('Error 1', 'Error 2', 'Error 3'))
Пример #3
0
from math import pi

from draw import draw_plots
from signal import error_points_by_M, \
    harmonic_signal, \
    mean_from_power, \
    mean_from_variance, \
    fourier_amplitude, \
    EXPECTED_MEAN, \
    EXPECTED_AMPLITUDE

# Variant 1
PHASES = [0.0, pi / 32.0]
K_FROM_N = lambda N: 3 * N // 4
N = 64

LABELS = [
    'Amplitude error',
    'Mean from power error',
    'Mean from variance error'
]
PLOT_FUNCTIONS = [
    lambda phase: error_points_by_M(N, K_FROM_N(N), harmonic_signal, phase, EXPECTED_AMPLITUDE, fourier_amplitude),
    lambda phase: error_points_by_M(N, K_FROM_N(N), harmonic_signal, phase, EXPECTED_MEAN, mean_from_power),
    lambda phase: error_points_by_M(N, K_FROM_N(N), harmonic_signal, phase, EXPECTED_MEAN, mean_from_variance)
]


if __name__ == '__main__':
    draw_plots(PHASES, PLOT_FUNCTIONS, LABELS)
Пример #4
0
B1 = 100
B2 = 2

if __name__ == '__main__':
    random_signal_values = [test_signal(i, N, B1, B2) for i in range(N)]
    moving_averaged_values = moving_averaged_antialiasing(
        random_signal_values, AVERAGED_WINDOW)
    parabola_values = fourth_degree_parabola_antialiasing(random_signal_values)
    moving_median_values = moving_median_antialiasing(random_signal_values,
                                                      MEDIAN_WINDOW,
                                                      REMOVING_ELEMENTS)
    signals = [
        PlotDescription(values=random_signal_values,
                        label='Original',
                        visibility=True,
                        spectrum=amplitude_spectrum(random_signal_values)),
        PlotDescription(values=moving_averaged_values,
                        label='Moving averaged',
                        visibility=False,
                        spectrum=amplitude_spectrum(moving_averaged_values)),
        PlotDescription(values=parabola_values,
                        label='Fourth degree parabola',
                        visibility=False,
                        spectrum=amplitude_spectrum(parabola_values)),
        PlotDescription(values=moving_median_values,
                        label='Moving median',
                        visibility=False,
                        spectrum=amplitude_spectrum(moving_median_values))
    ]
    draw_plots(signals)