Skip to content
Snippets Groups Projects
Commit c1e59ce2 authored by Nicolas Marsic's avatar Nicolas Marsic
Browse files

Display largest and lowest singular values when iterating

parent bff7f389
No related branches found
No related tags found
No related merge requests found
import solver as Solver
import sys
import numpy as np
import numpy.matlib
......@@ -35,11 +36,15 @@ def simple(operator, origin, radius,
# Search A0
if(verbose): print "Searching A0..."
while(not hasK and it != maxIt):
if(verbose): print " # Iteration: " + str(it+1)
if(verbose): print " # Iteration: " + str(it+1),
if(verbose): sys.stdout.flush()
vHat = randomMatrix(m ,l) # Take a random VHat
vHat = randomMatrix(m, l) # Take a random VHat
A0 = integrate(operator, myPath, 0, vHat) # Compute A0
k = np.linalg.matrix_rank(A0, tol=rankTol) # Rank test
k, sMax, sMin = rank(A0, rankTol) # Rank
if(verbose): print "| " + format(sMax, ".2e"),
if(verbose): print "| " + format(sMin, ".2e")
if(k == 0): # Rank is zero?
if(verbose): print " # Rank test is zero: keep A0 as is!"
......@@ -92,10 +97,28 @@ def simple(operator, origin, radius,
## Import only simple (other functions are just helpers)
__all__ = ['simple']
__all__ = ["simple"]
## Helper functions
def rank(A, tol):
"""Returns the rank of a given matrix and its largest and lowest SVs
Keywords arguments:
A -- the matrix to use
tol -- the tolerance used to compute the rank
"""
S = np.linalg.svd(A, full_matrices=False, compute_uv=0)
nSV = len(S)
k = 0
for i in range(nSV):
if(S[i] > tol): k = k + 1
return k, S[0].tolist(), S[nSV - 1].tolist()
def path(nodes, origin, radius):
"""Returns a list with the coordinates of a circular contour
......@@ -187,12 +210,12 @@ def display(nodes, maxIt, lStart, lStep, rankTol, origin, radius):
print " # Initial size of col(A0): " + " " + str(lStart)
print " # Step size for increasing col(A0): " + " " + str(lStep)
print " # Rank test tolerance: ",
print format(rankTol, '.2e')
print format(rankTol, ".2e")
print "---------------------------------------"
print " # Cirular path origin: ",
print "(" + format(np.real(origin).tolist(), '+.2e') + ")",
print "(" + format(np.real(origin).tolist(), "+.2e") + ")",
print "+",
print "(" + format(np.imag(origin).tolist(), '+.2e') + ")j"
print "(" + format(np.imag(origin).tolist(), "+.2e") + ")j"
print " # Cirular path radius: ",
print format(radius, '+.2e')
print format(radius, "+.2e")
print "---------------------------------------"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment