Commit c8cd7e75 authored by jansen31's avatar jansen31
Browse files

tabs to spaces

parent fb5e7e20
......@@ -40,8 +40,8 @@ class ADMM(Algorithm):
config : dict
Dictionary containing the problem configuration.
It must contain the following mappings:
proxoperators: 2 ProxOperators
tuple of ProxOperators (the class, no instance)
proxoperators: 2 ProxOperators
tuple of ProxOperators (the class, no instance)
prox1: ProxOperator
First ProxOperator (the class, no instance)
prox2: ProxOperator
......@@ -53,15 +53,15 @@ class ADMM(Algorithm):
beta_switch: int
Iteration at which beta moves from beta0 -> beta_max
iter: int
Lagr_mult_update : ProxOperator
Lagr_mult_update : ProxOperator
"""
self.iter = config['iter']
self.beta0 = config['beta0']
self.beta_max = config['beta_max']
self.beta_switch = config['beta_switch']
self.prox1 = config['proxoperators'][0](config); self.prox2 = config['proxoperators'][1](config)
self.iter = config['iter']
self.beta0 = config['beta0']
self.beta_max = config['beta_max']
self.beta_switch = config['beta_switch']
self.prox1 = config['proxoperators'][0](config); self.prox2 = config['proxoperators'][1](config)
if 'truth' in config:
if 'truth' in config:
self.truth = config['truth']
self.truth_dim = config['truth_dim']
self.norm_truth = config['norm_truth']
......@@ -72,17 +72,17 @@ class ADMM(Algorithm):
self.diagnostic = False
def run(self, u, tol, maxiter):
iter = self.iter - 1
beta0 = self.beta0
beta_max = self.beta_max
beta_switch = self.beta_switch
beta = exp((-iter/beta_switch)**3)*beta0+(1-exp((-iter/beta_switch)**3))*beta_max
self.beta = beta #this is not part of the usual ADMM, but I keep it
def run(self, u, tol, maxiter):
iter = self.iter - 1
beta0 = self.beta0
beta_max = self.beta_max
beta_switch = self.beta_switch
beta = exp((-iter/beta_switch)**3)*beta0+(1-exp((-iter/beta_switch)**3))*beta_max
self.beta = beta #this is not part of the usual ADMM, but I keep it
#in place in case one wants a dynamic prox parameter
u[0] = self.prox1.work(u)
u[1] = self.prox2.work(u)
u[2] = self.Lagr_mult_update.work(u)
return u
u[0] = self.prox1.work(u)
u[1] = self.prox2.work(u)
u[2] = self.Lagr_mult_update.work(u)
return u
......@@ -28,49 +28,49 @@ from proxtoolbox import ProxOperators
from .proxoperators import ProxOperator
class CDRl(SimpleAlgorithm):
def __init__(self,config):
"""
def __init__(self,config):
"""
Parameters
----------
config : dict
Dictionary containing the problem configuration.
It must contain the following mappings:
proxoperators: ProxOperators
It must contain the following mappings:
proxoperators: ProxOperators
list of ProxOperators (the class, no instance)
iter : int
lambda_0 : float
lambda_max : float
lambda_switch : float
prox_idx : int
"""
self.prox = config['proxoperators'](config)
self.iter = config['iter']
self.lambda0 = config['lambda0']
self.lambda_max = config['lambda_max']
self.lambda_switch = config['lambda_switch']
self.prox_idx = config['prox_idx']
iter : int
lambda_0 : float
lambda_max : float
lambda_switch : float
prox_idx : int
"""
self.prox = config['proxoperators'](config)
self.iter = config['iter']
self.lambda0 = config['lambda0']
self.lambda_max = config['lambda_max']
self.lambda_switch = config['lambda_switch']
self.prox_idx = config['prox_idx']
def evaluate(self, u):
prox = self.prox
iter = self.config['iter']
def evaluate(self, u):
prox = self.prox
iter = self.config['iter']
lambda0 = self.config['lambda_0']
lambda_max = self.config['lambda_max']
lambda_switch = self.config['lambda_switch']
# dynamic lambda
lambda = exp((-iter/lambda_switch)**3)*lambda0+(1-exp((-iter/lambda_switch)**3))*lambda_max
tmp_u = u
nProx = len(prox)
for j in range(nProx-1):
self.prox_idx = j+1
tmp1 = 2*(prox[j].work(tmp_u)) - tmp_u
self.prox_idx = j
tmp2 = pro[j-1].work(tmp1)
tmp_u = (lambda*(2*tmp2-tmp1) + (1-lambda)*tmp1 + tmp_u)/2
self.prox_idx = 1
tmp1 = 2*(prox[0].work(tmp_u)) - tmp_u
self.prox_idx = nProx
tmp2 = prox[nProx].work(tmp1)
unew = (lambda*(2*tmp2-tmp1) + (1-lambda)*tmp1 + tmp_u)/2
return unew
# dynamic lambda
lambda = exp((-iter/lambda_switch)**3)*lambda0+(1-exp((-iter/lambda_switch)**3))*lambda_max # MJ: Looks like this intended to be _lambda or a similar handle, not a python lambda function.
tmp_u = u
nProx = len(prox)
for j in range(nProx-1):
self.prox_idx = j+1
tmp1 = 2*(prox[j].work(tmp_u)) - tmp_u
self.prox_idx = j
tmp2 = pro[j-1].work(tmp1)
tmp_u = (lambda*(2*tmp2-tmp1) + (1-lambda)*tmp1 + tmp_u)/2
self.prox_idx = 1
tmp1 = 2*(prox[0].work(tmp_u)) - tmp_u
self.prox_idx = nProx
tmp2 = prox[nProx].work(tmp1)
unew = (lambda*(2*tmp2-tmp1) + (1-lambda)*tmp1 + tmp_u)/2
return unew
......@@ -21,9 +21,9 @@ from proxtoolbox import ProxOperators
from .proxoperators import ProxOperator
class CP(SimpleAlgorithm):
def __init__(self,config):
"""
def __init__(self,config):
"""
Parameters
----------
config : dict
......@@ -32,12 +32,12 @@ class CP(SimpleAlgorithm):
proxoperators: ProxOperators
list of ProxOperators (the class, no instance)
prox_idx : int
"""
self.prox_idx = config['prox_idx']
self.prox = config['proxoperators']
if 'truth' in config:
prox_idx : int
"""
self.prox_idx = config['prox_idx']
self.prox = config['proxoperators']
if 'truth' in config:
self.truth = config['truth']
self.truth_dim = config['truth_dim']
self.norm_truth = config['norm_truth']
......@@ -47,15 +47,15 @@ class CP(SimpleAlgorithm):
else:
self.diagnostic = False
def evaluate(self, u):
tmp_u = u
prox = self.prox
nProx=len(prox)
for j in range(nProx):
self.prox_idx = j
tmp_u = prox[j-1].work(tmp_u)
return tmp_u
def evaluate(self, u):
tmp_u = u
prox = self.prox
nProx=len(prox)
for j in range(nProx):
self.prox_idx = j
tmp_u = prox[j-1].work(tmp_u)
return tmp_u
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 __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
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
change = sqrt(tmp_change)
#hopefully copies to config
self.u_monitor = u
return change
return change
......@@ -31,57 +31,57 @@ from .GRAAL_F import GRAAL_F #GRAAL_F.py needed
from .SimpleAlgortihm import SimpleAlgorithm
class KM(SimpleAlgorithm):
def __init__(self,config):
"""
def __init__(self,config):
"""
Parameters
----------
config : dict
Dictionary containing the problem configuration.
It must contain the following mapping:
Fx : float
"""
self.Fx = config['Fx']
if 'GRAAL_initialized' not in config:
self.bool = False
if 'phi' not in config:
phi = 1.4
self.phi = phi
else:
self.phi = config['phi']
phi = self.phi
if 'inv_Lipschitz_const' not in config:
la = 0.5
else:
self.inv_Lipschitz_const = config['inv_Lipschitz_const']
la = self.inv_Lipschitz_const
else:
self.bool = True
def evaluate(self, x):
if (self.bool == False):
self.x = x
self.xbar = self.x
self.tau = 1. / phi + 1. / phi**2
# F = lambda x: x - T(x)
# GRAAL_F does:
# Fx1 = x-T(x)
self.Fx= GRAAL_F.evaluate(x)
self.th = 1
self.inv_Lipschitz_const=la
self.GRAAL_initialized=True
x1=x
xnew=x1+999
It must contain the following mapping:
Fx : float
"""
self.Fx = config['Fx']
if 'GRAAL_initialized' not in config:
self.bool = False
if 'phi' not in config:
phi = 1.4
self.phi = phi
else:
self.phi = config['phi']
phi = self.phi
if 'inv_Lipschitz_const' not in config:
la = 0.5
else:
self.inv_Lipschitz_const = config['inv_Lipschitz_const']
la = self.inv_Lipschitz_const
else:
self.bool = True
def evaluate(self, x):
if (self.bool == False):
self.x = x
self.xbar = self.x
self.tau = 1. / phi + 1. / phi**2
# F = lambda x: x - T(x)
# GRAAL_F does:
# Fx1 = x-T(x)
self.Fx= GRAAL_F.evaluate(x)
self.th = 1
self.inv_Lipschitz_const=la
self.GRAAL_initialized=True
x1=x
xnew=x1+999
else:
x1 = x - self.Fx
Fx1 = GRAAL_F.evaluate(x1)
# GRAAL_F does:
# Fx1 = x1-T(x1);
self.Fx=Fx1
xnew=x1
return xnew
else:
x1 = x - self.Fx
Fx1 = GRAAL_F.evaluate(x1)
# GRAAL_F does:
# Fx1 = x1-T(x1);
self.Fx=Fx1
xnew=x1
return xnew
......@@ -28,9 +28,9 @@ from proxtoolbox import ProxOperators
from .proxoperators import ProxOperator
class RRR(SimpleAlgorithm):
def __init__(self,config):
"""
def __init__(self,config):
"""
Parameters
----------
config : dict
......@@ -46,35 +46,35 @@ class RRR(SimpleAlgorithm):
beta_switch: int
Iteration at which beta moves from beta_0 -> beta_max
iter: int
prox_idx: int
prox_idx: int
"""
self.beta0 = config['beta0']
self.beta_max = config['beta_max']
self.beta_switch = config['beta_switch']
self.iter = config['iter']
self.prox1 = config['proxoperators'][0](config)
self.beta0 = config['beta0']
self.beta_max = config['beta_max']
self.beta_switch = config['beta_switch']
self.iter = config['iter']
self.prox1 = config['proxoperators'][0](config)
self.prox2 = config['proxoperators'][1](config)
if 'truth' in config:
if 'truth' in config:
self.truth = config['truth']
self.truth_dim = config['truth_dim']
self.norm_truth = config['norm_truth']
if 'diagnostic' in config:
self.diagnostic = True
else:
else:
self.diagnostic = False
def evaluate(self, u):
beta0 =self.beta0
beta_max = self.beta_max
beta_switch = self.beta_switch
iter = self.iter
tmp1 = 2*(self.prox2.work(u))-u
tmp2 = self.prox1.work(tmp1)
#update
beta = exp((-iter/beta_switch)**3)*beta0+(1-exp((-iter/beta_switch)**3))*beta_max #unrelaxes
unew = beta*(2*tmp2-tmp1)/2 + (1-beta)*u
return unew
def evaluate(self, u):
beta0 =self.beta0
beta_max = self.beta_max
beta_switch = self.beta_switch
iter = self.iter
tmp1 = 2*(self.prox2.work(u))-u
tmp2 = self.prox1.work(tmp1)
#update
beta = exp((-iter/beta_switch)**3)*beta0+(1-exp((-iter/beta_switch)**3))*beta_max #unrelaxes
unew = beta*(2*tmp2-tmp1)/2 + (1-beta)*u
return unew
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