Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
cim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
getdp
cim
Commits
c1e59ce2
Commit
c1e59ce2
authored
8 years ago
by
Nicolas Marsic
Browse files
Options
Downloads
Patches
Plain Diff
Display largest and lowest singular values when iterating
parent
bff7f389
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/beyn.py
+31
-8
31 additions, 8 deletions
src/beyn.py
with
31 additions
and
8 deletions
src/beyn.py
+
31
−
8
View file @
c1e59ce2
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
"
---------------------------------------
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment