rowSampler.RowSampler,\
                        randomProjections.RandomProjections,\
                        randomSums.RandomSums,\
                        frequentDirections.FrequentDirections]
    ns = [500]
    ds = [100]
    ells = range(10,101,10)
    ks = [5]
    rounds = 1
        
    for (n, d, k) in product (ns, ds, ks):
        data_maker = SyntheticDataMaker()
        data_maker.initBeforeMake(d, k, signal_to_noise_ratio=10.0)
        A = data_maker.makeMatrix(n) # n * d matrix

        ATA = covariance(A.T)
        squared_frob_A = norm(A,'fro') ** 2
        A_rank_k = truncateSVD(A, k)

        for (sketcherClass, ell, r) in product(sketcherClasses, ells, range(rounds)):
            if ell > d/2:
                continue
                   
            sketcher = sketcherClass(d, ell)
            for row in A:
                sketcher.append(row)

            sketch = sketcher.get()    

            diff = ATA - dot(sketch.transpose(),sketch)
            relative_cov_err = norm(diff,2) / squared_frob_A
        
 
        
if __name__ == '__main__':
    # make input data
    n = 1000
    d = 400
    k = 5
    ells = range(10,21,10)
    density = 0.1
    A = rand(n, d, density, format = 'lil')   
    
  
    # error computation
    B = A.todense()
    ATA = covariance(B.T)
    squared_frob_A = norm(B,'fro') ** 2
    A_rank_k = truncateSVD(B, k)
    opt_rank_k_err = norm(B - A_rank_k, 'fro') ** 2

   
    for ell in ells:
        sketcher = SparseSketcher(d, ell)

        t_start = timer()
        for sv in A:
            sketcher.append(sv)
        t_end = timer()
        totalSketchTime = t_end-t_start
        
        sketch = sketcher.get()
Ejemplo n.º 3
0
                        rowSampler.RowSampler,\
                        randomProjections.RandomProjections,\
                        randomSums.RandomSums,\
                        frequentDirections.FrequentDirections]
    ns = [500]
    ds = [100]
    ells = range(10, 101, 10)
    ks = [5]
    rounds = 1

    for (n, d, k) in product(ns, ds, ks):
        data_maker = SyntheticDataMaker()
        data_maker.initBeforeMake(d, k, signal_to_noise_ratio=10.0)
        A = data_maker.makeMatrix(n)  # n * d matrix

        ATA = covariance(A.T)
        squared_frob_A = norm(A, 'fro')**2
        A_rank_k = truncateSVD(A, k)

        for (sketcherClass, ell, r) in product(sketcherClasses, ells,
                                               range(rounds)):
            if ell > d / 2:
                continue

            sketcher = sketcherClass(d, ell)
            for row in A:
                sketcher.append(row)

            sketch = sketcher.get()

            diff = ATA - dot(sketch.transpose(), sketch)
        self.__rotate__()
        return self._sketch[:self.ell, :]


if __name__ == '__main__':
    # make input data
    n = 1000
    d = 400
    k = 5
    ells = range(10, 21, 10)
    density = 0.1
    A = rand(n, d, density, format='lil')

    # error computation
    B = A.todense()
    ATA = covariance(B.T)
    squared_frob_A = norm(B, 'fro')**2
    A_rank_k = truncateSVD(B, k)
    opt_rank_k_err = norm(B - A_rank_k, 'fro')**2

    for ell in ells:
        sketcher = SparseSketcher(d, ell)

        t_start = timer()
        for sv in A:
            sketcher.append(sv)
        t_end = timer()
        totalSketchTime = t_end - t_start

        sketch = sketcher.get()
        #### cov-error #######