Commit 5998f724 authored by Alexander Dornheim's avatar Alexander Dornheim
Browse files

Added class IterateMonitor which implements a generic iterate monitor (this class is not used yet)

parent e8404935
class IterateMonitor:
def __init__(self,config):
self.norm_data = config['norm_data']
#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
if u.monitor == None:
#if first call, set change to high value
return 999
#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
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
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
change = sqrt(tmp_change)
#hopefully copies to config
self.u_monitor = u
return change
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment