Exemplo n.º 1
0
 def __init__(self,F,Ne,S,**kwargs):
     self.tol = kwargs.get('tol',settings.DMPTolerance)
     self.maxit = kwargs.get('maxit',settings.DMPIterations)
     self.S = S
     self.N = F.shape[0]
     self.I = identity(self.N,'d')
     self.Ne = Ne
     self.F = F
     self.emin, self.emax = lanczos_minmax(self.F,self.S)
     self.initialize()
     self.print_init_info()
     return
Exemplo n.º 2
0
 def __init__(self,F,Ne,S,**opts):
     self.tol = opts.get('tol',1e-7)
     self.maxit = opts.get('maxit',50)
     self.S = S
     self.N = F.shape[0]
     self.I = identity(self.N,'d')
     self.Ne = Ne
     self.F = F
     self.emin, self.emax = lanczos_minmax(self.F,self.S)
     self.initialize()
     self.print_init_info()
     return
Exemplo n.º 3
0
 def __init__(self, F, Ne, S, **kwargs):
     self.tol = kwargs.get('tol', settings.DMPTolerance)
     self.maxit = kwargs.get('maxit', settings.DMPIterations)
     self.S = S
     self.N = F.shape[0]
     self.I = identity(self.N, 'd')
     self.Ne = Ne
     self.F = F
     self.emin, self.emax = lanczos_minmax(self.F, self.S)
     self.initialize()
     self.print_init_info()
     return
Exemplo n.º 4
0
 def __init__(self, F, Ne, S, **opts):
     self.tol = opts.get('tol', 1e-7)
     self.maxit = opts.get('maxit', 50)
     self.S = S
     self.N = F.shape[0]
     self.I = identity(self.N, 'd')
     self.Ne = Ne
     self.F = F
     self.emin, self.emax = lanczos_minmax(self.F, self.S)
     self.initialize()
     self.print_init_info()
     return
Exemplo n.º 5
0
def expmat(A,**kwargs):
    nmax = kwargs.get('nmax',12)
    cut = kwargs.get('cut',1e-8)
    E = identity(A.shape[0],'d')
    D = E
    for i in xrange(1,nmax):
        D = matrixmultiply(D,A)/i
        E += D
        maxel = D.max()
        if abs(maxel) < cut:
            break
    else:
        print "Warning: expmat unconverged after %d iters: %g" % (nmax,maxel)
    return E
Exemplo n.º 6
0
    def __init__(self,F,Ne,S=None,**opts):
        self.tol = opts.get('tol',1e-7)
        self.maxit = opts.get('maxit',100)
        self.do_orth = S is not None

        self.N = F.shape[0]
        self.I = identity(self.N,'d')
        self.Ne = Ne

        if self.do_orth:
            self.X = SymOrth(S)
            self.F = simx(F,self.X)

        self.emin, self.emax = gershgorin_minmax(self.F)
        self.initialize()
        self.print_init_info()
        return
Exemplo n.º 7
0
    def __init__(self,F,Ne,S=None,**kwargs):
        self.tol = kwargs.get('tol',settings.DMPTolerance)
        self.maxit = kwargs.get('maxit',settings.DMPIterations)
        self.do_orth = S is not None

        self.N = F.shape[0]
        self.I = identity(self.N,'d')
        self.Ne = Ne

        if self.do_orth:
            self.X = SymOrth(S)
            self.F = simx(F,self.X)

        self.emin, self.emax = gershgorin_minmax(self.F)
        self.initialize()
        self.print_init_info()
        return
Exemplo n.º 8
0
    def __init__(self, F, Ne, S=None, **kwargs):
        self.tol = kwargs.get('tol', settings.DMPTolerance)
        self.maxit = kwargs.get('maxit', settings.DMPIterations)
        self.do_orth = S is not None

        self.N = F.shape[0]
        self.I = identity(self.N, 'd')
        self.Ne = Ne

        if self.do_orth:
            self.X = SymOrth(S)
            self.F = simx(F, self.X)

        self.emin, self.emax = gershgorin_minmax(self.F)
        self.initialize()
        self.print_init_info()
        return
Exemplo n.º 9
0
    def __init__(self, F, Ne, S=None, **opts):
        self.tol = opts.get('tol', 1e-7)
        self.maxit = opts.get('maxit', 100)
        self.do_orth = S is not None

        self.N = F.shape[0]
        self.I = identity(self.N, 'd')
        self.Ne = Ne

        if self.do_orth:
            self.X = SymOrth(S)
            self.F = simx(F, self.X)

        self.emin, self.emax = gershgorin_minmax(self.F)
        self.initialize()
        self.print_init_info()
        return
