Example #1
0
    def __init__(self, usage=None, version=None):
        """
        __init__ will create all the necessary information you need to run the code.
        It parses the command line to understand all your options.
        """
        if not usage:
            usage = 'usage: %prog [options] args'
        optparse.OptionParser.__init__(self, usage=usage, version=version)
        self.add_option("-f", "--file", dest="filename", type='string', 
                help="gnuplot data filename")
        self.add_option("-A", "--matrix_form", dest='MatrixForm', type='string',
                default="diagonal",
                help="What kind of matrix.  Currently only supports diagonal.")
        self.add_option("-z", "--size", dest="size", type='int', default=10,
                help="Size of matrix.")
        self.add_option("-T", "--trials", dest="Trials", type="float", default=1E5,
                help="How many independent trials to calculate bias.")
        self.add_option("-s", "--sd", dest="sd", type='string', default='0',
                help="What noise standard deviations will be used.")
        self.add_option("-t", "--tol", dest="Tol", type="float", default=0.1,
                help="Accepted tolerance in eigenvalue bias standard deviation.")
        self.add_option("-v", "--values", dest="eigenvalues", type="int",
                default=1, help="How many eigenvalues calculated.")
        self.add_option("-I", "--iterations", dest="I", type="int",
                default=10, help="How many Arnoldi Iterations per trial.")
        self.add_option("-q", dest="q", type="string", 
                default="scipy.ones(self.options.size)", 
                help="Initial q.")
        self.add_option("-r", "--run", dest="run", action="store_true", default=False,
                help="Perform calculation.")

        # Parse command line options
        self.options, self.args = self.parse_args()

        if string.lower(self.options.MatrixForm) == 'diagonal':
            self.A = Matrix.Diagonal(scipy.arange(self.options.size, 0, -1))
        elif isinstance(eval(self.options.MatrixForm), scipy.ndarray):
            self.A = eval(self.options.MatrixForm)
            self.options.size = self.A.shape
        else:
            raise ValueError, """Only Diagonal matrices or scipy.ndarray objects
Example #2
0
import cmath
import time

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:
Example #3
0
"""This module is meant to complement the Mathematica notes included in 
Thesis/Notes.  It is a numerical investigation in the bias of the estimated
eigenvalue due to noise."""

import sys

import scipy
import Gnuplot

import arnoldiDTM
import Matrix


if __name__ == "__main__":
    M = 2
    A = Matrix.Diagonal(scipy.arange(M,0,-1))
    I = M+1
    q = scipy.zeros(M)
    q[0] = 1

    Chart = Gnuplot.Gnuplot()
    Chart.xlabel('Standard Deviation of Noise')
    Chart.ylabel('Mean Eigenvalues')

    Means = []
    Noises = scipy.arange(1,500,10)
    for N in Noises:
        eValues = []
        for i in xrange(100):
            adtm = arnoldiDTM.arnoldiDTM(A, Noise=N, NoiseShape='normal')
            Values, Vectors = adtm.arnoldi(q, I)
Example #4
0
__version__ = " $Revision: 159 $"
__date__     = "$Date: 2007-09-14 08:07:06 -0600 (Fri, 14 Sep 2007) $"


import scipy.linalg

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))