Commit 943962eb by constantin.hoeing

### QNAP demo

parent f060d157
 """ Phase_JWST_DRAP_demo written on Sep 17. 2019 by Constantin Höing Inst. Fuer Numerische und Angewandte Mathematik Universität Göttingen """ import sys sys.path.append('../proxtoolbox/Problems/Phase') # find out what should be in the string sys.path.append("..") import JWST_data_processor import JWST_QNAP_in from phase import Phase JWST = Phase(JWST_QNAP_in.new_config) JWST.solve() JWST.show()
 ... ... @@ -35,11 +35,11 @@ from numpy import zeros, isreal, zeros_like import numpy as np from algorithms import Algorithm from .algorithms import Algorithm import sys try: sys.path.append('../../samsara/python') from samsara import Samsara from .samsara import Samsara except: print('*********************************************************************') print('* SAMSARA package missing. Please download from *') ... ... @@ -60,6 +60,7 @@ class QNAP(Algorithm): self.norm_data = config['norm_data'] self.Nx = config['Nx']; self.Ny = config['Ny']; self.Nz = config['Nz'] self.product_space_dimension = config['product_space_dimension'] self.anim = config["anim"] if 'truth' in config: self.truth = config['truth'] ... ... @@ -195,9 +196,9 @@ class QNAP(Algorithm): tmp_u[:,:,j]=tmp2 else: tmp2=np.concatenate(np.real(u[:,:,0]),np.imag(u[:,:,0])) tmp2=np.concatenate((np.real(u[:,:,0]),np.imag(u[:,:,0])), axis=1) uold_vec=tmp2.reshape(self.Nx*self.Ny*2,1) tmp2= np.concatenate(np.real(tmp_u[:,:,0]), np.imag(tmp_u[:,:,0])) tmp2= np.concatenate((np.real(tmp_u[:,:,0]), np.imag(tmp_u[:,:,0])), axis=1) unew_vec = tmp2.reshape(self.Nx*self.Ny*2,1) if iter<=3: gradfnew_vec = uold_vec-unew_vec ... ... @@ -218,7 +219,7 @@ class QNAP(Algorithm): else: # product space of 3D arrays print('Cannot handle 3D arrays on the product space yet') tmp1 = self.prox2.run(tmp_u) tmp1 = self.prox2.work(tmp_u) tmp_change=0; tmp_gap=0 if(p==1)and(q==1): ... ... @@ -233,7 +234,7 @@ class QNAP(Algorithm): else: z=tmp_u; Relerrs[iter] = np.linalg.norm(self.truth - np.exp(-1j*np.angle(trace(self.truth*z))) * z, 'fro')/self.norm_truth; Relerrs[iter] = np.linalg.norm(self.truth - np.exp(-1j*np.angle(np.trace(self.truth*z))) * z, 'fro')/self.norm_truth; elif(q==1): ... ... @@ -253,7 +254,7 @@ class QNAP(Algorithm): tmp_gap = tmp_gap+(np.linalg.norm(tmp1[:,:,k,j]-tmp_u[:,:,k,j],'fro')/(norm_data))**2; if hasattr(self, "truth") and j == 1: # (any(strcmp('truth',fieldnames(method_input))))&&(j==1) Relerrs[iter] = Relerrs[iter]+np.linalg.norm(self.truth - exp(-1j*angle(trace(self.truth*tmp_u[:,:,:,1]))) * tmp_u[:,:,k,1], 'fro')/self.norm_truth; Relerrs[iter] = Relerrs[iter]+np.linalg.norm(self.truth - np.exp(-1j*np.angle(np.trace(self.truth*tmp_u[:,:,:,1]))) * tmp_u[:,:,k,1], 'fro')/self.norm_truth; ... ... @@ -264,18 +265,21 @@ class QNAP(Algorithm): if hasattr(self, "diagnostic"): #(any(strcmp('diagnostic', fieldnames(method_input)))) # graphics if (anim>=1)and (iter%2==0): #print(config["anim"]) if (self.anim>=1)and (iter%2==0): self.u=tmp1; self=self.animation(method_output); #self=self.animation(method_output); #self.animation() self.stats.time = toc; #self.stats.time = toc; tmp = self.prox1(u); tmp = self.prox1.work(u); self.u=tmp; tmp2 = self.prox2(u); tmp2 = self.prox2.work(u); if(self.Nx==1): self.u1 = tmp[:,0]; self.u2 = tmp2[:,0]; ... ... @@ -289,15 +293,21 @@ class QNAP(Algorithm): self.u1 = tmp; self.u2 = tmp2; change=change[1:iter]; self.stats.iter = iter-1; self.stats.change = change; change=change[0:iter]; self.iter = iter; print(self.iter) self.change = change; if hasattr(self, "diagnostic"): #(any(strcmp('diagnostic', fieldnames(method_input)))) gap=gap[1:iter]; self.stats.gap = gap; self.gap = gap; if hasattr(self, "truth"): #(any(strcmp('truth',fieldnames(method_input)))) self.stats.Relerrs=Relerrs; self.yRelerrs=Relerrs; # self.output = {} # for key, val in self.__dict__.items(): # if key != "output": # self.output[str(key)] = val return self.__dict__
 ... ... @@ -30,5 +30,6 @@ from .DRl import * from .GRAAL_F import * from .GRAAL_objective import * from .KM import * from .QNAP import * __all__ = ["AP","HPR","RAAR", "AP_expert", "GRAAL", "RAAR_expert", "DRl", "ADMM", "RRR", "CAARL", "CADRl", "CDRl", "CP", "CPrand", "DRAP", "DRl", "GRAAL_F", "GRAAL_objective", "KM"] __all__ = ["AP","HPR","RAAR", "AP_expert", "GRAAL", "RAAR_expert", "DRl", "ADMM", "RRR", "CAARL", "CADRl", "CDRl", "CP", "CPrand", "DRAP", "DRl", "GRAAL_F", "GRAAL_objective", "KM", "QNAP"]
 """Provides the class Samsara that is an unconstrained optimiser for real-valued functions. Running Samsara =============== Samsara is written for Python 3 (but works with Python 2.7) and has the following dependencies: * `numpy` * `matplotlib` You should also add the location of your samsara folder to the ``PYTHONPATH`` environment variable. To use Samsara with your project copy the `driver.py` file from the samsara folder to any destination you like and edit it with the function you want optimised. Running the Tests ================= To run the tests you will need to have MATLAB, the `matlab` module for Python installed (the module can be found with your installed MATLAB program in `/extern/engines/python`) and pytest installed. To run the test you then execute >>> py.test """ ### MODULE FUNCTION IMPORTS ### # Samsara from .samsara import Samsara # Hessian products and Scaler from .hessian import BFGS1_product, invBFGS1_product, Broyden1_product,\ invBroyden1_product, Broyden2_product, invBroyden2_product,\ delta_MSB2, delta_invBFGS # History from .history import fdSY_mat, cdSY_mat # Step finder from .step_finder import Dogleg_QN, Explicit_TR
 """ Extending samsara ----------------- Any functions from additional modules have to be imported in this file. """ ### MODULE FUNCTION IMPORTS ### # Samsara from .samsara import Samsara # Hessian products and Scaler from .hessian import BFGS1_product, invBFGS1_product, Broyden1_product,\ invBroyden1_product, Broyden2_product, invBroyden2_product,\ delta_MSB2, delta_invBFGS # History from .history import fdSY_mat, cdSY_mat # Step finder from .step_finder import Dogleg_QN, Explicit_TR