Exemplo n.º 10
0
def jacobi(A,**kwargs):
    """\
    E,V = jacobi(A,**kwargs) - Solve the eigenvalues/vectors of matrix
                             A using Jacobi's method.
    Options:
    Name        Default  Definition
    tol         1e-10    The tolerance for an element to be declared zero
    max_sweeps  200      Maximum number of sweeps through the matrix
    """
    max_sweeps = kwargs.get('max_sweeps',settings.JacobiSweeps)
    tol = kwargs.get('tol',settings.JacobiTolerance)
    n = len(A)
    V = identity(n,'d')
    b = diagonal(A)
    d = diagonal(A)
    z = zeros(n,'d')
    nrot = 0
    for irot in xrange(max_sweeps):
        sm = 0
        for ip in xrange(n-1):
            for iq in xrange(ip+1,n):
                sm += abs(A[ip,iq])
        if sm < tol:
            # Normal return
            return evsort(b,V)

        thresh = 0
        if  irot < 3: thresh = 0.2*sm/n/n

        for ip in xrange(n-1):
            for iq in xrange(ip+1,n):
                g = 100*abs(A[ip,iq])
                if irot > 3 and g < tol:
                    A[ip,iq] = 0
                elif abs(A[ip,iq]) > thresh:
                    h = d[iq]-d[ip]
                    if g < tol:
                        t = A[ip,iq]/h  # t = 1/(2\theta)
                    else:
                        theta = 0.5*h/A[ip,iq] #  eq 11.1.10
                        t = 1./(abs(theta)+sqrt(1.+theta*theta))
                        if theta < 0: t = -t
                    c = 1.0/sqrt(1+t*t)
                    s = t*c
                    tau = s/(1.0+c)
                    h = t*A[ip,iq]
                    z[ip] -= h
                    z[iq] += h
                    d[ip] -= h
                    d[iq] += h
                    A[ip,iq] = 0
                    for j in xrange(ip):
                        A[j,ip],A[j,iq] = rotate(A[j,ip],A[j,iq],s,tau)
                    for j in xrange(ip+1,iq):
                        A[ip,j],A[j,iq] = rotate(A[ip,j],A[j,iq],s,tau)
                    for j in xrange(iq+1,n):
                        A[ip,j],A[iq,j] = rotate(A[ip,j],A[iq,j],s,tau)
                    for j in xrange(n):
                        V[j,ip],V[j,iq] = rotate(V[j,ip],V[j,iq],s,tau)
                    nrot += 1
        for ip in xrange(n):
            b[ip] += z[ip]
            d[ip] = b[ip]
            z[ip] = 0
    else:
        print "Too many iterations"
    return None
Exemplo n.º 11
0
def jacobi(A, **kwargs):
    """\
    E,V = jacobi(A,**kwargs) - Solve the eigenvalues/vectors of matrix
                             A using Jacobi's method.
    Options:
    Name        Default  Definition
    tol         1e-10    The tolerance for an element to be declared zero
    max_sweeps  200      Maximum number of sweeps through the matrix
    """
    max_sweeps = kwargs.get('max_sweeps', settings.JacobiSweeps)
    tol = kwargs.get('tol', settings.JacobiTolerance)
    n = len(A)
    V = identity(n, 'd')
    b = diagonal(A)
    d = diagonal(A)
    z = zeros(n, 'd')
    nrot = 0
    for irot in xrange(max_sweeps):
        sm = 0
        for ip in xrange(n - 1):
            for iq in xrange(ip + 1, n):
                sm += abs(A[ip, iq])
        if sm < tol:
            # Normal return
            return evsort(b, V)

        thresh = 0
        if irot < 3: thresh = 0.2 * sm / n / n

        for ip in xrange(n - 1):
            for iq in xrange(ip + 1, n):
                g = 100 * abs(A[ip, iq])
                if irot > 3 and g < tol:
                    A[ip, iq] = 0
                elif abs(A[ip, iq]) > thresh:
                    h = d[iq] - d[ip]
                    if g < tol:
                        t = A[ip, iq] / h  # t = 1/(2\theta)
                    else:
                        theta = 0.5 * h / A[ip, iq]  #  eq 11.1.10
                        t = 1. / (abs(theta) + sqrt(1. + theta * theta))
                        if theta < 0: t = -t
                    c = 1.0 / sqrt(1 + t * t)
                    s = t * c
                    tau = s / (1.0 + c)
                    h = t * A[ip, iq]
                    z[ip] -= h
                    z[iq] += h
                    d[ip] -= h
                    d[iq] += h
                    A[ip, iq] = 0
                    for j in xrange(ip):
                        A[j, ip], A[j, iq] = rotate(A[j, ip], A[j, iq], s, tau)
                    for j in xrange(ip + 1, iq):
                        A[ip, j], A[j, iq] = rotate(A[ip, j], A[j, iq], s, tau)
                    for j in xrange(iq + 1, n):
                        A[ip, j], A[iq, j] = rotate(A[ip, j], A[iq, j], s, tau)
                    for j in xrange(n):
                        V[j, ip], V[j, iq] = rotate(V[j, ip], V[j, iq], s, tau)
                    nrot += 1
        for ip in xrange(n):
            b[ip] += z[ip]
            d[ip] = b[ip]
            z[ip] = 0
    else:
        print "Too many iterations"
    return None