import numpy as np from numpy import * import matplotlib matplotlib.use('TkAgg') from matplotlib import pyplot as plt from matplotlib import animation N = 1000 def f(x): return log(cosh(x)) def df(x): return tanh(x) def ddf(x): return sech(x)**2 # generate random pairs s = np.random.rand(N, 2) # reshape them A = zeros([2,2]) A[0] = [1, 2] A[1] = [3, 1] x = dot(s,A) # zero mean xm = x-mean(x) # diagonalize cv = cov(xm) w, v = linalg.eig(cv) # print shape(diag(1/pow(w,0.5))) # print v xd = dot(v.T,xm) # xfixed = dot(np.diag(1/pow(w,0.5)),xd) # # d = np.diag([1/pow(i,0.5) for i in w]) # print(d) # xfixed = dot(d,dot(v.T,xm)) # print xd # print xn # wt = random.rand(N,2) # # print shape(xd) # nsteps = 1 # for i in range(nsteps): # # w = mean(x*df(w*x)) - w*mean(ddf(w*x)) # w_new = df(dot(xd,wt.T)) # print shape(w_new) fig = plt.figure() ax = plt.axes() ax.plot(s[:,0],s[:,1],'b.') ax.plot(x[:,0],x[:,1],'r.') ax.plot(xm[:,0],xm[:,1],'g.') # ax.plot(xd[:,0],xd[:,1],'k.') plt.show()