diff --git a/denoising-plots/denoised_via_kerreg.pdf b/denoising-plots/denoised_via_kerreg.pdf deleted file mode 100644 index c129e230aed54d8196152bf497e39825b3c7b3b7..0000000000000000000000000000000000000000 Binary files a/denoising-plots/denoised_via_kerreg.pdf and /dev/null differ diff --git a/denoising-plots/examples.ipynb b/denoising-plots/examples.ipynb deleted file mode 100644 index e9e8b9dd8cc76e39f4ef4255268864b1dab1fe7b..0000000000000000000000000000000000000000 --- a/denoising-plots/examples.ipynb +++ /dev/null @@ -1,197 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 1, - "id": "6db15641", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [], - "text/plain": [ - "<IPython.core.display.HTML object>" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "\u001b[36m(pid=3980984)\u001b[0m /usr/lib/python3/dist-packages/scipy/__init__.py:146: UserWarning: A NumPy version >=1.17.3 and <1.25.0 is required for this version of SciPy (detected version 1.26.4\n", - "\u001b[36m(pid=3980984)\u001b[0m warnings.warn(f\"A NumPy version >={np_minversion} and <{np_maxversion}\"\n", - "2024-03-14 15:03:03,729\tWARNING tune.py:186 -- Stop signal received (e.g. via SIGINT/Ctrl+C), ending Ray Tune run. This will try to checkpoint the experiment state one last time. Press CTRL+C (or send SIGINT/SIGKILL/SIGTERM) to skip. \n", - "2024-03-14 15:03:09,319\tWARNING tune.py:1057 -- Experiment has been interrupted, but the most recent state was saved.\n", - "Resume experiment with: Tuner.restore(path=\"/home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04\", trainable=...)\n", - "2024-03-14 15:03:15,927\tWARNING experiment_analysis.py:193 -- Failed to fetch metrics for 17 trial(s):\n", - "- objective_STIS_99690_00970: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00970: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00970_970_beta1=100.0000,beta2=0.0100,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph__2024-03-14_15-02-55')\n", - "- objective_STIS_99690_00971: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00971: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00971_971_beta1=10.0000,beta2=0.0100,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a_2024-03-14_15-02-55')\n", - "- objective_STIS_99690_00972: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00972: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00972_972_beta1=1.0000,beta2=0.0100,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a5_2024-03-14_15-02-55')\n", - "- objective_STIS_99690_00974: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00974: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00974_974_beta1=0.0100,beta2=0.0100,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a5_2024-03-14_15-02-55')\n", - "- objective_STIS_99690_00976: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00976: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00976_976_beta1=10.0000,beta2=100.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_2024-03-14_15-03-00')\n", - "- objective_STIS_99690_00977: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00977: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00977_977_beta1=1.0000,beta2=100.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph__2024-03-14_15-03-00')\n", - "- objective_STIS_99690_00978: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00978: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00978_978_beta1=0.1000,beta2=100.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph__2024-03-14_15-03-00')\n", - "- objective_STIS_99690_00980: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00980: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00980_980_beta1=100.0000,beta2=10.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00982: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00982: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00982_982_beta1=1.0000,beta2=10.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00983: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00983: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00983_983_beta1=0.1000,beta2=10.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00984: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00984: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00984_984_beta1=0.0100,beta2=10.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00986: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00986: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00986_986_beta1=10.0000,beta2=1.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00987: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00987: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00987_987_beta1=1.0000,beta2=1.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a5_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00988: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00988: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00988_988_beta1=0.1000,beta2=1.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a5_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00989: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00989: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00989_989_beta1=0.0100,beta2=1.0000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a5_2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00990: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00990: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00990_990_beta1=100.0000,beta2=0.1000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph__2024-03-14_15-03-01')\n", - "- objective_STIS_99690_00991: FileNotFoundError('Could not fetch metrics for objective_STIS_99690_00991: both result.json and progress.csv were not found at /home/ypilavci/ray_results/objective_STIS_2024-03-14_14-56-04/objective_STIS_99690_00991_991_beta1=10.0000,beta2=0.1000,lambdaS=0.0000,lambdax=0.0000,sigma2=0.0400,t=ref_ph_8d1a09f1,x=ref_ph_a_2024-03-14_15-03-03')\n" - ] - } - ], - "source": [ - "import numpy as np\n", - "import scipy\n", - "import matplotlib.pyplot as plt\n", - "import quaternion # load the quaternion module\n", - "import bispy as bsp\n", - "import torch\n", - "from utils import STIS,optimize_loop,snr_bivariate,param_search,objective_STIS,objective_KReSP,KReSP,plot_on_sphere\n", - "from ray import tune,init\n", - "import pickle\n", - "\n", - "\n", - "init(num_cpus=16)\n", - "\n", - "## PLOT AN EXAMPLE \n", - "\n", - "np.random.seed(5)\n", - "N = 1024 # length of the signal\n", - "t = np.linspace(0, 2*np.pi/4, N) # time vector\n", - "dt = t[1]-t[0]\n", - "\n", - "# ellipse parameters - AM-FM-PM polarized \n", - "theta1 = np.pi/4 - 2*t\n", - "chi1 = np.pi/16 - t\n", - "phi1 = 0 \n", - "f0 = 25/N/dt \n", - "S0 = bsp.utils.windows.hanning(N)\n", - "\n", - "x_quad = bsp.signals.bivariateAMFM(S0, theta1, chi1, 2*np.pi*f0*t+ phi1)\n", - "x = quaternion.as_float_array(x_quad)[:,:2]\n", - "\n", - "\n", - "bsp.utils.visual.plot3D(t,x_quad)\n", - "plt.savefig(\"clean_sig.pdf\")\n", - "plt.close()\n", - "\n", - "sigma = 0.2\n", - "n = np.zeros([N,4])\n", - "noise_complex = np.random.randn(N,2)\n", - "y = x +sigma*noise_complex\n", - "\n", - "uH = np.imag(scipy.signal.hilbert(noise_complex[:,0]))\n", - "vH = np.imag(scipy.signal.hilbert(noise_complex[:,1]))\n", - "n[:,0] = noise_complex[:,0]\n", - "n[:,1] = noise_complex[:,1]\n", - "n[:,2] = uH\n", - "n[:,3] = vH\n", - "n = quaternion.from_float_array(n)\n", - "y_quad = sigma*n + x_quad # Noisy signal\n", - "\n", - "ax = plt.figure().add_subplot(projection='3d')\n", - "# ax.view_init(15,-135,0)\n", - "plt.title(\"Normalized Stokes Parameters\")\n", - "plt.tight_layout()\n", - "plot_on_sphere(y_quad,ax,label=\"noisy signal\",t=t,scatter=True)\n", - "plot_on_sphere(x_quad,ax,label=\"original signal\",scatter=False)\n", - "\n", - "plt.legend()\n", - "plt.tight_layout()\n", - "plt.savefig(\"noisy_sig_sphere.pdf\")\n", - "plt.close()\n", - "\n", - "bsp.utils.visual.plot3D(t,y_quad)\n", - "plt.savefig(\"noisy_sig.pdf\")\n", - "\n", - "\n", - "print(\"sigma: \" + str(sigma) + \" Noise SNR: \"+ str(snr_bivariate(x,y) ) )\n", - "search_space = {\"x\":tune.grid_search([x]),\"t\":tune.grid_search([t]),\"y\":tune.grid_search([y]),\"lambdax\": tune.grid_search((0.1)**np.linspace(5,15,7)), \"lambdaS\": tune.grid_search((0.1)**np.linspace(5,10,7)) , \"beta1\":tune.grid_search((0.10)**np.linspace(-2,2,5)),\"beta2\":tune.grid_search((0.10)**np.linspace(-2,2,5)),\"sigma2\":tune.grid_search([sigma**2])}\n", - "config = param_search(objective_STIS,search_space)\n", - "model = STIS(t,y,lambdax=config[\"lambdax\"],lambdaS=config[\"lambdaS\"],beta1=config[\"beta1\"],beta2=config[\"beta2\"],sigma2=sigma**2,p=2)\n", - "optimizer = torch.optim.Adam(model.parameters(), lr=0.01)\n", - "model = optimize_loop(model,optimizer,numit=1000)\n", - "\n", - "x_stis = quaternion.from_float_array(model.Xquad.detach().numpy())\n", - "bsp.utils.visual.plot2D(t,x_stis)\n", - "plt.savefig(\"denoised_via_all_terms.pdf\")\n", - "\n", - "print(\"sigma: \" + str(sigma) + \" STIS SNR: \"+ str(snr_bivariate(x,model.X.detach().numpy())))\n", - "\n", - "\n", - "# NO STOKES REGULARIZATION \n", - "search_space = {\"x\":tune.grid_search([x]),\"t\":tune.grid_search([t]),\"y\":tune.grid_search([y]),\"lambdax\": tune.grid_search((0.1)**np.linspace(5,15,7)), \"lambdaS\":tune.grid_search([0.0]) , \"beta1\":tune.grid_search([0.0]),\"beta2\":tune.grid_search([0.0]),\"sigma2\":tune.grid_search([sigma**2])}\n", - "config = param_search(objective_STIS,search_space)\n", - "model = STIS(t,y,lambdax=config[\"lambdax\"],lambdaS=config[\"lambdaS\"],beta1=config[\"beta1\"],beta2=config[\"beta2\"],sigma2=sigma**2,p=2)\n", - "optimizer = torch.optim.Adam(model.parameters(), lr=0.01)\n", - "model = optimize_loop(model,optimizer,numit=1000)\n", - "\n", - "print(\"sigma: \" + str(sigma) + \" STIS SNR: \"+ str((snr_bivariate(x,model.X.detach().numpy()))))\n", - "x_nostokes = quaternion.from_float_array(model.Xquad.detach().numpy())\n", - "bsp.utils.visual.plot2D(t,x_nostokes)\n", - "plt.savefig(\"denoised_via_no_stokes.pdf\")\n", - "\n", - "# ONLY SMOOTH STOKES\n", - "search_space = {\"x\":tune.grid_search([x]),\"t\":tune.grid_search([t]),\"y\":tune.grid_search([y]),\"lambdax\": tune.grid_search([0.0]), \"lambdaS\": tune.grid_search((0.1)**np.linspace(5,10,7)) , \"beta1\":tune.grid_search((0.1)**np.linspace(-2,2,7)),\"beta2\":tune.grid_search((0.1)**np.linspace(-2,2,5)),\"sigma2\":tune.grid_search([sigma**2])}\n", - "config = param_search(objective_STIS,search_space)\n", - "model = STIS(t,y,lambdax=config[\"lambdax\"],lambdaS=config[\"lambdaS\"],beta1=config[\"beta1\"],beta2=config[\"beta2\"],sigma2=sigma**2,p=2)\n", - "optimizer = torch.optim.Adam(model.parameters(), lr=0.01)\n", - "model = optimize_loop(model,optimizer,numit=1000)\n", - "x_onlystokes = quaternion.from_float_array(model.Xquad.detach().numpy())\n", - "bsp.utils.visual.plot2D(t,x_onlystokes)\n", - "plt.savefig(\"denoised_via_no_signal_smoother.pdf\")\n", - "\n", - "print(\"sigma: \" + str(sigma) + \" STIS SNR: \"+ str((snr_bivariate(x,model.X.detach().numpy()))))\n", - "\n", - "# Kernel regression on normalized \n", - "search_space = {\"x\":tune.grid_search([x]),\"t\":tune.grid_search([t]),\"y\":tune.grid_search([y]),\"alpha\": tune.grid_search((0.1)**np.linspace(5,15,5)),\"lambda_1\": tune.grid_search((0.1)**np.linspace(5,15,5)), \"lambda_s\": tune.grid_search((0.1)**np.linspace(5,10,5)) , \"beta\":tune.grid_search((0.10)**np.linspace(-2,2,5)),\"gamma\":tune.grid_search((0.1)**np.linspace(0,1,5)),\"sigma2\":tune.grid_search([sigma**2])}\n", - "config = param_search(objective_KReSP,search_space)\n", - "model = KReSP(t,y,lambda_1=config[\"lambda_1\"],beta=config[\"beta\"],lambda_s=config[\"lambda_s\"],alpha=config[\"alpha\"],gamma=config[\"gamma\"],eps=10**-7,win_width=64,sigma2=sigma**2)\n", - "optimizer = torch.optim.Adam(model.parameters(), lr=0.01)\n", - "model = optimize_loop(model,optimizer,numit=300)\n", - "\n", - "\n", - "print(\"sigma: \" + str(sigma) + \" KReSP SNR: \"+ str(snr_bivariate(x,model.X.detach().numpy())))\n", - "x_kerreg = quaternion.from_float_array(model.Xquad.detach().numpy())\n", - "bsp.utils.visual.plot2D(t,x_kerreg)\n", - "plt.savefig(\"denoised_via_kerreg.pdf\")\n", - "\n", - "with open('example.pkl', 'wb') as f:\n", - "\tpickle.dump(x,f)\n", - "\tpickle.dump(y,f)\n", - "\tpickle.dump(x_stis,f)\n", - "\tpickle.dump(x_nostokes,f)\n", - "\tpickle.dump(x_onlystokes,f)\n", - "\tpickle.dump(x_kerreg,f)\n" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}