import scipy import scipy.linalg import arnoldiDTM import NumBias import Matrix import gnuplotFile if __name__ == "__main__": numby = NumBias.NB(version=str(__version__)) A = Matrix.Diagonal(scipy.arange(numby.options.size, 0, -1)) # Calculate similarDiag matrix adtm = arnoldiDTM.arnoldiDTM(A, Noise=0.0) q = scipy.ones(numby.options.size) adtm.arnoldi(q, numby.options.size) Q = scipy.array(adtm.Q) B = scipy.dot(scipy.dot(Q[:-1].transpose(), A), Q[:-1]) # Double-check print "\n\nDouble-check:" print "Eigenvalues of A:\n%s\nEigenvalues of B:\n%s\n" % ( scipy.linalg.eigvals(A), scipy.linalg.eigvals(B)) print "A: \n%s" % B numby.printParameters() if numby.options.run: numby.run(A=B, q=q)
Chart = Gnuplot.Gnuplot() Chart.xlabel('Iteration') Chart.ylabel('Estimated eigenvalue') Chart.title('Noise = %4G' %(Noise)) Chart('set yrange [3.0:]') Chart('set pointsize 0.5') Chart('set key right bottom') Chart('set y2tics') # Chart('set no key') # Not Noisy Chart.replot(Gnuplot.Data(range(iterations), scipy.ones(iterations)*scipy.pi, with='lines', title='True eValue')) # adtm = arnoldiDTM.arnoldiDTM(A, Noise=0.0, NoiseShape='uniform') # ePairs = adtm.arnoldi(q, iterations) # conData = Gnuplot.Data(adtm.convergence, with='linespoints', # title='NotNoisy') # Chart.replot(conData) eValues = [] for n in xrange(20): adtm = arnoldiDTM.arnoldiDTM(A, Noise=Noise, NoiseShape='normal') ePairs = adtm.arnoldi(q, iterations) eValues.append(ePairs[0][-1]) conData = Gnuplot.Data(adtm.convergence, with='linespoints', title=None) Chart.replot(conData) print "Averaage eigenvalue: %.4f" %(scipy.mean(eValues))
import Gnuplot import arnoldiDTM import Matrix if __name__ == "__main__": N = 10 # A = Matrix.DingDong(N) A = Matrix.Diagonal(scipy.arange(1,N+1)) print A I = 11 # Arnoldi Iterations R = 10 # Arnoldi Restarts q = scipy.random.random(N) adtm = arnoldiDTM.arnoldiDTM(A) values, vectors = adtm.arnoldi(q, I) print "Estimated Eigenvalues: %s" %(values) realvalues, realvectors = scipy.linalg.eig(A) realvalues.sort() print "Real values: %i, Estimated values %i" %(len(realvalues), len(values)) # print "Real Eigenvalues: %s" %(realvalues) # print "Difference: %s" %(abs(realvalues-values)) Chart = Gnuplot.Gnuplot() plotData = Gnuplot.Data(vectors[:,-1], with='histeps') Chart.plot(plotData)