Commit d091e36d authored by jansen31's avatar jansen31
Browse files

Merge remote-tracking branch 'origin/dornheim' into dornheim

# Conflicts:
#	proxtoolbox/ProxOperators/P_M.py
#	proxtoolbox/ProxOperators/P_Sparsity.py
parents f9c08834 b0c8f349
......@@ -4,3 +4,4 @@ docs/Manual/autotoc/
_build
build
dist
proxtoolbox/Algorithms/samsara
\ No newline at end of file
......@@ -4,13 +4,28 @@ from proxtoolbox.Algorithms.CAARL import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_CAARL(unittest.TestCase):
def test_CAARL(self):
config={'proxoperators':[P_binary,P_RN,P_M],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'M':np.array([1,2,2,2,2,12])}
self.pro= CAARL(config)
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(u).tolist(),np.array([ -1.8703690419340218+8.437742860180073j , 2.5477381663013103+8.807889679799857j,-7.613529601089619+0.3701468196197832j, -12.384068573713796-8.437742860180071j, 9.483898643023636-8.807889679799857j, 9.836330407412484-0.3701468196197823j]).tolist())
config = {'proxoperators': [P_binary, P_RN, P_M], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_binary, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'M': np.array([1, 2, 2, 2, 2, 12])}
self.pro = CAARL(config)
u = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(u).tolist(), np.array(
[-1.8703690419340218 + 8.437742860180073j, 2.5477381663013103 + 8.807889679799857j,
-7.613529601089619 + 0.3701468196197832j, -12.384068573713796 - 8.437742860180071j,
9.483898643023636 - 8.807889679799857j, 9.836330407412484 - 0.3701468196197823j]).tolist())
if __name__ == '__main__':
unittest.main()
#inut:u=[1,2,5,6,-5,-6]
#output:[ -1.8703690419340218+8.437742860180073j , 2.5477381663013103+8.807889679799857j,-7.613529601089619+0.3701468196197832j, -12.384068573713796-8.437742860180071j, 9.483898643023636-8.807889679799857j, 9.836330407412484-0.3701468196197823j]
# inut:u=[1,2,5,6,-5,-6]
# output:[ -1.8703690419340218+8.437742860180073j ,
# 2.5477381663013103 + 8.807889679799857j,
# -7.613529601089619 + 0.3701468196197832j,
# -12.384068573713796 - 8.437742860180071j,
# 9.483898643023636 - 8.807889679799857j,
# 9.836330407412484 - 0.3701468196197823j]
......@@ -4,11 +4,21 @@ from proxtoolbox.Algorithms.CADRl import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_CADRl(unittest.TestCase):
def test_CADRl(self):
config={'proxoperators':[P_RN,P_M,P_binary],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'M':np.array([1,2,2,2,2,12])}
self.pro= CADRl(config)
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(u).tolist(),np.array([ (-1.9356980627875102+3.0408182027976864j) ,0.8580885402990752+2.7029495135979418j,-1.1271369416921422-0.3378686891997414j,-1.779020587713914-3.0408182027976864j,1.062835004479652-2.7029495135979418j, 1.9209320474148388+0.3378686891997414j]).tolist())
config = {'proxoperators': [P_RN, P_M, P_binary], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_binary, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'M': np.array([1, 2, 2, 2, 2, 12])}
self.pro = CADRl(config)
u = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(u).tolist(), np.array(
[(-1.9356980627875102 + 3.0408182027976864j), 0.8580885402990752 + 2.7029495135979418j,
-1.1271369416921422 - 0.3378686891997414j, -1.779020587713914 - 3.0408182027976864j,
1.062835004479652 - 2.7029495135979418j, 1.9209320474148388 + 0.3378686891997414j]).tolist())
if __name__ == '__main__':
unittest.main()
......@@ -4,12 +4,21 @@ from proxtoolbox.Algorithms.CDRl import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_CDRl(unittest.TestCase):
def test_CDRl(self):
config={'proxoperators':[P_binary,P_RN,P_M],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'M':np.array([1,2,2,2,2,12]),'lambda0':2,'lambda_max':2,'lambda_switch':1,'lambda_0':2}
self.pro= CDRl(config)
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(u).tolist(),np.array([ 0.9510576492339013-2.7982183410847505j,1.2326217479829011-2.9678073314535216j ,16.23359565239013-0.169588990368774j ,19.54586980521637+2.798218341084751j ,-16.18465330162403+2.967807331453521j , -19.778491553199267+0.169588990368774j]).tolist())
config = {'proxoperators': [P_binary, P_RN, P_M], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_binary, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'M': np.array([1, 2, 2, 2, 2, 12]), 'lambda0': 2, 'lambda_max': 2, 'lambda_switch': 1, 'lambda_0': 2}
self.pro = CDRl(config)
u = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(u).tolist(), np.array(
[0.9510576492339013 - 2.7982183410847505j, 1.2326217479829011 - 2.9678073314535216j,
16.23359565239013 - 0.169588990368774j, 19.54586980521637 + 2.798218341084751j,
-16.18465330162403 + 2.967807331453521j, -19.778491553199267 + 0.169588990368774j]).tolist())
if __name__ == '__main__':
unittest.main()
......@@ -4,14 +4,20 @@ from proxtoolbox.Algorithms.CDRlrand import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_CDRlrand(unittest.TestCase):
def test_CDRlrand(self):
config={'proxoperators':[P_binary,P_RN,P_M],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'M':np.array([1,2,2,2,2,12]),'lambda0':2,'lambda_max':2,'lambda_switch':1,'lambda_0':2}
self.pro= CDRlrand(config)
u = np.array([1,2,5,6,-5,-6])
# self.assertEqual(self.pro.evaluate(u).tolist(),np.array([ 0.9510576492339013-2.7982183410847505j,1.2326217479829011-2.9678073314535216j ,16.23359565239013-0.169588990368774j ,19.54586980521637+2.798218341084751j ,-16.18465330162403+2.967807331453521j , -19.778491553199267+0.169588990368774j]).tolist())
config = {'proxoperators': [P_binary, P_RN, P_M], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_binary, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'M': np.array([1, 2, 2, 2, 2, 12]), 'lambda0': 2, 'lambda_max': 2, 'lambda_switch': 1, 'lambda_0': 2}
self.pro = CDRlrand(config)
u = np.array([1, 2, 5, 6, -5, -6])
# self.assertEqual(self.pro.evaluate(u).tolist(),np.array([ 0.9510576492339013-2.7982183410847505j,1.2326217479829011-2.9678073314535216j ,16.23359565239013-0.169588990368774j ,19.54586980521637+2.798218341084751j ,-16.18465330162403+2.967807331453521j , -19.778491553199267+0.169588990368774j]).tolist())
#randomized algorithm, no deterministic result for given input
# randomized algorithm, no deterministic result for given input
if __name__ == '__main__':
unittest.main()
......@@ -4,11 +4,21 @@ from proxtoolbox.Algorithms.CP import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_CP(unittest.TestCase):
def test_CP(self):
config={'proxoperators':[P_RN,P_M,P_binary],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'M':np.array([1,2,2,2,2,12])}
self.pro= CP(config)
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(u).tolist(),np.array([ 2.5632402409811483+0.8545904827420623j, 2.4782116433462313-0.8545904827420624j, -0.45748570118254206-1.6454095172579373j,-1.5632402409811479-0.8545904827420623j , -1.4782116433462318+0.8545904827420624j,-0.5425142988174578+1.6454095172579373j]).tolist())
config = {'proxoperators': [P_RN, P_M, P_binary], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_binary, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'M': np.array([1, 2, 2, 2, 2, 12])}
self.pro = CP(config)
u = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(u).tolist(), np.array(
[2.5632402409811483 + 0.8545904827420623j, 2.4782116433462313 - 0.8545904827420624j,
-0.45748570118254206 - 1.6454095172579373j, -1.5632402409811479 - 0.8545904827420623j,
-1.4782116433462318 + 0.8545904827420624j, -0.5425142988174578 + 1.6454095172579373j]).tolist())
if __name__ == '__main__':
unittest.main()
......@@ -4,11 +4,21 @@ from proxtoolbox.Algorithms.CPrand import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_CPrand(unittest.TestCase):
def test_CPrand(self):
config={'proxoperators':[P_RN,P_M,P_binary],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'M':np.array([1,2,2,2,2,12])}
self.pro= CPrand(config)
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(u).tolist(),np.array([ 2.5632402409811483+0.8545904827420623j, 2.4782116433462313-0.8545904827420624j, -0.45748570118254206-1.6454095172579373j,-1.5632402409811479-0.8545904827420623j , -1.4782116433462318+0.8545904827420624j,-0.5425142988174578+1.6454095172579373j]).tolist())
config = {'proxoperators': [P_RN, P_M, P_binary], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_binary, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'M': np.array([1, 2, 2, 2, 2, 12])}
self.pro = CPrand(config)
u = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(u).tolist(), np.array(
[2.5632402409811483 + 0.8545904827420623j, 2.4782116433462313 - 0.8545904827420624j,
-0.45748570118254206 - 1.6454095172579373j, -1.5632402409811479 - 0.8545904827420623j,
-1.4782116433462318 + 0.8545904827420624j, -0.5425142988174578 + 1.6454095172579373j]).tolist())
if __name__ == '__main__':
unittest.main()
......@@ -3,16 +3,22 @@ import numpy as np
from proxtoolbox.Algorithms.DRAP import *
from proxtoolbox.ProxOperators.P_M import *
from proxtoolbox.ProxOperators.P_RN import *
class test_DRAP(unittest.TestCase):
def test_DRAP(self):
config={'proxoperators':[P_M,P_RN],'beta_0':2 ,'beta_max':2,'beta_switch':1,
'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),
'norm_data':2, 'Nx':6,'Ny':0,'Nz':0, 'product_space_dimension':1,'M':np.array([1,2,2,2,2,12])}
u=np.array([1,2,5,6,-5,-6])
self.pro= DRAP(config)
self.assertEqual(self.pro.evaluate(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())
config = {'proxoperators': [P_M, P_RN], 'beta_0': 2, 'beta_max': 2, 'beta_switch': 1,
'prox_idx': 2, 'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]),
'norm_data': 2, 'Nx': 6, 'Ny': 0, 'Nz': 0, 'product_space_dimension': 1,
'M': np.array([1, 2, 2, 2, 2, 12])}
u = np.array([1, 2, 5, 6, -5, -6])
self.pro = DRAP(config)
self.assertEqual(self.pro.evaluate(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()
......@@ -4,14 +4,23 @@ from proxtoolbox.Algorithms.GRAAL_F import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_GRAAL_F(unittest.TestCase):
def test_GRAAL_F(self):
config={'proxoperators': [P_M,P_RN,P_binary],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_M,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'Fx':np.array([1,2,3]),'phi':2, 'T': P_M,'M':np.array([1,2,2,2,2,12])}
self.pro= GRAAL_F(config)
x = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(x).tolist(),np.array([ 1.467849031393755-1.5204091013988432j , 0.5709557298504624-1.3514747567989709j , 3.063568470846071+0.1689343445998707j ,3.889510293856957+1.5204091013988432j, -3.031417502239826+1.3514747567989709j, -3.9604660237074194-0.1689343445998707j]).tolist())
config = {'proxoperators': [P_M, P_RN, P_binary], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_M, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'Fx': np.array([1, 2, 3]), 'phi': 2, 'T': P_M, 'M': np.array([1, 2, 2, 2, 2, 12])}
self.pro = GRAAL_F(config)
x = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(x).tolist(), np.array(
[1.467849031393755 - 1.5204091013988432j, 0.5709557298504624 - 1.3514747567989709j,
3.063568470846071 + 0.1689343445998707j, 3.889510293856957 + 1.5204091013988432j,
-3.031417502239826 + 1.3514747567989709j, -3.9604660237074194 - 0.1689343445998707j]).tolist())
if __name__ == '__main__':
unittest.main()
#input:x = [1,2,5,6,-5,-6], M:[1,2,2,2,2,12],T: P_M
#output:[ 1.46785-1.52041j 0.57096-1.35147j 3.06357+0.16893j 3.88951+1.520401j -3.03142 +1.35147j -3.96047-0.16893j]
# input:x = [1,2,5,6,-5,-6], M:[1,2,2,2,2,12],T: P_M
# output:[ 1.46785-1.52041j 0.57096-1.35147j 3.06357+0.16893j 3.88951+1.520401j -3.03142 +1.35147j -3.96047-0.16893j]
import numpy as np
import unittest
from proxtoolbox.Algorithms.GRAAL_objective import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_GRAAL_objective(unittest.TestCase):
def test_GRAAL_objective(self):
config={'proxoperators': [P_M,P_RN,P_binary],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_M,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'Fx':np.array([1,2,3]),'phi':2, 'T': P_M,'M':np.array([1,2,2,2,2,12]),'Fx1':np.array([ 1.467849031393755-1.5204091013988432j , 0.5709557298504624-1.3514747567989709j , 3.063568470846071+0.1689343445998707j ,3.889510293856957+1.5204091013988432j, -3.031417502239826+1.3514747567989709j, -3.9604660237074194-0.1689343445998707j])}
self.pro= GRAAL_objective(config)
x = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(x),7.759022480773861)
config = {'proxoperators': [P_M, P_RN, P_binary], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_M, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'Fx': np.array([1, 2, 3]), 'phi': 2, 'T': P_M, 'M': np.array([1, 2, 2, 2, 2, 12]), 'Fx1': np.array(
[1.467849031393755 - 1.5204091013988432j, 0.5709557298504624 - 1.3514747567989709j,
3.063568470846071 + 0.1689343445998707j, 3.889510293856957 + 1.5204091013988432j,
-3.031417502239826 + 1.3514747567989709j, -3.9604660237074194 - 0.1689343445998707j])}
self.pro = GRAAL_objective(config)
x = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(x), 7.759022480773861)
if __name__ == '__main__':
unittest.main()
#input:Fx1:[ 1.46785-1.52041j 0.57096-1.35147j 3.06357+0.16893j 3.88951+1.520401j -3.03142 +1.35147j -3.96047-0.16893j]
#output:7.7590
# input:Fx1:[ 1.46785-1.52041j 0.57096-1.35147j 3.06357+0.16893j 3.88951+1.520401j -3.03142 +1.35147j -3.96047-0.16893j]
# output:7.7590
......@@ -4,14 +4,20 @@ from proxtoolbox.Algorithms.KM import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
# input: config={'proxoperators':[P_binary,P_RN,P_avg],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'Fx':np.array([1,2,3]),'phi':2}
#u=[1,2,5,6,-5,-6],
# u=[1,2,5,6,-5,-6],
class test_KM(unittest.TestCase):
def test_KM(self):
config={'proxoperators':[P_binary,P_RN,P_M],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'Fx':np.array([1,2,3]),'phi':2, 'T':P_M,'M':np.array([1,2,2,2,2,12])}
self.pro= KM(config)
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(u).tolist(),np.array([1000,1001,1004,1005,994,993]).tolist())
config = {'proxoperators': [P_binary, P_RN, P_M], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2,
'iter': 10, 'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0,
'Prox': [P_binary, P_RN], 'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2,
'Fx': np.array([1, 2, 3]), 'phi': 2, 'T': P_M, 'M': np.array([1, 2, 2, 2, 2, 12])}
self.pro = KM(config)
u = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(u).tolist(), np.array([1000, 1001, 1004, 1005, 994, 993]).tolist())
if __name__ == '__main__':
unittest.main()
......@@ -4,13 +4,22 @@ from proxtoolbox.Algorithms.RRR import *
from proxtoolbox.ProxOperators.P_binary import *
from proxtoolbox.ProxOperators.P_RN import *
from proxtoolbox.ProxOperators.P_M import *
class test_RRR(unittest.TestCase):
def test_RRR(self):
config={'proxoperators':[P_RN,P_M],'beta0':2 ,'beta_max':2,'beta_switch':1,'prox_idx':2,'iter':10,'prox_idx':2,'support_idx':np.array([1,2]),'Nx':8,'Ny':0,'Nz':0,'Prox':[P_binary,P_RN], 'norm_data':1, 'product_space_dimension':5,'beta_0':2,'M':np.array([1,2,2,2,2,12])}
self.pro= RRR(config)
u = np.array([1,2,5,6,-5,-6])
self.assertEqual(self.pro.evaluate(u).tolist(),np.array([-2.93569806278751+3.0408182027976864j,-1.1419114597009248+2.7029495135979418j,-6.127136941692142-0.3378686891997414j,-7.779020587713914-3.0408182027976864j,6.062835004479652-2.7029495135979418j,7.920932047414839+0.3378686891997414j]).tolist())
config = {'proxoperators': [P_RN, P_M], 'beta0': 2, 'beta_max': 2, 'beta_switch': 1, 'prox_idx': 2, 'iter': 10,
'prox_idx': 2, 'support_idx': np.array([1, 2]), 'Nx': 8, 'Ny': 0, 'Nz': 0, 'Prox': [P_binary, P_RN],
'norm_data': 1, 'product_space_dimension': 5, 'beta_0': 2, 'M': np.array([1, 2, 2, 2, 2, 12])}
self.pro = RRR(config)
u = np.array([1, 2, 5, 6, -5, -6])
self.assertEqual(self.pro.evaluate(u).tolist(), np.array(
[-2.93569806278751 + 3.0408182027976864j, -1.1419114597009248 + 2.7029495135979418j,
-6.127136941692142 - 0.3378686891997414j, -7.779020587713914 - 3.0408182027976864j,
6.062835004479652 - 2.7029495135979418j, 7.920932047414839 + 0.3378686891997414j]).tolist())
if __name__ == '__main__':
unittest.main()
#input:u=[1,2,5,6,-5,-6]
#output:[-2.9357+3.0408j,-1.1419+2.7029j,-6.1271-0.3379j, -7.7790-3.0408j,6.0628-2.7029j,7.9209+0.3379j]
# input:u=[1,2,5,6,-5,-6]
# output:[-2.9357+3.0408j,-1.1419+2.7029j,-6.1271-0.3379j, -7.7790-3.0408j,6.0628-2.7029j,7.9209+0.3379j]
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
......@@ -115,7 +115,7 @@ class SimpleAlgorithm:
config['u'] = u
u_new = self.evaluate(u)
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
# the next prox operation only gets used in the computation of
# the size of the gap. This extra step is not
# required in alternating projections, which makes RAAR
......@@ -132,7 +132,7 @@ class SimpleAlgorithm:
# tmp_change = (norm(u - u_new, 'fro') / norm_data) ** 2
tmp_change = phase_offset_compensated_norm(u, u_new, norm_type='fro', norm_factor=norm_data) ** 2
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
# For Douglas-Rachford,in general it is appropriate to monitor the
# SHADOWS of the iterates, since in the convex case these converge
# even for beta=1.
......@@ -157,24 +157,24 @@ class SimpleAlgorithm:
elif q == 1:
for j in range(self.product_space_dimension):
tmp_change = tmp_change + (norm(u[:, :, j] - u_new[:, :, j], 'fro') / norm_data) ** 2
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
# compute (||P_SP_Mx-P_Mx||/norm_data)^2:
tmp_gap = tmp_gap + (norm(u1[:, :, j] - u2[:, :, j], 'fro') / norm_data) ** 2
tmp_shadow = tmp_shadow + (norm(u2[:, :, j] - shadow[:, :, j], 'fro') / norm_data) ** 2
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
if hasattr(self, 'truth'):
z = u1[:, :, 0]
Relerrs[iter] = norm((self.truth - exp(-1j * angle(trace(self.truth.T.transpose() * z))) * z),'fro') / self.norm_truth
else:
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
if hasattr(self, 'truth'):
Relerrs[iter] = 0
for j in range(self.product_space_dimension):
for k in range(self.Nz):
tmp_change = tmp_change + (norm(u[:, :, k, j] - u_new[:, :, k, j], 'fro') / norm_data) ** 2
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
# compute (||P_Sx-P_Mx||/norm_data)^2:
tmp_gap = tmp_gap + (norm(u1[:, :, k, j] - u2[:, :, k, j], 'fro') / (norm_data)) ** 2
tmp_shadow = tmp_shadow + (
......@@ -185,7 +185,7 @@ class SimpleAlgorithm:
'fro') / self.norm_Truth
change[iter] = sqrt(tmp_change)
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
gap[iter] = sqrt(tmp_gap)
shadow_change[iter] = sqrt(tmp_shadow) # this is the Euclidean norm of the gap to
# the unregularized set. To monitor the Euclidean norm of the gap to the
......@@ -196,7 +196,7 @@ class SimpleAlgorithm:
# update
u = u_new
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
# For Douglas-Rachford,in general it is appropriate to monitor the
# SHADOWS of the iterates, since in the convex case these converge
# even for beta=1.
......@@ -219,7 +219,7 @@ class SimpleAlgorithm:
change = change[1:iter + 1]
output = {'u': u, 'u1': u1, 'u2': u2, 'iter': iter, 'change': change}
if 'diagnostic' in self.config:
if 'diagnostic' in self.config and self.config['diagnostic']:
gap = gap[1:iter + 1]
shadow_change = shadow_change[1:iter + 1]
output['gap'] = gap
......
......@@ -31,6 +31,7 @@
from matplotlib.pyplot import subplots, show
import numpy as np
from .complex_field_visualization import complex_to_rgb
from .stack_viewer import XYZStackViewer, SingleStackViewer
def Phase_graphics(config, output):
......@@ -84,3 +85,8 @@ def Phase_graphics(config, output):
bx4.set_ylabel('$||x^{2k+1}-x^{2k}||$')
show()
def Phase_graphics_3d(config, output):
# TODO: combine 3D graphics and convergence plots
return 0
from .Phase_graphics import Phase_graphics
from .array_tools import *
# from proxtoolbox.Utilities.OrbitalTomog.array_tools import *
from .complex_field_visualization import complex_to_rgb
from .stack_viewer import XYZStackViewer, SingleStackViewer
__all__ = ["Phase_graphics", "roll_to_pos", "complex_to_rgb",'fourier_interpolate']
__all__ = ["Phase_graphics", "complex_to_rgb", # 'fourier_interpolate', "roll_to_pos",
'XYZStackViewer', 'SingleStackViewer']
import numpy as np
from scipy.ndimage import measurements
import scipy.fftpack as fft
def shift_array(arr, dy, dx):
temp = np.roll(arr, (dy, dx), (0, 1))
return temp
def roll_to_pos(arr, y=0, x=0, move_maximum=False, by_abs_val=True):
if move_maximum:
if by_abs_val or arr.dtype in [np.complex64, np.complex128]:
old = np.floor(measurements.maximum_position(abs(arr)))
else:
old = np.floor(measurements.maximum_position(arr))
else:
if by_abs_val or arr.dtype in [np.complex64, np.complex128]:
old = np.floor(measurements.center_of_mass(abs(arr)))
else:
old = np.floor(measurements.center_of_mass(arr))
temp = shift_array(arr, int(y - old[0]), int(x - old[1]))
return temp
def shifted_fft(arr):
return fft.ifftshift(fft.fft2(fft.fftshift(arr)))
def shifted_ifft(arr):
return fft.fftshift(fft.ifft2(fft.ifftshift(arr)))
def fourier_interpolate(arr):
"""
Interpolate 2d complex array by a factor 2
:param arr: numpy array
:return: interpolated array
"""
ny, nx = arr.shape
assert ny == nx
pd = int(ny / 2)
_arr = roll_to_pos(arr, pd, pd, move_maximum=True)
_arr = roll_to_pos(_arr, pd, pd)
fd = shifted_fft(arr)
tmp = np.pad(fd, ((pd, pd), (pd, pd)), mode='constant')
return shifted_ifft(tmp)
import matplotlib.pyplot as plt
from matplotlib import get_backend
from numpy import max, min
from matplotlib.widgets import Slider
from warnings import warn
good_backends = ['Qt5Agg', 'TkAgg', 'Qt4Agg']
class SingleStackViewer:
def __init__(self, volume):
"""
Create window showing a slice of the 3d data, allows to scan the slice position using j, k keys.
Note that k will also change the x-axis if the mouse is hovering over the window.