Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nam
ProxPython
Commits
df972ad2
Commit
df972ad2
authored
Mar 26, 2020
by
Matthijs
Browse files
matlab -> python translation IterateMonitor
parent
7ad2bb43
Changes
1
Hide whitespace changes
Inline
Side-by-side
proxtoolbox/Algorithms/IterateMonitor.py
View file @
df972ad2
from
numpy.linalg
import
norm
from
numpy
import
sqrt
class
IterateMonitor
:
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
self
.
norm_data
=
config
[
'norm_data'
]
#this will be set after the first call of monitor
#
this will be set after the first call of monitor
self
.
u_monitor
=
None
def
monitor
(
u
):
#check if u_monitor is set, otherwise first call of monitor
def
monitor
(
self
,
u
):
#
check if u_monitor is set, otherwise first call of monitor
if
u
.
monitor
==
None
:
#if first call, set change to high value
#
if first call, set change to high value
return
999
#this is the right calculation for change if u does not have blocks structure
#
this is the right calculation for change if u does not have blocks structure
if
u
.
ndim
<
3
:
tmp_change
=
(
norm
(
u
-
u_monitor
,
'fro'
)
/
norm_data
)
**
2
# What function are we trying to import here?
tmp_change
=
(
norm
(
u
-
self
.
u_monitor
,
'fro'
)
/
self
.
norm_data
)
**
2
# What function are we trying to import here?
elif
u
.
ndim
==
3
:
for
j
in
range
(
u
.
shape
[
2
]):
tmp_change
=
tmp_change
+
(
norm
(
u
[:,:,
j
]
-
u_monitor
[:,:,
j
],
'fro'
)
/
norm_data
)
**
2
tmp_change
=
tmp_change
+
(
norm
(
u
[:,
:,
j
]
-
self
.
u_monitor
[:,
:,
j
],
'fro'
)
/
self
.
norm_data
)
**
2
else
:
for
j
in
range
(
u
.
shape
[
3
]):
for
k
in
range
(
u
.
shape
[
2
]:
tmp_change
=
tmp_change
+
(
norm
(
u
[:,:,
k
,
j
]
-
u_monitor
[:,:,
k
,
j
],
'fro'
)
/
norm_data
)
**
2
for
k
in
range
(
u
.
shape
[
2
]):
tmp_change
=
tmp_change
+
(
norm
(
u
[:,
:,
k
,
j
]
-
self
.
u_monitor
[:,
:,
k
,
j
],
'fro'
)
/
self
.
norm_data
)
**
2
change
=
sqrt
(
tmp_change
)
#hopefully copies to config
#
hopefully copies to config
self
.
u_monitor
=
u
return
change
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment