Beispiel #1
0
def checkImageFormat(fmt,verbose=True):
    """Checks image format; if verbose, warn if it is not.

    Returns the image format, or None if it is not OK.
    """
    pf.debug("Format requested: %s" % fmt,pf.DEBUG.IMAGE)
    pf.debug("Formats available: %s" % imageFormats(),pf.DEBUG.IMAGE)
    if fmt in imageFormats():
        if fmt == 'tex' and verbose:
            pf.warning("This will only write a LaTeX fragment to include the 'eps' image\nYou have to create the .eps image file separately.\n")
        return fmt
    else:
        if verbose:
            import draw
            draw.error("Sorry, can not save in %s format!\n"
                       "I suggest you use 'png' format ;)"%fmt)
        return None
Beispiel #2
0
def checkImageFormat(fmt, verbose=True):
    """Checks image format; if verbose, warn if it is not.

    Returns the image format, or None if it is not OK.
    """
    pf.debug("Format requested: %s" % fmt, pf.DEBUG.IMAGE)
    pf.debug("Formats available: %s" % imageFormats(), pf.DEBUG.IMAGE)
    if fmt in imageFormats():
        if fmt == 'tex' and verbose:
            pf.warning(
                "This will only write a LaTeX fragment to include the 'eps' image\nYou have to create the .eps image file separately.\n"
            )
        return fmt
    else:
        if verbose:
            import draw
            draw.error("Sorry, can not save in %s format!\n"
                       "I suggest you use 'png' format ;)" % fmt)
        return None
Beispiel #3
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'))
Beispiel #4
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'))
Beispiel #5
0
    Returns
    -------
    U, S, V : SVD decomposition

    """
    Q, R = randomized_range_finder(A, l=l)
    return direct_svd(A, Q)


def algo_3(A, l=8, method='srft'):
    """
    Computes the third algorithm
    """
    Q, _ = fast_randomized_range_finder(A, l=l, method=method)
    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'))
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'))