Example #1
0
def power_iteration_4(Y, X, U, S, iterations, v0):
    v = CuckooVector({})    
    v.add(v0)

    for i in range(iterations):
        v1 = CuckooVector({})
        for (x,y) in zip(X,Y):            
            v1.add_scale_dict(x, v.dot_dict(y))
                
        v2 = CuckooVector({})
        for (x,y) in zip(X,Y):
            v2.add_scale_dict(y, v1.dot_dict(x))        
        
        for (u,s) in zip(U,S):
            print(-s * u.dot(v)) 
            v2.add_scale(u, -s * u.dot(v))        
            
        mu = v2.norm(2)        
        v2.scale(1.0/mu)
        v = v2

    return mu,v
Example #2
0
    X += sn 
    P += sn[:-n]
    F += sn[n:]

    pickle.dump((X,P,F), open(out_dir + 'xpf.pcl', 'wb', -1))   
#(X,F,P) = pickle.load(open('xpf.pcl', 'rb'))

rnd = np.random

start = time.time()

# Form an initial vector for power iteration by taking a randomly
# weighted sum of training examples.
v0 = CuckooVector({})
for x in X:
    v0.add_scale_dict(x, rnd.normal(0.0, 5.0))

U = []
Ud = []
S = []

# Compute 1000 singular vectors of future-past covariance
# by computing the eigen vectors of FP^TPF^T using power iteration
# with deflation.
for i in range(1000):
    print(i)
    mu,u = mat_utils.power_iteration_4(F, P, U, S, 10, v0)
    S.append(mu)
    U.append(u)

    # Convert new singular vector from Cuckoovec to dictionary