Commit 46bb9fcd authored by rnahme's avatar rnahme
Browse files

specified imports in Algorithms instances

parent 259f6aeb
......@@ -7,7 +7,7 @@ Created on Mon Dec 14 13:08:06 2015
from math import sqrt
from numpy import zeros
import scipy.linalg
from scipy.linalg import norm
from .algorithms import Algorithm
class AP(Algorithm):
......@@ -72,17 +72,17 @@ class AP(Algorithm):
tmp_change = 0; tmp_gap = 0;
if self.Ny == 1 or self.Nx == 1:
tmp_change = (scipy.linalg.norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (scipy.linalg.norm(tmp1-tmp_u,'fro')/normM)**2;
tmp_change = (norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (norm(tmp1-tmp_u,'fro')/normM)**2;
elif self.Nz == 1:
for j in xrange(self.dim):
tmp_change += (scipy.linalg.norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp1[:,:,j]-tmp_u[:,:,j])/normM,'fro')**2;
tmp_change += (norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (norm(tmp1[:,:,j]-tmp_u[:,:,j])/normM,'fro')**2;
else:
for j in xrange(self.dim):
for k in xrange(self.Nz):
tmp_change += (scipy.linalg.norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp1[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_change += (norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (norm(tmp1[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
change[iters] = sqrt(tmp_change);
gap[iters] = sqrt(tmp_gap);
......
......@@ -7,7 +7,7 @@ Created on Mon Dec 14 12:59:44 2015
from math import exp, sqrt
from numpy import zeros
import scipy.linalg
from scipy.linalg import norm
from .algorithms import Algorithm
class HPR(Algorithm):
......@@ -93,17 +93,17 @@ class HPR(Algorithm):
tmp_change = 0; tmp_gap = 0;
if self.Ny == 1 or self.Nx == 1:
tmp_change = (scipy.linalg.norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (scipy.linalg.norm(tmp3-tmp2,'fro')/normM)**2;
tmp_change = (norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (norm(tmp3-tmp2,'fro')/normM)**2;
elif self.Nz == 1:
for j in xrange(self.dim):
tmp_change += (scipy.linalg.norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,j]-tmp2[:,:,j])/normM,'fro')**2;
tmp_change += (norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (norm(tmp3[:,:,j]-tmp2[:,:,j])/normM,'fro')**2;
else:
for j in xrange(self.dim):
for k in xrange(self.Nz):
tmp_change += (scipy.linalg.norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,k,j]-tmp2[:,:,k,j],'fro')/normM)**2;
tmp_change += (norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (norm(tmp3[:,:,k,j]-tmp2[:,:,k,j],'fro')/normM)**2;
change[iters] = sqrt(tmp_change);
gap[iters] = sqrt(tmp_gap);
......
......@@ -5,7 +5,10 @@ Created on Mon Dec 14 12:48:26 2015
@author: rebecca
"""
import math, numpy, scipy.linalg
from math import exp, sqrt
from numpy import zeros
from scipy.linalg import norm
from .algorithms import Algorithm
......@@ -66,7 +69,7 @@ class RAAR(Algorithm):
beta = self.beta0;
iters = self.iters
change = numpy.zeros(maxiter+1,dtype=u.dtype);
change = zeros(maxiter+1,dtype=u.dtype);
change[0] = 999;
gap = change.copy();
......@@ -75,7 +78,7 @@ class RAAR(Algorithm):
##### LOOP
while iters < maxiter and change[iters] >= tol:
tmp = math.exp((-iters/self.beta_switch)**3);
tmp = exp((-iters/self.beta_switch)**3);
beta = (tmp*self.beta0) + ((1-tmp)*self.beta_max);
iters += 1;
......@@ -87,20 +90,20 @@ class RAAR(Algorithm):
tmp_change = 0; tmp_gap = 0;
if self.Ny == 1 or self.Nx == 1:
tmp_change = (scipy.linalg.norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (scipy.linalg.norm(tmp3-tmp2,'fro')/normM)**2;
tmp_change = (norm(u-tmp_u,'fro')/normM)**2;
tmp_gap = (norm(tmp3-tmp2,'fro')/normM)**2;
elif self.Nz == 1:
for j in xrange(self.dim):
tmp_change += (scipy.linalg.norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,j]-tmp2[:,:,j])/normM,'fro')**2;
tmp_change += (norm(u[:,:,j]-tmp_u[:,:,j],'fro')/normM)**2;
tmp_gap += (norm(tmp3[:,:,j]-tmp2[:,:,j])/normM,'fro')**2;
else:
for j in xrange(self.dim):
for k in xrange(self.Nz):
tmp_change += (scipy.linalg.norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (scipy.linalg.norm(tmp3[:,:,k,j]-tmp2[:,:,k,j],'fro')/normM)**2;
tmp_change += (norm(u[:,:,k,j]-tmp_u[:,:,k,j],'fro')/normM)**2;
tmp_gap += (norm(tmp3[:,:,k,j]-tmp2[:,:,k,j],'fro')/normM)**2;
change[iters] = math.sqrt(tmp_change);
gap[iters] = math.sqrt(tmp_gap);
change[iters] = sqrt(tmp_change);
gap[iters] = sqrt(tmp_gap);
u = tmp_u;
tmp1 = (2*tmp2) - tmp_u;
......
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