Commit bb6c32a3 authored by s.gretchko's avatar s.gretchko
Browse files

Added new code to match Matlab's Cone_and_Sphere

parent 35a7a8e7
......@@ -9,7 +9,7 @@ class test_P_M(unittest.TestCase):
def test_P_M(self):
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.prox.work(u).tolist(),np.array([(-0.46784903139375517+1.5204091013988432j), (1.4290442701495376+1.3514747567989709j), (1.936431529153929-0.1689343445998707j),
self.assertEqual(self.prox.eval(u).tolist(),np.array([(-0.46784903139375517+1.5204091013988432j), (1.4290442701495376+1.3514747567989709j), (1.936431529153929-0.1689343445998707j),
(2.110489706143043-1.5204091013988432j),(-1.968582497760174-1.3514747567989709j),-2.0395339762925806+0.1689343445998707j ]).tolist())
if __name__ == '__main__':
unittest.main()
......
......@@ -9,7 +9,7 @@ class test_P_RN(unittest.TestCase):
def test_P_RN(self):
u = np.array([1,2,3,4,5,6])
self.assertEqual(self.prox.work(u).tolist(),np.array([1,2,3,4,5,6]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([1,2,3,4,5,6]).tolist())
if __name__ == '__main__':
unittest.main()
#input: support_idx =[1,2]; u = [1,2,3,4,5,6];
......
......@@ -9,7 +9,7 @@ class test_P_S_real(unittest.TestCase):
def test_P_S_real(self):
u = np.array([2+3j,-4,5,-4,-3-2j])
self.assertEqual(self.prox.work(u).tolist(),np.array([2+0j,-4+0j,5+0j,0+0j,0+0j]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([2+0j,-4+0j,5+0j,0+0j,0+0j]).tolist())
if __name__ == '__main__':
unittest.main()
#input: support_idx =[1,2,3]; u = [2+3j,-4,5,-4,-3-2j];
......
......@@ -13,7 +13,7 @@ class test_P_avg(unittest.TestCase):
config = {'Prox':[P_binary,P_RN],'Nx':1,'Ny':1, 'Nz':0}
self.pro = P_avg(config)
u = np.array([[1,2,3,4],[5,6,-5,-6]])
self.assertEqual(self.pro.work(u).tolist(),np.array([3,4,-1,-1]).tolist())
self.assertEqual(self.pro.eval(u).tolist(),np.array([3,4,-1,-1]).tolist())
if __name__ == '__main__':
unittest.main()
#input: Nx=1,Ny=1,Nz=0; u = [1,2,3,4;5,6,-5,-6];
......
......@@ -8,7 +8,7 @@ class test_P_binary(unittest.TestCase):
config = {'support_idx':np.array([1,2])}
self.prox = P_binary(config)
u = np.array([1,2,3,4,5,6])
self.assertEqual(self.prox.work(u).tolist(),np.array([1,1,0,0,0,0]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([1,1,0,0,0,0]).tolist())
if __name__ == '__main__':
unittest.main()
#input: support_idx =[1,2]; u = [1,2,3,4,5,6];
......
......@@ -9,7 +9,7 @@ class test_P_nonneg_sparsity(unittest.TestCase):
def test_P_nonneg_sparsity(self):
u = np.array([[1,2,3],[-3,0,-4]])
self.assertEqual(self.prox.work(u).tolist(),np.array([[1,2,3],[0,0,0]]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([[1,2,3],[0,0,0]]).tolist())
if __name__ == '__main__':
unittest.main()
#input: sparsity_parmeter=3; u = [1,2,3;-3,0,-4];
......
......@@ -9,7 +9,7 @@ class test_P_parallel_scaled_hyperplane(unittest.TestCase):
def test_P_parallel_scaled_hyperplane(self):
u0 = np.array([-2,-12])
self.assertEqual(self.prox.work(u0).tolist(),np.array([-648.,613.5]).tolist())
self.assertEqual(self.prox.eval(u0).tolist(),np.array([-648.,613.5]).tolist())
if __name__ == '__main__':
unittest.main()
#input: A=[1,-3;12,-11], b=[2;3]; u = [-2;-12];
......
......@@ -9,7 +9,7 @@ class test_P_sequential_hyperplane(unittest.TestCase):
def test_P_sequential_hyperplane(self):
u = np.array([11,12,13])
self.assertEqual(self.pro.work(u).tolist(),np.array([-2824357061.5378065, -3109775163.705577
self.assertEqual(self.pro.eval(u).tolist(),np.array([-2824357061.5378065, -3109775163.705577
, -3395193265.873347]).tolist())
if __name__ == '__main__':
unittest.main()
......
......@@ -9,7 +9,7 @@ class test_Prox_l0(unittest.TestCase):
def test_Prox_l0(self):
u = np.array([1,-12,23,45,1000])
self.assertEqual(self.prox.work(u).tolist(),np.array([0,0,23,45,1000]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([0,0,23,45,1000]).tolist())
if __name__ == '__main__':
unittest.main()
#input: u= [1,-12,23,45,1000], sparsity_parameter=22
......
......@@ -9,7 +9,7 @@ class test_Prox_l1(unittest.TestCase):
def test_Prox_l1(self):
u = np.array([1,-2,3,4])
self.assertEqual(self.prox.work(u).tolist(),np.array([0,0,0,1]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([0,0,0,1]).tolist())
if __name__ == '__main__':
unittest.main()
#input: sparsity_paramter=3, u=[1,-2,3,4]
......
......@@ -9,7 +9,7 @@ class test_Prox_nonneg_l0(unittest.TestCase):
def test_Prox_nonneg_l0(self):
u = np.array([1,-11,0,12])
self.assertEqual(self.prox.work(u).tolist(),np.array([1,0,0,12]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([1,0,0,12]).tolist())
if __name__ == '__main__':
unittest.main()
#input:sparsity_parameter= -2, u=[1,-11,0,12]
......
......@@ -9,7 +9,7 @@ class test_Prox_nonneg_l1(unittest.TestCase):
def test_Prox_nonneg_l1(self):
u = np.array([1,-11,0,12])
self.assertEqual(self.prox.work(u).tolist(),np.array([3,0,2,14]).tolist())
self.assertEqual(self.prox.eval(u).tolist(),np.array([3,0,2,14]).tolist())
if __name__ == '__main__':
unittest.main()
#input:sparsity_parameter= -2, u=[1,-11,0,12]
......
#Sylvain
#SG
import SetProxPythonPath
from proxtoolbox.Problems.Phase.JWST_Experiment import JWST_Experiment
......
#Sylvain
#SG
import SetProxPythonPath
from proxtoolbox.Problems.Phase.JWST_Experiment import JWST_Experiment
......
......@@ -3,6 +3,6 @@
import SetProxPythonPath
from proxtoolbox.Problems.Phase.JWST_Experiment import JWST_Experiment
JWST = JWST_Experiment(algorithm = 'RAAR', beta_0 = 1.0, beta_max = 1.0, MAXIT = 500)
JWST = JWST_Experiment(algorithm = 'RAAR', beta_0 = 1.0, beta_max = 1.0, MAXIT = 1000)
JWST.run()
JWST.show()
#Sylvain
#SG
# Cone_and_sphere demo
import SetProxPythonPath
from proxtoolbox.Problems.Phase.JWST_Experiment import JWST_Experiment
......
......@@ -3,6 +3,8 @@
import SetProxPythonPath
from proxtoolbox.Problems.Phase.JWST_Experiment import JWST_Experiment
# Warning: Does not work with new Cone_and_sphere framework. Deprecated.
# Will be removed. New algorithm is QNAvP that uses QNAccelerator
JWST = JWST_Experiment(algorithm = 'QNAP', beta_0 = 0.85, beta_max = 0.85, MAXIT = 500)
JWST.run()
JWST.show()
......@@ -72,9 +72,9 @@ class ADMM(SimpleAlgorithm):
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)
u[0] = self.prox1.eval(u)
u[1] = self.prox2.eval(u)
u[2] = self.Lagr_mult_update.eval(u)
return u
......@@ -3,6 +3,6 @@ from .SimpleAlgortihm import SimpleAlgorithm
class AP(SimpleAlgorithm):
def evaluate(self, u):
tmp_u = self.prox2.work(u)
unew = self.prox1.work(tmp_u)
tmp_u = self.prox2.eval(u)
unew = self.prox1.eval(tmp_u)
return unew
......@@ -85,13 +85,13 @@ class AP_expert(Algorithm):
if hasattr(self, 'truth'):
Relerrs = change.copy()
tmp1 = prox2.work(u);
tmp1 = prox2.eval(u);
while iters < maxiter and change[iters] >= tol:
iters += 1;
tmp_u = prox1.work(tmp1);
tmp1 = prox2.work(tmp_u);
tmp_u = prox1.eval(tmp1);
tmp1 = prox2.eval(tmp_u);
tmp_change = 0; tmp_gap = 0;
if p==1 and q==1:
......@@ -124,8 +124,8 @@ class AP_expert(Algorithm):
u = tmp_u;
tmp = prox1.work(u);
tmp2 = prox2.work(u);
tmp = prox1.eval(u);
tmp2 = prox2.eval(u);
if self.Nx == 1:
......
Markdown is supported
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