├── HighDataRegime ├── .ipynb_checkpoints │ ├── Advection-JaxKernels-OutputPCAd-checkpoint.ipynb │ ├── Advection-JaxKernels-checkpoint.ipynb │ ├── Advection-Plots-checkpoint.ipynb │ ├── Advection-checkpoint.ipynb │ ├── Complexity accuracy Plot-checkpoint.ipynb │ ├── Helmholtz-Jax-checkpoint.ipynb │ ├── Helmholtz-JaxKernels-OutputPCAd-Copy1-checkpoint.ipynb │ ├── Helmholtz-JaxKernels-checkpoint.ipynb │ ├── Helmholtz-checkpoint.ipynb │ ├── Navier-Stokes-JaxKernels-Feature maps-checkpoint.ipynb │ ├── Navier-Stokes-JaxKernels-OutputPCAd-checkpoint.ipynb │ ├── Navier-Stokes-JaxKernels-checkpoint.ipynb │ ├── Navier-Stokes-checkpoint.ipynb │ ├── Plotting templates-checkpoint.ipynb │ ├── Struc-JaxKernels-OutputPCAd-checkpoint.ipynb │ ├── Structural Mechanics-JaxKernels-checkpoint.ipynb │ └── Structural Mechanics-checkpoint.ipynb ├── Advection-JaxKernels-OutputPCAd.ipynb ├── Advection-JaxKernels.ipynb ├── Advection-Plots.ipynb ├── Advection.ipynb ├── Complexity accuracy Plot.ipynb ├── Figures │ ├── AccuracyComplexity.pdf │ ├── ErrorAdvection.pdf │ ├── ErrorHelmholtz.pdf │ ├── ErrorMechanics.pdf │ ├── ErrorNavierStokes.pdf │ ├── InputAdvection.pdf │ ├── InputHelmoltz.pdf │ ├── InputNavierStokes.pdf │ ├── InputStructural.pdf │ ├── OutputAdvection.pdf │ ├── OutputHelmholtz.pdf │ ├── OutputNavierStokes.pdf │ ├── OutputStructuralMechanics.pdf │ ├── OverlayAdvection.pdf │ ├── OverlayAdvectionII.pdf │ ├── PredAdvection.pdf │ ├── PredictedHelmholtz.pdf │ ├── PredictedMechanics.pdf │ ├── PredictedNavierStokes.pdf │ ├── TestAdvection.pdf │ ├── True.pdf │ ├── TrueAdvection.pdf │ ├── TrueHelmholtz.pdf │ ├── TrueMechanics.pdf │ └── TrueNavierStokes.pdf ├── Helmholtz-Jax.ipynb ├── Helmholtz-JaxKernels-OutputPCAd-Copy1.ipynb ├── Helmholtz-JaxKernels.ipynb ├── Helmholtz.ipynb ├── Navier-Stokes-JaxKernels-Feature maps.ipynb ├── Navier-Stokes-JaxKernels-OutputPCAd.ipynb ├── Navier-Stokes-JaxKernels.ipynb ├── Navier-Stokes.ipynb ├── Plotting templates.ipynb ├── PredictedHH.pkl ├── PredictedNS.pkl ├── PredictedSM.pkl ├── Struc-JaxKernels-OutputPCAd.ipynb ├── Structural Mechanics-JaxKernels.ipynb ├── Structural Mechanics.ipynb ├── data │ ├── DeepONet_Adv.csv │ ├── DeepONet_Helmhotz.csv │ ├── DeepONet_NS.csv │ ├── DeepONet_Solid.csv │ ├── FNO_Adv.csv │ ├── FNO_Helmhotz.csv │ ├── FNO_NS.csv │ ├── FNO_Solid.csv │ ├── PARA_Adv.csv │ ├── PARA_Helmhotz.csv │ ├── PARA_NS.csv │ ├── PARA_Solid.csv │ ├── PCA_Adv.csv │ ├── PCA_Helmhotz.csv │ ├── PCA_NS.csv │ └── PCA_Solid.csv ├── helmpca95.npy ├── helmpca99Te.npy ├── helmpca99Tr.npy ├── perdAdvection.pkl ├── plot_style-Examples.txt ├── plot_style-coolwarm.txt ├── plot_style.txt ├── plots.tar.gz ├── plots_output │ ├── ErrorAdvection.pdf │ ├── ErrorHelmholtz.pdf │ ├── ErrorMechanics.pdf │ ├── ErrorNavierStokes.pdf │ ├── InputAdvection.pdf │ ├── InputHelmoltz.pdf │ ├── InputNavierStokes.pdf │ ├── InputStructural.pdf │ ├── OutputAdvection.pdf │ ├── OutputHelmholtz.pdf │ ├── OutputNavierStokes.pdf │ ├── OutputStructuralMechanics.pdf │ ├── OverlayAdvectionII.pdf │ ├── PredAdvection.pdf │ ├── PredictedHelmholtz.pdf │ ├── PredictedMechanics.pdf │ ├── PredictedNavierStokes.pdf │ ├── TrueAdvection.pdf │ ├── TrueHelmholtz.pdf │ ├── TrueMechanics.pdf │ └── TrueNavierStokes.pdf └── predAdvection.pkl ├── LowDataRegime ├── Advection equation I │ ├── .ipynb_checkpoints │ │ ├── Advection equation-checkpoint.ipynb │ │ ├── Plotting_templates - advection-checkpoint.ipynb │ │ └── Plotting_templates_v2-checkpoint.ipynb │ ├── Advection equation.ipynb │ ├── ErrorAdvection.pdf │ ├── InputAdvection.pdf │ ├── InputAdvection2.pdf │ ├── OutputAdvection.pdf │ ├── OverlayAdvection.pdf │ ├── Plotting_templates.ipynb │ ├── PredAdvection.pdf │ ├── PredictedAdvection.pdf │ ├── Readme.md │ ├── TrueAdvection.pdf │ └── plot_style-Examples.txt ├── Burger's equation │ ├── .ipynb_checkpoints │ │ ├── Cholesky and Bayesian optimization-checkpoint.ipynb │ │ ├── GP on burger - cholesky-checkpoint.ipynb │ │ ├── PCA + GP on Burger - 5 datasets-checkpoint.ipynb │ │ ├── PCA + GP on Burger -checkpoint.ipynb │ │ ├── Plotting_templates - burger-checkpoint.ipynb │ │ └── Plotting_templates_v2-checkpoint.ipynb │ ├── Choleksy.py │ ├── Choleksy_2.py │ ├── Choleksy_green.py │ ├── Cholesky and Bayesian optimization.ipynb │ ├── ErrorBurger.pdf │ ├── GP on burger - cholesky.ipynb │ ├── InputBurger.pdf │ ├── InputBurger2.pdf │ ├── OutputBurger.pdf │ ├── OutputBurger2.pdf │ ├── OverlaidBurger.pdf │ ├── PCA + GP on Burger - 5 datasets.ipynb │ ├── PCA + GP on Burger .ipynb │ ├── Plotting_templates.ipynb │ ├── PredBurger.pdf │ ├── Readme.md │ ├── TrueBurger.pdf │ ├── cholesky_bayesian.py │ └── plot_style-Examples.txt └── Darcy problem │ ├── .ipynb_checkpoints │ ├── Cholesky and Bayesian optimization-Copy1-checkpoint.ipynb │ ├── Cholesky and Bayesian optimization-Copy2-checkpoint.ipynb │ ├── Cholesky and Bayesian optimization-checkpoint.ipynb │ ├── Darcy problem - tuning individual lengthscales-checkpoint.ipynb │ ├── Darcy problem-checkpoint.ipynb │ ├── Plotting_templates - Darcy flow-checkpoint.ipynb │ └── Plotting_templates_v2-checkpoint.ipynb │ ├── Cholesky and Bayesian optimization-Copy1.ipynb │ ├── Cholesky and Bayesian optimization-Copy2.ipynb │ ├── Cholesky and Bayesian optimization.ipynb │ ├── Darcy problem - tuning individual lengthscales.ipynb │ ├── Darcy problem.ipynb │ ├── Darcy problem_old.ipynb │ ├── ErrorDarcy.pdf │ ├── InputDarcy.pdf │ ├── OutputDarcy.pdf │ ├── Plotting_templates.ipynb │ ├── PredictedDarcy.pdf │ ├── Readme.md │ ├── TrueDarcy.pdf │ ├── example_prediction.png │ ├── example_prediction2.png │ ├── example_prediction3.png │ ├── example_prediction4.png │ ├── example_prediction5.png │ ├── example_prediction_test.png │ ├── plot_style-Examples.txt │ ├── test_example.png │ └── training_example.png └── README.md /HighDataRegime/.ipynb_checkpoints/Advection-JaxKernels-OutputPCAd-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "import pandas as pd" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "1a79b907", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 40 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 41 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 42 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "6c5e4ba4", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "#The columns = [Nexamples, network width, Train, Test]" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "a989201f", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "Inputs = onp.load('data/Helmholtz_inputs.npy')\n", 63 | "Outputs = onp.load('data/Helmholtz_outputs.npy')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "id": "7d27a7a7", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "Inputs = Inputs.transpose((2,1,0))\n", 74 | "Outputs = Outputs.transpose((2,1,0))\n", 75 | "\n", 76 | "Inputs_fl = Inputs.reshape(len(Inputs), 101*101)\n", 77 | "Outputs_fl = Outputs.reshape(len(Outputs), 101*101)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "d5235802", 83 | "metadata": {}, 84 | "source": [ 85 | "GP regression" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 6, 91 | "id": "74327ec9", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 96 | " return np.sum( (x - y) ** 2)\n", 97 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 98 | "\n", 99 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 100 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 101 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 102 | "\n", 103 | "\n", 104 | "@jit\n", 105 | "def matern(v1, v2, sigma = 50):\n", 106 | " #V1 is a [k1] vector\n", 107 | " #V2 is a [k2] vector\n", 108 | " #returns a k1xk2 matrix\n", 109 | " d = sqdists(v1, v2)\n", 110 | " #return a*np.exp(-d**2/sigma)\n", 111 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 112 | "\n", 113 | "@jit\n", 114 | "def exp(v1, v2, sigma):\n", 115 | " #V1 is a [k1] vector\n", 116 | " #V2 is a [k2] vector\n", 117 | " #returns a k1xk2 matrix\n", 118 | " d = dists(v1, v2)\n", 119 | " return np.exp(-d/sigma)\n", 120 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 121 | "\n", 122 | "@jit\n", 123 | "def iq(v1, v2, sigma):\n", 124 | " #V1 is a [k1] vector\n", 125 | " #V2 is a [k2] vector\n", 126 | " #returns a k1xk2 matrix\n", 127 | " d = dists(v1, v2)\n", 128 | " #return a*np.exp(-d**2/sigma)\n", 129 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 130 | " return 1/np.sqrt(d+sigma)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 15, 136 | "id": "c53c7c21", 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "Ntrain = 10000" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 16, 146 | "id": "c5fb23e6", 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "Xtr = Inputs_fl[:Ntrain]\n", 151 | "pca_inp = PCA(n_components=200)\n", 152 | "Xtr = pca_inp.fit_transform(Xtr)\n", 153 | "Xtest = pca_inp.transform(Inputs_fl[20000:])\n", 154 | "\n", 155 | "Ytr = Outputs_fl[:Ntrain]\n", 156 | "pca_out = PCA(n_components=500)\n", 157 | "Ytr = pca_out.fit_transform(Ytr)\n", 158 | "Ytest = pca_out.transform(Outputs_fl[20000:])" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 17, 164 | "id": "5dc9353e", 165 | "metadata": { 166 | "scrolled": false 167 | }, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "1000 1e-12\n", 174 | "\n", 175 | " Train error (abs): 6.959614690085883e-09 \n", 176 | " Train error (rel): 1.7157951523708667e-08 \n", 177 | " Test error (PCA space, abs): 0.016747542524584408 \n", 178 | " Test error (PCA space, rel): 0.032924033460171226 \n", 179 | " Test error (Real space, abs): 0.01674755086003411 \n", 180 | " Test error (Real space, rel): 0.03292405210672207 \n", 181 | "---\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "for kernel in [iq]:\n", 187 | " for s in [1000]:\n", 188 | " for nugget in [1e-12]:\n", 189 | " k = kernel\n", 190 | " Kxx = k(Xtr, Xtr, s)\n", 191 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 192 | " L = cho_factor(nuggeted_matrix)\n", 193 | " result = cho_solve(L, Ytr)\n", 194 | " Train_pred = Kxx@result #train predictions\n", 195 | " K_te_tr = k(Xtest, Xtr,s)\n", 196 | " Test_pred = K_te_tr@result #test predictions\n", 197 | "\n", 198 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 199 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 200 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 201 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 202 | "\n", 203 | " true_pred = pca_out.inverse_transform(Test_pred)\n", 204 | " true_ytest = Outputs_fl[20000:]\n", 205 | "\n", 206 | " aux5 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1))\n", 207 | " aux6 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 208 | "\n", 209 | " print(s, nugget)\n", 210 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (PCA space, abs): {2} \\n Test error (PCA space, rel): {3} \\n Test error (Real space, abs): {4} \\n Test error (Real space, rel): {5} \".format(aux1, aux2, aux3, aux4, aux5, aux6))\n", 211 | " print('---')" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "id": "dc3b0fa4", 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [] 221 | } 222 | ], 223 | "metadata": { 224 | "kernelspec": { 225 | "display_name": "Python 3 (ipykernel)", 226 | "language": "python", 227 | "name": "python3" 228 | }, 229 | "language_info": { 230 | "codemirror_mode": { 231 | "name": "ipython", 232 | "version": 3 233 | }, 234 | "file_extension": ".py", 235 | "mimetype": "text/x-python", 236 | "name": "python", 237 | "nbconvert_exporter": "python", 238 | "pygments_lexer": "ipython3", 239 | "version": "3.10.4" 240 | } 241 | }, 242 | "nbformat": 4, 243 | "nbformat_minor": 5 244 | } 245 | -------------------------------------------------------------------------------- /HighDataRegime/.ipynb_checkpoints/Complexity accuracy Plot-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "6d843493", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import numpy as np\n", 11 | "import matplotlib.pyplot as plt\n", 12 | "import pandas as pd" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": null, 18 | "id": "fb5abdb6", 19 | "metadata": {}, 20 | "outputs": [], 21 | "source": [ 22 | "def cplx_linear(p, n, m):\n", 23 | " return min(2*m*n, (2*p-1)*n + (2*m-1)*p + m)" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": null, 29 | "id": "8203fedb", 30 | "metadata": {}, 31 | "outputs": [], 32 | "source": [ 33 | "def cplx_gp(m, N = 10000):\n", 34 | " return (2*N-1)*m + N" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": null, 40 | "id": "fe9149b4", 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [ 44 | "PCANetNS = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 45 | "DeepONetNS = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 46 | "ParaNS = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 47 | "FNONS = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()\n", 48 | "\n", 49 | "PCANetHH = pd.read_csv(\"data/PCA_Helmhotz.csv\", header = None).to_numpy()\n", 50 | "DeepONetHH = pd.read_csv(\"data/DeepONet_Helmhotz.csv\", header = None).to_numpy()\n", 51 | "ParaHH = pd.read_csv(\"data/PARA_Helmhotz.csv\", header = None).to_numpy()\n", 52 | "FNOHH = pd.read_csv(\"data/FNO_Helmhotz.csv\", header = None).to_numpy()\n", 53 | "\n", 54 | "PCANetSM = pd.read_csv(\"data/PCA_Solid.csv\", header = None).to_numpy()\n", 55 | "DeepONetSM = pd.read_csv(\"data/DeepONet_Solid.csv\", header = None).to_numpy()\n", 56 | "ParaSM = pd.read_csv(\"data/PARA_Solid.csv\", header = None).to_numpy()\n", 57 | "FNOSM = pd.read_csv(\"data/FNO_Solid.csv\", header = None).to_numpy()\n", 58 | "\n", 59 | "PCANetAD = pd.read_csv(\"data/PCA_Adv.csv\", header = None).to_numpy()\n", 60 | "DeepONetAD = pd.read_csv(\"data/DeepONet_Adv.csv\", header = None).to_numpy()\n", 61 | "ParaAD = pd.read_csv(\"data/PARA_Adv.csv\", header = None).to_numpy()\n", 62 | "FNOAD = pd.read_csv(\"data/FNO_Adv.csv\", header = None).to_numpy()" 63 | ] 64 | }, 65 | { 66 | "cell_type": "code", 67 | "execution_count": null, 68 | "id": "86f58946", 69 | "metadata": {}, 70 | "outputs": [], 71 | "source": [ 72 | "plt.style.use('plot_style-coolwarm.txt')\n", 73 | "\n", 74 | "fig, ax = plt.subplots(2,2, figsize = (10,8))\n", 75 | "#Navier Stokes\n", 76 | "\n", 77 | "\n", 78 | "ax[0,0].set_title(r'Navier Stokes', loc = 'center')\n", 79 | "ax[0,0].plot(PCANetNS[PCANetNS[:,0] == 10000][:,2], PCANetNS[PCANetNS[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 80 | "ax[0,0].plot(DeepONetNS[DeepONetNS[:,0] == 10000][:,2], DeepONetNS[DeepONetNS[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 81 | "ax[0,0].plot(ParaNS[ParaNS[:,0] == 10000][:4,2], ParaNS[ParaNS[:,0] == 10000][:4, 4], '-h', label = 'Para')\n", 82 | "ax[0,0].plot(FNONS[FNONS[:,0] == 10000][:,2], FNONS[FNONS[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 83 | "resultspca = [[8, 0.5086471004988675],\n", 84 | " [16, 0.32902767742497485],\n", 85 | " [32, 0.1417764805416794],\n", 86 | " [64, 0.06491252235537232],\n", 87 | " [128, 0.05433896061902034],\n", 88 | " [256, 0.054339492288471514],\n", 89 | " [512, 0.05433913950959782]]\n", 90 | "\n", 91 | "# resultsRF = [[100.0, 0.16383867940666916],\n", 92 | "# [500.0, 0.03541254226505244],\n", 93 | "# [1000.0, 0.023207984180962718],\n", 94 | "# [2000.0, 0.01357973704163874],\n", 95 | "# [4000.0, 0.007802352160094999],\n", 96 | "# [8000.0, 0.005128712798623048],\n", 97 | "# [16000.0, 0.004917405952514918]]\n", 98 | "\n", 99 | "# ax[0,0].plot([cplx_linear(i, 64*64,64*64) for i in [j[0] for j in resultsRF]], [i[1] for i in resultsRF], '-s', label = 'Linear + PCA')\n", 100 | "\n", 101 | "\n", 102 | "ax[0,0].set_xscale('log')\n", 103 | "ax[0,0].set_yscale('log')\n", 104 | "ax[0,0].plot([cplx_linear(i, 64*64,64*64) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear + PCA')\n", 105 | "ax[0,0].scatter([cplx_gp(64*64)], [0.0012], color = 'black', marker ='D', label = 'GP')\n", 106 | "\n", 107 | "\n", 108 | "\n", 109 | "#Helmholtz\n", 110 | "\n", 111 | "\n", 112 | "ax[0,1].set_title(r'Helmholtz', loc = 'center')\n", 113 | "ax[0,1].plot(PCANetHH[PCANetHH[:,0] == 10000][:,2], PCANetHH[PCANetHH[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 114 | "ax[0,1].plot(DeepONetHH[DeepONetHH[:,0] == 10000][:,2], DeepONetHH[DeepONetHH[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 115 | "ax[0,1].plot(ParaHH[ParaHH[:,0] == 10000][:4,2], ParaHH[ParaHH[:,0] == 10000][:4, 4], '-h', label = 'Para')\n", 116 | "ax[0,1].plot(FNOHH[FNOHH[:,0] == 10000][:,2], FNOHH[FNOHH[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 117 | "ax[0,1].set_xscale('log')\n", 118 | "ax[0,1].set_yscale('log')\n", 119 | "resultspca = [[8, 0.14960297462671757],\n", 120 | " [16, 0.13260202963830026],\n", 121 | " [32, 0.1140852985756796],\n", 122 | " [64, 0.10946473627559893],\n", 123 | " [128, 0.10592485656461126],\n", 124 | " [256, 0.10669036765776628]]\n", 125 | "ax[0,1].plot([cplx_linear(i, 101*101,101*101) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear')\n", 126 | "ax[0,1].scatter([cplx_gp(101*101)], [0.010], marker ='D', color = 'black', label = 'GP')\n", 127 | "\n", 128 | "\n", 129 | "#Structural Mechanics\n", 130 | "\n", 131 | "\n", 132 | "ax[1,0].set_title(r'Structural Mechanics', loc = 'center')\n", 133 | "ax[1,0].plot(PCANetSM[PCANetSM[:,0] == 10000][:,2], PCANetSM[PCANetSM[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 134 | "ax[1,0].plot(DeepONetSM[DeepONetSM[:,0] == 10000][:,2], DeepONetSM[DeepONetSM[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 135 | "ax[1,0].plot(ParaSM[ParaSM[:,0] == 10000][:,2], ParaSM[ParaSM[:,0] == 10000][:, 4], '-h', label = 'Para')\n", 136 | "ax[1,0].plot(FNOSM[FNOSM[:,0] == 10000][:,2], FNOSM[FNOSM[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 137 | "ax[1,0].set_xscale('log')\n", 138 | "ax[1,0].set_yscale('log')\n", 139 | "\n", 140 | "resultspca = [[5, 0.2765221088188129],\n", 141 | " [10, 0.2734173270367],\n", 142 | " [20, 0.27266866934847744],\n", 143 | " [40, 0.2723498953506888]]\n", 144 | "ax[1,0].plot([cplx_linear(i, 41, 41*41) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear')\n", 145 | "ax[1,0].scatter([cplx_gp(41*41)], [0.054], marker ='D', color = 'black', label = 'GP')\n", 146 | "\n", 147 | "#Advection\n", 148 | "\n", 149 | "\n", 150 | "ax[1,1].set_title(r'Advection', loc = 'center')\n", 151 | "ax[1,1].plot(PCANetAD[PCANetAD[:,0] == 10000][:,2], PCANetAD[PCANetAD[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 152 | "ax[1,1].plot(DeepONetAD[DeepONetAD[:,0] == 10000][:,2], DeepONetAD[DeepONetAD[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 153 | "ax[1,1].plot(ParaAD[ParaAD[:,0] == 10000][:,2], ParaAD[ParaAD[:,0] == 10000][:, 4], '-h', label = 'ParaNet')\n", 154 | "ax[1,1].plot(FNOAD[FNOAD[:,0] == 10000][:,2], FNOAD[FNOAD[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 155 | "\n", 156 | "#From other notebook\n", 157 | "resultspca = [[16, 0.2539750558073611],\n", 158 | " [32, 0.18283896775861255],\n", 159 | " [64, 0.1371020695289114],\n", 160 | " [128, 0.11594513618759306],\n", 161 | " [200, 0.11341718064240679]]\n", 162 | "\n", 163 | "ax[1,1].plot([cplx_linear(i, 200, 200) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear')\n", 164 | "ax[1,1].scatter([cplx_gp(200)], [0.11639013233030239], color = 'black', marker ='D', label = 'Vanilla GP')\n", 165 | "\n", 166 | "ax[1,1].set_xscale('log')\n", 167 | "ax[1,1].set_yscale('log')\n", 168 | "\n", 169 | "lines_labels = [ax[1,1].get_legend_handles_labels()]\n", 170 | "lines, labels = [sum(lol, []) for lol in zip(*lines_labels)]\n", 171 | "fig.supxlabel(r'Complexity (flops)')\n", 172 | "fig.supylabel(r'Test error')\n", 173 | "ttl = fig.suptitle(r'Accuracy complexity trade-off')\n", 174 | "plt.tight_layout()\n", 175 | "lgd = fig.legend(lines, labels, loc='upper center', bbox_to_anchor = (0.5,0,0,0), ncol=6)\n", 176 | "#plt.savefig('AccuracyComplexity.pdf', dpi = 500, bbox_inches = 'tight')#bbox_extra_artists=(lgd,)," 177 | ] 178 | }, 179 | { 180 | "cell_type": "code", 181 | "execution_count": null, 182 | "id": "240c955c", 183 | "metadata": {}, 184 | "outputs": [], 185 | "source": [ 186 | "def cplx_gp_pca(n, m, p_in, p_out, N = 10000):\n", 187 | " return (2*p_in-1)*n + (2*N-1)*p_out + (2*m-1)*p_out + N*p_in\n", 188 | "\n", 189 | "\n", 190 | "def cplx_gp_pca2(n, m, p_out, N = 10000):\n", 191 | " return (2*N-1)*p_out + (2*m-1)*p_out + N*n" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": null, 197 | "id": "684a1b05", 198 | "metadata": {}, 199 | "outputs": [], 200 | "source": [ 201 | "plt.style.use('plot_style-coolwarm.txt')\n", 202 | "\n", 203 | "fig, ax = plt.subplots(2,2, figsize = (10,8))\n", 204 | "#Navier Stokes\n", 205 | "\n", 206 | "\n", 207 | "ax[0,0].set_title(r'Navier Stokes', loc = 'center')\n", 208 | "ax[0,0].plot(PCANetNS[PCANetNS[:,0] == 10000][:,2], PCANetNS[PCANetNS[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 209 | "ax[0,0].plot(DeepONetNS[DeepONetNS[:,0] == 10000][:,2], DeepONetNS[DeepONetNS[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 210 | "ax[0,0].plot(ParaNS[ParaNS[:,0] == 10000][:4,2], ParaNS[ParaNS[:,0] == 10000][:4, 4], '-h', label = 'Para')\n", 211 | "ax[0,0].plot(FNONS[FNONS[:,0] == 10000][:,2], FNONS[FNONS[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 212 | "resultspca = [[8, 0.5086471004988675],\n", 213 | " [16, 0.32902767742497485],\n", 214 | " [32, 0.1417764805416794],\n", 215 | " [64, 0.06491252235537232],\n", 216 | " [128, 0.05433896061902034],\n", 217 | " [256, 0.054339492288471514],\n", 218 | " [512, 0.05433913950959782]]\n", 219 | "\n", 220 | "ax[0,0].set_xscale('log')\n", 221 | "ax[0,0].set_yscale('log')\n", 222 | "ax[0,0].plot([cplx_linear(i, 64*64,64*64) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear + PCA')\n", 223 | "ax[0,0].scatter([cplx_gp(64*64)], [0.0012], color = 'black', marker ='D', label = 'GP')\n", 224 | "ax[0,0].scatter([cplx_gp_pca(n=64*64, m = 64*64, p_in = 128, p_out = 128, N=20000)], [0.0012], color = 'darkblue', marker ='D', label = 'GP20k')\n", 225 | "\n", 226 | "\n", 227 | "\n", 228 | "#Helmholtz\n", 229 | "\n", 230 | "\n", 231 | "ax[0,1].set_title(r'Helmholtz', loc = 'center')\n", 232 | "ax[0,1].plot(PCANetHH[PCANetHH[:,0] == 10000][:,2], PCANetHH[PCANetHH[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 233 | "ax[0,1].plot(DeepONetHH[DeepONetHH[:,0] == 10000][:,2], DeepONetHH[DeepONetHH[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 234 | "ax[0,1].plot(ParaHH[ParaHH[:,0] == 10000][:4,2], ParaHH[ParaHH[:,0] == 10000][:4, 4], '-h', label = 'Para')\n", 235 | "ax[0,1].plot(FNOHH[FNOHH[:,0] == 10000][:,2], FNOHH[FNOHH[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 236 | "ax[0,1].set_xscale('log')\n", 237 | "ax[0,1].set_yscale('log')\n", 238 | "resultspca = [[8, 0.14960297462671757],\n", 239 | " [16, 0.13260202963830026],\n", 240 | " [32, 0.1140852985756796],\n", 241 | " [64, 0.10946473627559893],\n", 242 | " [128, 0.10592485656461126],\n", 243 | " [256, 0.10669036765776628]]\n", 244 | "\n", 245 | "ax[0,1].plot([cplx_linear(i, 101*101,101*101) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear')\n", 246 | "ax[0,1].scatter([cplx_gp(101*101)], [0.010], marker ='D', color = 'black', label = 'GP')\n", 247 | "ax[0,1].scatter([cplx_gp_pca(n=101*101, m = 101*101, p_in = 200, p_out = 300, N = 10000)], [0.024], marker ='D', color = 'darkblue', label = 'GP')\n", 248 | "\n", 249 | "#ax[0,1].scatter([cplx_gp_pca(n=101*101, m = 101*101, p_in = 200, p_out = 500)], [0.024], marker ='D', color = 'darkblue', label = 'GP')\n", 250 | "\n", 251 | "\n", 252 | "#Structural Mechanics\n", 253 | "\n", 254 | "\n", 255 | "ax[1,0].set_title(r'Structural Mechanics', loc = 'center')\n", 256 | "ax[1,0].plot(PCANetSM[PCANetSM[:,0] == 10000][:,2], PCANetSM[PCANetSM[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 257 | "ax[1,0].plot(DeepONetSM[DeepONetSM[:,0] == 10000][:,2], DeepONetSM[DeepONetSM[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 258 | "ax[1,0].plot(ParaSM[ParaSM[:,0] == 10000][:,2], ParaSM[ParaSM[:,0] == 10000][:, 4], '-h', label = 'Para')\n", 259 | "ax[1,0].plot(FNOSM[FNOSM[:,0] == 10000][:,2], FNOSM[FNOSM[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 260 | "ax[1,0].set_xscale('log')\n", 261 | "ax[1,0].set_yscale('log')\n", 262 | "\n", 263 | "resultspca = [[5, 0.2765221088188129],\n", 264 | " [10, 0.2734173270367],\n", 265 | " [20, 0.27266866934847744],\n", 266 | " [40, 0.2723498953506888]]\n", 267 | "ax[1,0].plot([cplx_linear(i, 41, 41*41) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear')\n", 268 | "ax[1,0].scatter([cplx_gp(41*41)], [0.054], marker ='D', color = 'black', label = 'GP')\n", 269 | "ax[1,0].scatter([cplx_gp_pca2(n=41, m = 41*41, p_out = 200, N = 10000)], [0.11], marker ='D', color = 'darkblue', label = 'GP')\n", 270 | "\n", 271 | "#Advection\n", 272 | "\n", 273 | "\n", 274 | "ax[1,1].set_title(r'Advection', loc = 'center')\n", 275 | "ax[1,1].plot(PCANetAD[PCANetAD[:,0] == 10000][:,2], PCANetAD[PCANetAD[:,0] == 10000][:, 4], '-*', label = 'PCANet')\n", 276 | "ax[1,1].plot(DeepONetAD[DeepONetAD[:,0] == 10000][:,2], DeepONetAD[DeepONetAD[:,0] == 10000][:, 4], '-p', label = 'DeepONet')\n", 277 | "ax[1,1].plot(ParaAD[ParaAD[:,0] == 10000][:,2], ParaAD[ParaAD[:,0] == 10000][:, 4], '-h', label = 'ParaNet')\n", 278 | "ax[1,1].plot(FNOAD[FNOAD[:,0] == 10000][:,2], FNOAD[FNOAD[:,0] == 10000][:, 4], '-X', label = 'FNO')\n", 279 | "\n", 280 | "#From other notebook\n", 281 | "resultspca = [[16, 0.2539750558073611],\n", 282 | " [32, 0.18283896775861255],\n", 283 | " [64, 0.1371020695289114],\n", 284 | " [128, 0.11594513618759306],\n", 285 | " [200, 0.11341718064240679]]\n", 286 | "\n", 287 | "ax[1,1].plot([cplx_linear(i, 200, 200) for i in [j[0] for j in resultspca]], [i[1] for i in resultspca], '-s', label = 'Linear')\n", 288 | "ax[1,1].scatter([cplx_gp(200)], [0.11639013233030239], color = 'black', marker ='D', label = 'Vanilla GP')\n", 289 | "ax[1,1].scatter([cplx_gp_pca2(n = 200, m = 200, p_out = 100, N = 10000)], [0.15], color = 'darkblue', marker ='D', label = 'GP + PCA')\n", 290 | "\n", 291 | "ax[1,1].set_xscale('log')\n", 292 | "ax[1,1].set_yscale('log')\n", 293 | "\n", 294 | "lines_labels = [ax[1,1].get_legend_handles_labels()]\n", 295 | "lines, labels = [sum(lol, []) for lol in zip(*lines_labels)]\n", 296 | "fig.supxlabel(r'Complexity (flops)')\n", 297 | "fig.supylabel(r'Test error')\n", 298 | "ttl = fig.suptitle(r'Accuracy complexity trade-off')\n", 299 | "plt.tight_layout()\n", 300 | "lgd = fig.legend(lines, labels, loc='upper center', bbox_to_anchor = (0.5,0,0,0), ncol=7)\n", 301 | "#plt.savefig('AccuracyComplexity.pdf', dpi = 500, bbox_inches = 'tight')#bbox_extra_artists=(lgd,)," 302 | ] 303 | }, 304 | { 305 | "cell_type": "code", 306 | "execution_count": null, 307 | "id": "3e17cc3e", 308 | "metadata": {}, 309 | "outputs": [], 310 | "source": [] 311 | }, 312 | { 313 | "cell_type": "code", 314 | "execution_count": null, 315 | "id": "e108ecfa", 316 | "metadata": {}, 317 | "outputs": [], 318 | "source": [] 319 | } 320 | ], 321 | "metadata": { 322 | "kernelspec": { 323 | "display_name": "Python 3 (ipykernel)", 324 | "language": "python", 325 | "name": "python3" 326 | }, 327 | "language_info": { 328 | "codemirror_mode": { 329 | "name": "ipython", 330 | "version": 3 331 | }, 332 | "file_extension": ".py", 333 | "mimetype": "text/x-python", 334 | "name": "python", 335 | "nbconvert_exporter": "python", 336 | "pygments_lexer": "ipython3", 337 | "version": "3.10.4" 338 | } 339 | }, 340 | "nbformat": 4, 341 | "nbformat_minor": 5 342 | } 343 | -------------------------------------------------------------------------------- /HighDataRegime/.ipynb_checkpoints/Helmholtz-JaxKernels-OutputPCAd-Copy1-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "import pandas as pd" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "1a79b907", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 40 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 41 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 42 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "6c5e4ba4", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "#The columns = [Nexamples, network width, Train, Test]" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "a989201f", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "Inputs = onp.load('data/Helmholtz_inputs.npy')\n", 63 | "Outputs = onp.load('data/Helmholtz_outputs.npy')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "id": "7d27a7a7", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "Inputs = Inputs.transpose((2,1,0))\n", 74 | "Outputs = Outputs.transpose((2,1,0))\n", 75 | "\n", 76 | "Inputs_fl = Inputs.reshape(len(Inputs), 101*101)\n", 77 | "Outputs_fl = Outputs.reshape(len(Outputs), 101*101)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "d5235802", 83 | "metadata": {}, 84 | "source": [ 85 | "GP regression" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 6, 91 | "id": "74327ec9", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 96 | " return np.sum( (x - y) ** 2)\n", 97 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 98 | "\n", 99 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 100 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 101 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 102 | "\n", 103 | "\n", 104 | "@jit\n", 105 | "def matern(v1, v2, sigma = 50):\n", 106 | " #V1 is a [k1] vector\n", 107 | " #V2 is a [k2] vector\n", 108 | " #returns a k1xk2 matrix\n", 109 | " d = sqdists(v1, v2)\n", 110 | " #return a*np.exp(-d**2/sigma)\n", 111 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 112 | "\n", 113 | "@jit\n", 114 | "def exp(v1, v2, sigma):\n", 115 | " #V1 is a [k1] vector\n", 116 | " #V2 is a [k2] vector\n", 117 | " #returns a k1xk2 matrix\n", 118 | " d = dists(v1, v2)\n", 119 | " return np.exp(-d/sigma)\n", 120 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 121 | "\n", 122 | "@jit\n", 123 | "def iq(v1, v2, sigma):\n", 124 | " #V1 is a [k1] vector\n", 125 | " #V2 is a [k2] vector\n", 126 | " #returns a k1xk2 matrix\n", 127 | " d = dists(v1, v2)\n", 128 | " #return a*np.exp(-d**2/sigma)\n", 129 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 130 | " return 1/np.sqrt(d+sigma)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 15, 136 | "id": "c53c7c21", 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "Ntrain = 10000" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 16, 146 | "id": "c5fb23e6", 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "Xtr = Inputs_fl[:Ntrain]\n", 151 | "pca_inp = PCA(n_components=200)\n", 152 | "Xtr = pca_inp.fit_transform(Xtr)\n", 153 | "Xtest = pca_inp.transform(Inputs_fl[20000:])\n", 154 | "\n", 155 | "Ytr = Outputs_fl[:Ntrain]\n", 156 | "pca_out = PCA(n_components=500)\n", 157 | "Ytr = pca_out.fit_transform(Ytr)\n", 158 | "Ytest = pca_out.transform(Outputs_fl[20000:])" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 17, 164 | "id": "5dc9353e", 165 | "metadata": { 166 | "scrolled": false 167 | }, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "1000 1e-12\n", 174 | "\n", 175 | " Train error (abs): 6.959614690085883e-09 \n", 176 | " Train error (rel): 1.7157951523708667e-08 \n", 177 | " Test error (PCA space, abs): 0.016747542524584408 \n", 178 | " Test error (PCA space, rel): 0.032924033460171226 \n", 179 | " Test error (Real space, abs): 0.01674755086003411 \n", 180 | " Test error (Real space, rel): 0.03292405210672207 \n", 181 | "---\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "for kernel in [iq]:\n", 187 | " for s in [1000]:\n", 188 | " for nugget in [1e-12]:\n", 189 | " k = kernel\n", 190 | " Kxx = k(Xtr, Xtr, s)\n", 191 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 192 | " L = cho_factor(nuggeted_matrix)\n", 193 | " result = cho_solve(L, Ytr)\n", 194 | " Train_pred = Kxx@result #train predictions\n", 195 | " K_te_tr = k(Xtest, Xtr,s)\n", 196 | " Test_pred = K_te_tr@result #test predictions\n", 197 | "\n", 198 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 199 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 200 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 201 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 202 | "\n", 203 | " true_pred = pca_out.inverse_transform(Test_pred)\n", 204 | " true_ytest = Outputs_fl[20000:]\n", 205 | "\n", 206 | " aux5 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1))\n", 207 | " aux6 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 208 | "\n", 209 | " print(s, nugget)\n", 210 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (PCA space, abs): {2} \\n Test error (PCA space, rel): {3} \\n Test error (Real space, abs): {4} \\n Test error (Real space, rel): {5} \".format(aux1, aux2, aux3, aux4, aux5, aux6))\n", 211 | " print('---')" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "id": "dc3b0fa4", 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [] 221 | } 222 | ], 223 | "metadata": { 224 | "kernelspec": { 225 | "display_name": "Python 3 (ipykernel)", 226 | "language": "python", 227 | "name": "python3" 228 | }, 229 | "language_info": { 230 | "codemirror_mode": { 231 | "name": "ipython", 232 | "version": 3 233 | }, 234 | "file_extension": ".py", 235 | "mimetype": "text/x-python", 236 | "name": "python", 237 | "nbconvert_exporter": "python", 238 | "pygments_lexer": "ipython3", 239 | "version": "3.10.4" 240 | } 241 | }, 242 | "nbformat": 4, 243 | "nbformat_minor": 5 244 | } 245 | -------------------------------------------------------------------------------- /HighDataRegime/.ipynb_checkpoints/Navier-Stokes-JaxKernels-OutputPCAd-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "import pandas as pd" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "1a79b907", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 40 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 41 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 42 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "6c5e4ba4", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "#The columns = [Nexamples, network width, Train, Test]" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "a989201f", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "Inputs = onp.load('data/NavierStokes_inputs.npy')\n", 63 | "Outputs = onp.load('data/NavierStokes_outputs.npy')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "id": "7d27a7a7", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "Inputs = Inputs.transpose((2,1,0))\n", 74 | "Outputs = Outputs.transpose((2,1,0))\n", 75 | "\n", 76 | "Inputs_fl = Inputs.reshape(len(Inputs), 64*64)\n", 77 | "Outputs_fl = Outputs.reshape(len(Outputs), 64*64)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "d5235802", 83 | "metadata": {}, 84 | "source": [ 85 | "GP regression" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 6, 91 | "id": "74327ec9", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 96 | " return np.sum( (x - y) ** 2)\n", 97 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 98 | "\n", 99 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 100 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 101 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 102 | "\n", 103 | "\n", 104 | "@jit\n", 105 | "def matern(v1, v2, sigma = 50):\n", 106 | " #V1 is a [k1] vector\n", 107 | " #V2 is a [k2] vector\n", 108 | " #returns a k1xk2 matrix\n", 109 | " d = sqdists(v1, v2)\n", 110 | " #return a*np.exp(-d**2/sigma)\n", 111 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 112 | "\n", 113 | "@jit\n", 114 | "def exp(v1, v2, sigma):\n", 115 | " #V1 is a [k1] vector\n", 116 | " #V2 is a [k2] vector\n", 117 | " #returns a k1xk2 matrix\n", 118 | " d = dists(v1, v2)\n", 119 | " return np.exp(-d/sigma)\n", 120 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 121 | "\n", 122 | "@jit\n", 123 | "def iq(v1, v2, sigma):\n", 124 | " #V1 is a [k1] vector\n", 125 | " #V2 is a [k2] vector\n", 126 | " #returns a k1xk2 matrix\n", 127 | " d = dists(v1, v2)\n", 128 | " #return a*np.exp(-d**2/sigma)\n", 129 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 130 | " return 1/np.sqrt(d+sigma)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 20, 136 | "id": "c53c7c21", 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "Ntrain = 10000\n" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 21, 146 | "id": "c5fb23e6", 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "128\n" 154 | ] 155 | } 156 | ], 157 | "source": [ 158 | "print(ncomp)\n", 159 | "Xtr = Inputs_fl[:Ntrain]\n", 160 | "pca_inp = PCA(n_components=128)\n", 161 | "Xtr = pca_inp.fit_transform(Xtr)\n", 162 | "Xtest = pca_inp.transform(Inputs_fl[20000:])\n", 163 | "\n", 164 | "Ytr = Outputs_fl[:Ntrain]\n", 165 | "pca_out = PCA(n_components=128)\n", 166 | "Ytr = pca_out.fit_transform(Ytr)\n", 167 | "Ytest = pca_out.transform(Outputs_fl[20000:])\n" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 22, 173 | "id": "5dc9353e", 174 | "metadata": { 175 | "scrolled": false 176 | }, 177 | "outputs": [ 178 | { 179 | "name": "stdout", 180 | "output_type": "stream", 181 | "text": [ 182 | "10 1e-12\n", 183 | "\n", 184 | " Train error (abs): 6.425398231654291e-09 \n", 185 | " Train error (rel): 2.7146044992801137e-09 \n", 186 | " Test error (PCA space, abs): 0.006521107888810295 \n", 187 | " Test error (PCA space, rel): 0.0025367140024987133 \n", 188 | " Test error (Real space, abs): 0.006648690663249997 \n", 189 | " Test error (Real space, rel): 0.0025890687838295763 \n", 190 | "---\n" 191 | ] 192 | } 193 | ], 194 | "source": [ 195 | "for kernel in [iq]:\n", 196 | " for s in [10]:\n", 197 | " for nugget in [1e-12]:\n", 198 | " k = kernel\n", 199 | " Kxx = k(Xtr, Xtr, s)\n", 200 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 201 | " L = cho_factor(nuggeted_matrix)\n", 202 | " result = cho_solve(L, Ytr)\n", 203 | " Train_pred = Kxx@result #train predictions\n", 204 | " K_te_tr = k(Xtest, Xtr,s)\n", 205 | " Test_pred = K_te_tr@result #test predictions\n", 206 | "\n", 207 | " np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 208 | "\n", 209 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 210 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 211 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 212 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 213 | "\n", 214 | " true_pred = pca_out.inverse_transform(Test_pred)\n", 215 | " true_ytest = Outputs_fl[20000:]\n", 216 | "\n", 217 | " aux5 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1))\n", 218 | " aux6 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 219 | "\n", 220 | " print(s, nugget)\n", 221 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (PCA space, abs): {2} \\n Test error (PCA space, rel): {3} \\n Test error (Real space, abs): {4} \\n Test error (Real space, rel): {5} \".format(aux1, aux2, aux3, aux4, aux5, aux6))\n", 222 | " print('---')" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": null, 228 | "id": "35530bd5", 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "#Jax regression" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": null, 238 | "id": "5eeda8a0", 239 | "metadata": {}, 240 | "outputs": [], 241 | "source": [] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": null, 246 | "id": "d97489e4", 247 | "metadata": {}, 248 | "outputs": [], 249 | "source": [] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": null, 254 | "id": "4ec629f8", 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "true_pred.shapea" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": null, 264 | "id": "5b3c7ee8", 265 | "metadata": {}, 266 | "outputs": [], 267 | "source": [] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": null, 272 | "id": "92942cd1", 273 | "metadata": {}, 274 | "outputs": [], 275 | "source": [ 276 | "import pickle" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": null, 282 | "id": "c5d91382", 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [ 286 | "pickle.dump(obj=[Ytest[42], Test_pred[42]], file = open('PredictedNS.pkl', 'wb'))" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "id": "d148ef50", 293 | "metadata": { 294 | "scrolled": false 295 | }, 296 | "outputs": [], 297 | "source": [] 298 | } 299 | ], 300 | "metadata": { 301 | "kernelspec": { 302 | "display_name": "Python 3 (ipykernel)", 303 | "language": "python", 304 | "name": "python3" 305 | }, 306 | "language_info": { 307 | "codemirror_mode": { 308 | "name": "ipython", 309 | "version": 3 310 | }, 311 | "file_extension": ".py", 312 | "mimetype": "text/x-python", 313 | "name": "python", 314 | "nbconvert_exporter": "python", 315 | "pygments_lexer": "ipython3", 316 | "version": "3.10.4" 317 | } 318 | }, 319 | "nbformat": 4, 320 | "nbformat_minor": 5 321 | } 322 | -------------------------------------------------------------------------------- /HighDataRegime/.ipynb_checkpoints/Navier-Stokes-JaxKernels-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "\n", 30 | "import pandas as pd" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "id": "100fc64e", 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "import pandas as pd" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "id": "1a79b907", 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 51 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 52 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 53 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 4, 59 | "id": "4bf4febc", 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "data": { 64 | "text/plain": [ 65 | "(DeviceArray(0.02654266, dtype=float64),\n", 66 | " DeviceArray(0.00259586, dtype=float64),\n", 67 | " DeviceArray(0.03629472, dtype=float64),\n", 68 | " DeviceArray(0.04088747, dtype=float64))" 69 | ] 70 | }, 71 | "execution_count": 4, 72 | "metadata": {}, 73 | "output_type": "execute_result" 74 | } 75 | ], 76 | "source": [ 77 | "np.min(PCANet[:,4]), np.min(FNO[:,4]), np.min(DeepONet[:, 4]), np.min(Para[:, 4])" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 5, 83 | "id": "6c5e4ba4", 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "#The columns = [Nexamples, network width, Train, Test]" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 6, 93 | "id": "a989201f", 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "Inputs = np.load('data/NavierStokes_inputs.npy')\n", 98 | "Outputs = np.load('data/NavierStokes_outputs.npy')" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 7, 104 | "id": "2f967df0", 105 | "metadata": { 106 | "scrolled": true 107 | }, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "(64, 64, 40000)" 113 | ] 114 | }, 115 | "execution_count": 7, 116 | "metadata": {}, 117 | "output_type": "execute_result" 118 | } 119 | ], 120 | "source": [ 121 | "Inputs.shape" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 8, 127 | "id": "7d27a7a7", 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "Inputs = Inputs.transpose((2,1,0))\n", 132 | "Outputs = Outputs.transpose((2,1,0))\n", 133 | "\n", 134 | "Inputs_fl = Inputs.reshape(len(Inputs), 64*64)\n", 135 | "Outputs_fl = Outputs.reshape(len(Outputs), 64*64)" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "id": "e74c76d7", 141 | "metadata": {}, 142 | "source": [ 143 | "Linear regression" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 9, 149 | "id": "4c430294", 150 | "metadata": { 151 | "scrolled": false 152 | }, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "20000 128\n", 159 | "0.053725325383721885 0.054129107629736904\n", 160 | "20000 256\n", 161 | "0.053724771853986414 0.0541287837480367\n", 162 | "20000 512\n", 163 | "0.053725442394692256 0.054128941233027035\n", 164 | "20000 1024\n", 165 | "0.05372536128518232 0.0541288361220119\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "results = []\n", 171 | "for Ntrain in [20000]:\n", 172 | " for N_components in [128, 256, 512, 1024]:\n", 173 | " print(Ntrain, N_components)\n", 174 | " Ytr = Outputs_fl[:Ntrain]\n", 175 | " Xtr = Inputs_fl[:Ntrain]\n", 176 | " pca = PCA(n_components=min(N_components,Ntrain))\n", 177 | " Xtr = pca.fit_transform(Xtr)\n", 178 | " reg = LinearRegression(n_jobs = -1).fit(Xtr, Ytr)\n", 179 | " #Ypred Ypredtr = reg.predict(Xtr)\n", 180 | " Ypredtr = reg.predict(Xtr)\n", 181 | " train_error = np.mean(np.linalg.norm(Ypredtr-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 182 | " Xtest = Inputs_fl[20000:]\n", 183 | " Ytest = Outputs_fl[20000:]\n", 184 | " Xtest = pca.transform(Xtest)\n", 185 | " Ypred = reg.predict(Xtest)\n", 186 | " test_error = np.mean(np.linalg.norm(Ypred-Ytest, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 187 | " print(train_error, test_error)\n", 188 | " results.append([Ntrain, N_components, train_error, test_error])\n", 189 | "\n", 190 | "results = np.array(results)" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "id": "d5235802", 196 | "metadata": {}, 197 | "source": [ 198 | "GP regression" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 10, 204 | "id": "eecfb3f4", 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "# from sklearn.gaussian_process import GaussianProcessRegressor\n", 209 | "# from sklearn.gaussian_process.kernels import Matern, RBF, RationalQuadratic\n", 210 | "\n", 211 | "# kernel = Matern(nu = 2.5)\n", 212 | "\n", 213 | "# Xtr.shape\n", 214 | "\n", 215 | "# resultsgp = []\n", 216 | "# for Ntrain in [156, 312, 624, 1250, 2500]:\n", 217 | "# print(Ntrain)\n", 218 | "# Ytr = Outputs_fl[:Ntrain]\n", 219 | "# Xtr = Inputs_fl[:Ntrain]\n", 220 | "# pca = PCA(n_components=128)\n", 221 | "# Xtr = pca.fit_transform(Xtr)\n", 222 | " \n", 223 | "# model = GaussianProcessRegressor(kernel, alpha = 1e-10)\n", 224 | "# model.fit(Xtr, Ytr)\n", 225 | "# #Ypred Ypredtr = reg.predict(Xtr)\n", 226 | "# Ypredtr = model.predict(Xtr)\n", 227 | "# train_error = np.mean(np.linalg.norm(Ypredtr-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 228 | "# Xtest = Inputs_fl[20000:]\n", 229 | "# Ytest = Outputs_fl[20000:]\n", 230 | "# Xtest = pca.transform(Xtest)\n", 231 | "# Ypred= model.predict(Xtest)\n", 232 | "# test_error = np.mean(np.linalg.norm(Ypred-Ytest, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 233 | "# print(train_error, test_error)\n", 234 | "# resultsgp.append([Ntrain, train_error, test_error])" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 11, 240 | "id": "35530bd5", 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [ 244 | "#Jax regression" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": 12, 250 | "id": "74327ec9", 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [ 254 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 255 | " return np.sum( (x - y) ** 2)\n", 256 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 257 | "\n", 258 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 259 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 260 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 261 | "\n", 262 | "\n", 263 | "@jit\n", 264 | "def matern(v1, v2, sigma = 50):\n", 265 | " #V1 is a [k1] vector\n", 266 | " #V2 is a [k2] vector\n", 267 | " #returns a k1xk2 matrix\n", 268 | " d = sqdists(v1, v2)\n", 269 | " #return a*np.exp(-d**2/sigma)\n", 270 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 271 | "\n", 272 | "@jit\n", 273 | "def exp(v1, v2, sigma):\n", 274 | " #V1 is a [k1] vector\n", 275 | " #V2 is a [k2] vector\n", 276 | " #returns a k1xk2 matrix\n", 277 | " d = dists(v1, v2)\n", 278 | " return np.exp(-d/sigma)\n", 279 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 280 | "\n", 281 | "@jit\n", 282 | "def iq(v1, v2, sigma):\n", 283 | " #V1 is a [k1] vector\n", 284 | " #V2 is a [k2] vector\n", 285 | " #returns a k1xk2 matrix\n", 286 | " d = dists(v1, v2)\n", 287 | " #return a*np.exp(-d**2/sigma)\n", 288 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 289 | " return 1/np.sqrt(d+sigma)" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": 13, 295 | "id": "c53c7c21", 296 | "metadata": {}, 297 | "outputs": [], 298 | "source": [ 299 | "Ntrain = 20000\n", 300 | "n_components = 128" 301 | ] 302 | }, 303 | { 304 | "cell_type": "code", 305 | "execution_count": 18, 306 | "id": "5dc9353e", 307 | "metadata": {}, 308 | "outputs": [], 309 | "source": [ 310 | "Ytr = Outputs_fl[:Ntrain]\n", 311 | "Xtr = Inputs_fl[:Ntrain]\n", 312 | "pca = PCA(n_components=128)\n", 313 | "Xtr = pca.fit_transform(Xtr)\n", 314 | "Xtest = pca.transform(Inputs_fl[20000:])\n", 315 | "Ytest = Outputs_fl[20000:]" 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 19, 321 | "id": "155103cb", 322 | "metadata": {}, 323 | "outputs": [], 324 | "source": [ 325 | "def aux(kernel, s, nugget):\n", 326 | " k = kernel\n", 327 | " Kxx = k(Xtr, Xtr, s)\n", 328 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 329 | " L = cho_factor(nuggeted_matrix)\n", 330 | " result = cho_solve(L, Ytr)\n", 331 | " Train_pred = Kxx@result #train predictions\n", 332 | " K_te_tr = k(Xtest, Xtr,s)\n", 333 | " Test_pred = K_te_tr@result #test predictions\n", 334 | "\n", 335 | " np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 336 | "\n", 337 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 338 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 339 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 340 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 341 | " print(s, nugget)\n", 342 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (abs): {2} \\n Test error (rel): {3}\".format(aux1, aux2, aux3, aux4))\n", 343 | " print('---')" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": null, 349 | "id": "5eeda8a0", 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "name": "stdout", 354 | "output_type": "stream", 355 | "text": [ 356 | "5 1e-08\n", 357 | "\n", 358 | " Train error (abs): 7.276826403528763e-06 \n", 359 | " Train error (rel): 3.089005917986685e-06 \n", 360 | " Test error (abs): 0.003665024745308938 \n", 361 | " Test error (rel): 0.0014081518995192623\n", 362 | "---\n", 363 | "10 1e-08\n", 364 | "\n", 365 | " Train error (abs): 7.200404681824904e-05 \n", 366 | " Train error (rel): 3.03446390315076e-05 \n", 367 | " Test error (abs): 0.003295011932480988 \n", 368 | " Test error (rel): 0.0012717308826757372\n", 369 | "---\n", 370 | "20 1e-08\n", 371 | "\n", 372 | " Train error (abs): 0.0005751168230804549 \n", 373 | " Train error (rel): 0.00023795777145700368 \n", 374 | " Test error (abs): 0.0035589315715148133 \n", 375 | " Test error (rel): 0.0013742244965366688\n", 376 | "---\n", 377 | "40 1e-08\n", 378 | "\n", 379 | " Train error (abs): 0.002571595017334048 \n", 380 | " Train error (rel): 0.0010307540462265849 \n", 381 | " Test error (abs): 0.0054430767479309895 \n", 382 | " Test error (rel): 0.002097828483297336\n", 383 | "---\n", 384 | "80 1e-08\n", 385 | "\n", 386 | " Train error (abs): 0.00710162282967508 \n", 387 | " Train error (rel): 0.002775712637816118 \n", 388 | " Test error (abs): 0.010035304873628978 \n", 389 | " Test error (rel): 0.003849685796999607\n", 390 | "---\n", 391 | "100 1e-08\n" 392 | ] 393 | } 394 | ], 395 | "source": [ 396 | "for kernel in [iq, matern]:\n", 397 | " for s in [5, 10, 20, 40, 80, 100]:\n", 398 | " for nugget in [1e-8]:\n", 399 | " aux(kernel, s, nugget)" 400 | ] 401 | }, 402 | { 403 | "cell_type": "code", 404 | "execution_count": 41, 405 | "id": "d148ef50", 406 | "metadata": {}, 407 | "outputs": [ 408 | { 409 | "name": "stdout", 410 | "output_type": "stream", 411 | "text": [ 412 | "5 1e-08\n", 413 | "\n", 414 | " Train error (abs): 7.276826314842877e-06 \n", 415 | " Train error (rel): 3.089005883597936e-06 \n", 416 | " Test error (abs): 0.0036650247452169396 \n", 417 | " Test error (rel): 0.001408151899488941\n", 418 | "---\n", 419 | "10 1e-08\n", 420 | "\n", 421 | " Train error (abs): 7.200404742330143e-05 \n", 422 | " Train error (rel): 3.0344639302522636e-05 \n", 423 | " Test error (abs): 0.003295011932740077 \n", 424 | " Test error (rel): 0.0012717308827894362\n", 425 | "---\n", 426 | "20 1e-08\n", 427 | "\n", 428 | " Train error (abs): 0.0005751168252746178 \n", 429 | " Train error (rel): 0.00023795777233394865 \n", 430 | " Test error (abs): 0.003558931576589692 \n", 431 | " Test error (rel): 0.0013742244987143153\n", 432 | "---\n", 433 | "40 1e-08\n", 434 | "\n", 435 | " Train error (abs): 0.0025715950223758775 \n", 436 | " Train error (rel): 0.0010307540484672058 \n", 437 | " Test error (abs): 0.005443076746567158 \n", 438 | " Test error (rel): 0.002097828482226641\n", 439 | "---\n", 440 | "80 1e-08\n", 441 | "\n", 442 | " Train error (abs): 0.007101622836243661 \n", 443 | " Train error (rel): 0.0027757126412045426 \n", 444 | " Test error (abs): 0.010035304870783596 \n", 445 | " Test error (rel): 0.003849685796898841\n", 446 | "---\n", 447 | "100 1e-08\n", 448 | "\n", 449 | " Train error (abs): 0.008777021698441391 \n", 450 | " Train error (rel): 0.0034134716017403914 \n", 451 | " Test error (abs): 0.011648809706353166 \n", 452 | " Test error (rel): 0.00446285613578873\n", 453 | "---\n", 454 | "5 1e-08\n", 455 | "\n", 456 | " Train error (abs): 1.8680382227438588e-05 \n", 457 | " Train error (rel): 7.715601158446827e-06 \n", 458 | " Test error (abs): 0.004082134181028857 \n", 459 | " Test error (rel): 0.0015439475541831824\n", 460 | "---\n", 461 | "10 1e-08\n", 462 | "\n", 463 | " Train error (abs): 0.0004593451867777649 \n", 464 | " Train error (rel): 0.00018792238790783902 \n", 465 | " Test error (abs): 0.004298729724052864 \n", 466 | " Test error (rel): 0.0016312560985817922\n", 467 | "---\n", 468 | "20 1e-08\n", 469 | "\n", 470 | " Train error (abs): 0.00441939982350507 \n", 471 | " Train error (rel): 0.001732601979238959 \n", 472 | " Test error (abs): 0.007564911314853524 \n", 473 | " Test error (rel): 0.0028775780601858606\n", 474 | "---\n", 475 | "40 1e-08\n", 476 | "\n", 477 | " Train error (abs): 0.011935068497307105 \n", 478 | " Train error (rel): 0.004609202332044532 \n", 479 | " Test error (abs): 0.014018198868345053 \n", 480 | " Test error (rel): 0.005357200943388285\n", 481 | "---\n", 482 | "80 1e-08\n", 483 | "\n", 484 | " Train error (abs): 0.028390596741171125 \n", 485 | " Train error (rel): 0.011160969489161255 \n", 486 | " Test error (abs): 0.029991121530365435 \n", 487 | " Test error (rel): 0.011725741509377191\n", 488 | "---\n", 489 | "100 1e-08\n", 490 | "\n", 491 | " Train error (abs): 0.04295939242209847 \n", 492 | " Train error (rel): 0.016883225497084167 \n", 493 | " Test error (abs): 0.044632569692721974 \n", 494 | " Test error (rel): 0.017459576399767546\n", 495 | "---\n" 496 | ] 497 | } 498 | ], 499 | "source": [ 500 | "for kernel in [iq, matern]:\n", 501 | " for s in [5, 10, 20, 40, 80, 100]:\n", 502 | " for nugget in [1e-8]:\n", 503 | " aux(kernel, s, nugget)" 504 | ] 505 | } 506 | ], 507 | "metadata": { 508 | "kernelspec": { 509 | "display_name": "Python 3 (ipykernel)", 510 | "language": "python", 511 | "name": "python3" 512 | }, 513 | "language_info": { 514 | "codemirror_mode": { 515 | "name": "ipython", 516 | "version": 3 517 | }, 518 | "file_extension": ".py", 519 | "mimetype": "text/x-python", 520 | "name": "python", 521 | "nbconvert_exporter": "python", 522 | "pygments_lexer": "ipython3", 523 | "version": "3.10.4" 524 | } 525 | }, 526 | "nbformat": 4, 527 | "nbformat_minor": 5 528 | } 529 | -------------------------------------------------------------------------------- /HighDataRegime/.ipynb_checkpoints/Struc-JaxKernels-OutputPCAd-checkpoint.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "import pandas as pd" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "1a79b907", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 40 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 41 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 42 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "6c5e4ba4", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "#The columns = [Nexamples, network width, Train, Test]" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "a989201f", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "Inputs = onp.load('data/Helmholtz_inputs.npy')\n", 63 | "Outputs = onp.load('data/Helmholtz_outputs.npy')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "id": "7d27a7a7", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "Inputs = Inputs.transpose((2,1,0))\n", 74 | "Outputs = Outputs.transpose((2,1,0))\n", 75 | "\n", 76 | "Inputs_fl = Inputs.reshape(len(Inputs), 101*101)\n", 77 | "Outputs_fl = Outputs.reshape(len(Outputs), 101*101)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "d5235802", 83 | "metadata": {}, 84 | "source": [ 85 | "GP regression" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 6, 91 | "id": "74327ec9", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 96 | " return np.sum( (x - y) ** 2)\n", 97 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 98 | "\n", 99 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 100 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 101 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 102 | "\n", 103 | "\n", 104 | "@jit\n", 105 | "def matern(v1, v2, sigma = 50):\n", 106 | " #V1 is a [k1] vector\n", 107 | " #V2 is a [k2] vector\n", 108 | " #returns a k1xk2 matrix\n", 109 | " d = sqdists(v1, v2)\n", 110 | " #return a*np.exp(-d**2/sigma)\n", 111 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 112 | "\n", 113 | "@jit\n", 114 | "def exp(v1, v2, sigma):\n", 115 | " #V1 is a [k1] vector\n", 116 | " #V2 is a [k2] vector\n", 117 | " #returns a k1xk2 matrix\n", 118 | " d = dists(v1, v2)\n", 119 | " return np.exp(-d/sigma)\n", 120 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 121 | "\n", 122 | "@jit\n", 123 | "def iq(v1, v2, sigma):\n", 124 | " #V1 is a [k1] vector\n", 125 | " #V2 is a [k2] vector\n", 126 | " #returns a k1xk2 matrix\n", 127 | " d = dists(v1, v2)\n", 128 | " #return a*np.exp(-d**2/sigma)\n", 129 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 130 | " return 1/np.sqrt(d+sigma)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 15, 136 | "id": "c53c7c21", 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "Ntrain = 110000" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 16, 146 | "id": "c5fb23e6", 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "Xtr = Inputs_fl[:Ntrain]\n", 151 | "pca_inp = PCA(n_components=200)\n", 152 | "Xtr = pca_inp.fit_transform(Xtr)\n", 153 | "Xtest = pca_inp.transform(Inputs_fl[20000:])\n", 154 | "\n", 155 | "Ytr = Outputs_fl[:Ntrain]\n", 156 | "pca_out = PCA(n_components=500)\n", 157 | "Ytr = pca_out.fit_transform(Ytr)\n", 158 | "Ytest = pca_out.transform(Outputs_fl[20000:])" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 17, 164 | "id": "5dc9353e", 165 | "metadata": { 166 | "scrolled": false 167 | }, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "1000 1e-12\n", 174 | "\n", 175 | " Train error (abs): 6.959614690085883e-09 \n", 176 | " Train error (rel): 1.7157951523708667e-08 \n", 177 | " Test error (PCA space, abs): 0.016747542524584408 \n", 178 | " Test error (PCA space, rel): 0.032924033460171226 \n", 179 | " Test error (Real space, abs): 0.01674755086003411 \n", 180 | " Test error (Real space, rel): 0.03292405210672207 \n", 181 | "---\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "for kernel in [iq]:\n", 187 | " for s in [1000]:\n", 188 | " for nugget in [1e-12]:\n", 189 | " k = kernel\n", 190 | " Kxx = k(Xtr, Xtr, s)\n", 191 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 192 | " L = cho_factor(nuggeted_matrix)\n", 193 | " result = cho_solve(L, Ytr)\n", 194 | " Train_pred = Kxx@result #train predictions\n", 195 | " K_te_tr = k(Xtest, Xtr,s)\n", 196 | " Test_pred = K_te_tr@result #test predictions\n", 197 | "\n", 198 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 199 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 200 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 201 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 202 | "\n", 203 | " true_pred = pca_out.inverse_transform(Test_pred)\n", 204 | " true_ytest = Outputs_fl[20000:]\n", 205 | "\n", 206 | " aux5 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1))\n", 207 | " aux6 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 208 | "\n", 209 | " print(s, nugget)\n", 210 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (PCA space, abs): {2} \\n Test error (PCA space, rel): {3} \\n Test error (Real space, abs): {4} \\n Test error (Real space, rel): {5} \".format(aux1, aux2, aux3, aux4, aux5, aux6))\n", 211 | " print('---')" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "id": "dc3b0fa4", 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [] 221 | } 222 | ], 223 | "metadata": { 224 | "kernelspec": { 225 | "display_name": "Python 3 (ipykernel)", 226 | "language": "python", 227 | "name": "python3" 228 | }, 229 | "language_info": { 230 | "codemirror_mode": { 231 | "name": "ipython", 232 | "version": 3 233 | }, 234 | "file_extension": ".py", 235 | "mimetype": "text/x-python", 236 | "name": "python", 237 | "nbconvert_exporter": "python", 238 | "pygments_lexer": "ipython3", 239 | "version": "3.10.4" 240 | } 241 | }, 242 | "nbformat": 4, 243 | "nbformat_minor": 5 244 | } 245 | -------------------------------------------------------------------------------- /HighDataRegime/Figures/AccuracyComplexity.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/AccuracyComplexity.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/ErrorAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/ErrorAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/ErrorHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/ErrorHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/ErrorMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/ErrorMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/ErrorNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/ErrorNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/InputAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/InputAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/InputHelmoltz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/InputHelmoltz.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/InputNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/InputNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/InputStructural.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/InputStructural.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/OutputAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/OutputAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/OutputHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/OutputHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/OutputNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/OutputNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/OutputStructuralMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/OutputStructuralMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/OverlayAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/OverlayAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/OverlayAdvectionII.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/OverlayAdvectionII.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/PredAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/PredAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/PredictedHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/PredictedHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/PredictedMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/PredictedMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/PredictedNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/PredictedNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/TestAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/TestAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/True.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/True.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/TrueAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/TrueAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/TrueHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/TrueHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/TrueMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/TrueMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/Figures/TrueNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/Figures/TrueNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/Helmholtz-JaxKernels-OutputPCAd-Copy1.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "import pandas as pd" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "1a79b907", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 40 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 41 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 42 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "6c5e4ba4", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "#The columns = [Nexamples, network width, Train, Test]" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "a989201f", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "Inputs = onp.load('data/Helmholtz_inputs.npy')\n", 63 | "Outputs = onp.load('data/Helmholtz_outputs.npy')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "id": "7d27a7a7", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "Inputs = Inputs.transpose((2,1,0))\n", 74 | "Outputs = Outputs.transpose((2,1,0))\n", 75 | "\n", 76 | "Inputs_fl = Inputs.reshape(len(Inputs), 101*101)\n", 77 | "Outputs_fl = Outputs.reshape(len(Outputs), 101*101)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "d5235802", 83 | "metadata": {}, 84 | "source": [ 85 | "GP regression" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 6, 91 | "id": "74327ec9", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 96 | " return np.sum( (x - y) ** 2)\n", 97 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 98 | "\n", 99 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 100 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 101 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 102 | "\n", 103 | "\n", 104 | "@jit\n", 105 | "def matern(v1, v2, sigma = 50):\n", 106 | " #V1 is a [k1] vector\n", 107 | " #V2 is a [k2] vector\n", 108 | " #returns a k1xk2 matrix\n", 109 | " d = sqdists(v1, v2)\n", 110 | " #return a*np.exp(-d**2/sigma)\n", 111 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 112 | "\n", 113 | "@jit\n", 114 | "def exp(v1, v2, sigma):\n", 115 | " #V1 is a [k1] vector\n", 116 | " #V2 is a [k2] vector\n", 117 | " #returns a k1xk2 matrix\n", 118 | " d = dists(v1, v2)\n", 119 | " return np.exp(-d/sigma)\n", 120 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 121 | "\n", 122 | "@jit\n", 123 | "def iq(v1, v2, sigma):\n", 124 | " #V1 is a [k1] vector\n", 125 | " #V2 is a [k2] vector\n", 126 | " #returns a k1xk2 matrix\n", 127 | " d = dists(v1, v2)\n", 128 | " #return a*np.exp(-d**2/sigma)\n", 129 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 130 | " return 1/np.sqrt(d+sigma)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 15, 136 | "id": "c53c7c21", 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "Ntrain = 10000" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 16, 146 | "id": "c5fb23e6", 147 | "metadata": {}, 148 | "outputs": [], 149 | "source": [ 150 | "Xtr = Inputs_fl[:Ntrain]\n", 151 | "pca_inp = PCA(n_components=200)\n", 152 | "Xtr = pca_inp.fit_transform(Xtr)\n", 153 | "Xtest = pca_inp.transform(Inputs_fl[20000:])\n", 154 | "\n", 155 | "Ytr = Outputs_fl[:Ntrain]\n", 156 | "pca_out = PCA(n_components=500)\n", 157 | "Ytr = pca_out.fit_transform(Ytr)\n", 158 | "Ytest = pca_out.transform(Outputs_fl[20000:])" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 17, 164 | "id": "5dc9353e", 165 | "metadata": { 166 | "scrolled": false 167 | }, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "1000 1e-12\n", 174 | "\n", 175 | " Train error (abs): 6.959614690085883e-09 \n", 176 | " Train error (rel): 1.7157951523708667e-08 \n", 177 | " Test error (PCA space, abs): 0.016747542524584408 \n", 178 | " Test error (PCA space, rel): 0.032924033460171226 \n", 179 | " Test error (Real space, abs): 0.01674755086003411 \n", 180 | " Test error (Real space, rel): 0.03292405210672207 \n", 181 | "---\n" 182 | ] 183 | } 184 | ], 185 | "source": [ 186 | "for kernel in [iq]:\n", 187 | " for s in [1000]:\n", 188 | " for nugget in [1e-12]:\n", 189 | " k = kernel\n", 190 | " Kxx = k(Xtr, Xtr, s)\n", 191 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 192 | " L = cho_factor(nuggeted_matrix)\n", 193 | " result = cho_solve(L, Ytr)\n", 194 | " Train_pred = Kxx@result #train predictions\n", 195 | " K_te_tr = k(Xtest, Xtr,s)\n", 196 | " Test_pred = K_te_tr@result #test predictions\n", 197 | "\n", 198 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 199 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 200 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 201 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 202 | "\n", 203 | " true_pred = pca_out.inverse_transform(Test_pred)\n", 204 | " true_ytest = Outputs_fl[20000:]\n", 205 | "\n", 206 | " aux5 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1))\n", 207 | " aux6 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 208 | "\n", 209 | " print(s, nugget)\n", 210 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (PCA space, abs): {2} \\n Test error (PCA space, rel): {3} \\n Test error (Real space, abs): {4} \\n Test error (Real space, rel): {5} \".format(aux1, aux2, aux3, aux4, aux5, aux6))\n", 211 | " print('---')" 212 | ] 213 | }, 214 | { 215 | "cell_type": "code", 216 | "execution_count": null, 217 | "id": "dc3b0fa4", 218 | "metadata": {}, 219 | "outputs": [], 220 | "source": [] 221 | } 222 | ], 223 | "metadata": { 224 | "kernelspec": { 225 | "display_name": "Python 3 (ipykernel)", 226 | "language": "python", 227 | "name": "python3" 228 | }, 229 | "language_info": { 230 | "codemirror_mode": { 231 | "name": "ipython", 232 | "version": 3 233 | }, 234 | "file_extension": ".py", 235 | "mimetype": "text/x-python", 236 | "name": "python", 237 | "nbconvert_exporter": "python", 238 | "pygments_lexer": "ipython3", 239 | "version": "3.10.4" 240 | } 241 | }, 242 | "nbformat": 4, 243 | "nbformat_minor": 5 244 | } 245 | -------------------------------------------------------------------------------- /HighDataRegime/Navier-Stokes-JaxKernels-OutputPCAd.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "import pandas as pd" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "1a79b907", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 40 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 41 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 42 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "6c5e4ba4", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "#The columns = [Nexamples, network width, Train, Test]" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "a989201f", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "Inputs = onp.load('data/NavierStokes_inputs.npy')\n", 63 | "Outputs = onp.load('data/NavierStokes_outputs.npy')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "id": "7d27a7a7", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "Inputs = Inputs.transpose((2,1,0))\n", 74 | "Outputs = Outputs.transpose((2,1,0))\n", 75 | "\n", 76 | "Inputs_fl = Inputs.reshape(len(Inputs), 64*64)\n", 77 | "Outputs_fl = Outputs.reshape(len(Outputs), 64*64)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "markdown", 82 | "id": "d5235802", 83 | "metadata": {}, 84 | "source": [ 85 | "GP regression" 86 | ] 87 | }, 88 | { 89 | "cell_type": "code", 90 | "execution_count": 6, 91 | "id": "74327ec9", 92 | "metadata": {}, 93 | "outputs": [], 94 | "source": [ 95 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 96 | " return np.sum( (x - y) ** 2)\n", 97 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 98 | "\n", 99 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 100 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 101 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 102 | "\n", 103 | "\n", 104 | "@jit\n", 105 | "def matern(v1, v2, sigma = 50):\n", 106 | " #V1 is a [k1] vector\n", 107 | " #V2 is a [k2] vector\n", 108 | " #returns a k1xk2 matrix\n", 109 | " d = sqdists(v1, v2)\n", 110 | " #return a*np.exp(-d**2/sigma)\n", 111 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 112 | "\n", 113 | "@jit\n", 114 | "def exp(v1, v2, sigma):\n", 115 | " #V1 is a [k1] vector\n", 116 | " #V2 is a [k2] vector\n", 117 | " #returns a k1xk2 matrix\n", 118 | " d = dists(v1, v2)\n", 119 | " return np.exp(-d/sigma)\n", 120 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 121 | "\n", 122 | "@jit\n", 123 | "def iq(v1, v2, sigma):\n", 124 | " #V1 is a [k1] vector\n", 125 | " #V2 is a [k2] vector\n", 126 | " #returns a k1xk2 matrix\n", 127 | " d = dists(v1, v2)\n", 128 | " #return a*np.exp(-d**2/sigma)\n", 129 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 130 | " return 1/np.sqrt(d+sigma)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 20, 136 | "id": "c53c7c21", 137 | "metadata": {}, 138 | "outputs": [], 139 | "source": [ 140 | "Ntrain = 10000\n" 141 | ] 142 | }, 143 | { 144 | "cell_type": "code", 145 | "execution_count": 21, 146 | "id": "c5fb23e6", 147 | "metadata": {}, 148 | "outputs": [ 149 | { 150 | "name": "stdout", 151 | "output_type": "stream", 152 | "text": [ 153 | "128\n" 154 | ] 155 | } 156 | ], 157 | "source": [ 158 | "print(ncomp)\n", 159 | "Xtr = Inputs_fl[:Ntrain]\n", 160 | "pca_inp = PCA(n_components=128)\n", 161 | "Xtr = pca_inp.fit_transform(Xtr)\n", 162 | "Xtest = pca_inp.transform(Inputs_fl[20000:])\n", 163 | "\n", 164 | "Ytr = Outputs_fl[:Ntrain]\n", 165 | "pca_out = PCA(n_components=128)\n", 166 | "Ytr = pca_out.fit_transform(Ytr)\n", 167 | "Ytest = pca_out.transform(Outputs_fl[20000:])\n" 168 | ] 169 | }, 170 | { 171 | "cell_type": "code", 172 | "execution_count": 22, 173 | "id": "5dc9353e", 174 | "metadata": { 175 | "scrolled": false 176 | }, 177 | "outputs": [ 178 | { 179 | "name": "stdout", 180 | "output_type": "stream", 181 | "text": [ 182 | "10 1e-12\n", 183 | "\n", 184 | " Train error (abs): 6.425398231654291e-09 \n", 185 | " Train error (rel): 2.7146044992801137e-09 \n", 186 | " Test error (PCA space, abs): 0.006521107888810295 \n", 187 | " Test error (PCA space, rel): 0.0025367140024987133 \n", 188 | " Test error (Real space, abs): 0.006648690663249997 \n", 189 | " Test error (Real space, rel): 0.0025890687838295763 \n", 190 | "---\n" 191 | ] 192 | } 193 | ], 194 | "source": [ 195 | "for kernel in [iq]:\n", 196 | " for s in [10]:\n", 197 | " for nugget in [1e-12]:\n", 198 | " k = kernel\n", 199 | " Kxx = k(Xtr, Xtr, s)\n", 200 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 201 | " L = cho_factor(nuggeted_matrix)\n", 202 | " result = cho_solve(L, Ytr)\n", 203 | " Train_pred = Kxx@result #train predictions\n", 204 | " K_te_tr = k(Xtest, Xtr,s)\n", 205 | " Test_pred = K_te_tr@result #test predictions\n", 206 | "\n", 207 | " np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 208 | "\n", 209 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 210 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 211 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 212 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 213 | "\n", 214 | " true_pred = pca_out.inverse_transform(Test_pred)\n", 215 | " true_ytest = Outputs_fl[20000:]\n", 216 | "\n", 217 | " aux5 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1))\n", 218 | " aux6 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 219 | "\n", 220 | " print(s, nugget)\n", 221 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (PCA space, abs): {2} \\n Test error (PCA space, rel): {3} \\n Test error (Real space, abs): {4} \\n Test error (Real space, rel): {5} \".format(aux1, aux2, aux3, aux4, aux5, aux6))\n", 222 | " print('---')" 223 | ] 224 | }, 225 | { 226 | "cell_type": "code", 227 | "execution_count": null, 228 | "id": "35530bd5", 229 | "metadata": {}, 230 | "outputs": [], 231 | "source": [ 232 | "#Jax regression" 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": null, 238 | "id": "5eeda8a0", 239 | "metadata": {}, 240 | "outputs": [], 241 | "source": [] 242 | }, 243 | { 244 | "cell_type": "code", 245 | "execution_count": null, 246 | "id": "d97489e4", 247 | "metadata": {}, 248 | "outputs": [], 249 | "source": [] 250 | }, 251 | { 252 | "cell_type": "code", 253 | "execution_count": null, 254 | "id": "4ec629f8", 255 | "metadata": {}, 256 | "outputs": [], 257 | "source": [ 258 | "true_pred.shapea" 259 | ] 260 | }, 261 | { 262 | "cell_type": "code", 263 | "execution_count": null, 264 | "id": "5b3c7ee8", 265 | "metadata": {}, 266 | "outputs": [], 267 | "source": [] 268 | }, 269 | { 270 | "cell_type": "code", 271 | "execution_count": null, 272 | "id": "92942cd1", 273 | "metadata": {}, 274 | "outputs": [], 275 | "source": [ 276 | "import pickle" 277 | ] 278 | }, 279 | { 280 | "cell_type": "code", 281 | "execution_count": null, 282 | "id": "c5d91382", 283 | "metadata": {}, 284 | "outputs": [], 285 | "source": [ 286 | "pickle.dump(obj=[Ytest[42], Test_pred[42]], file = open('PredictedNS.pkl', 'wb'))" 287 | ] 288 | }, 289 | { 290 | "cell_type": "code", 291 | "execution_count": null, 292 | "id": "d148ef50", 293 | "metadata": { 294 | "scrolled": false 295 | }, 296 | "outputs": [], 297 | "source": [] 298 | } 299 | ], 300 | "metadata": { 301 | "kernelspec": { 302 | "display_name": "Python 3 (ipykernel)", 303 | "language": "python", 304 | "name": "python3" 305 | }, 306 | "language_info": { 307 | "codemirror_mode": { 308 | "name": "ipython", 309 | "version": 3 310 | }, 311 | "file_extension": ".py", 312 | "mimetype": "text/x-python", 313 | "name": "python", 314 | "nbconvert_exporter": "python", 315 | "pygments_lexer": "ipython3", 316 | "version": "3.10.4" 317 | } 318 | }, 319 | "nbformat": 4, 320 | "nbformat_minor": 5 321 | } 322 | -------------------------------------------------------------------------------- /HighDataRegime/Navier-Stokes-JaxKernels.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "\n", 30 | "import pandas as pd" 31 | ] 32 | }, 33 | { 34 | "cell_type": "code", 35 | "execution_count": 2, 36 | "id": "100fc64e", 37 | "metadata": {}, 38 | "outputs": [], 39 | "source": [ 40 | "import pandas as pd" 41 | ] 42 | }, 43 | { 44 | "cell_type": "code", 45 | "execution_count": 3, 46 | "id": "1a79b907", 47 | "metadata": {}, 48 | "outputs": [], 49 | "source": [ 50 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 51 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 52 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 53 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 54 | ] 55 | }, 56 | { 57 | "cell_type": "code", 58 | "execution_count": 4, 59 | "id": "4bf4febc", 60 | "metadata": {}, 61 | "outputs": [ 62 | { 63 | "data": { 64 | "text/plain": [ 65 | "(DeviceArray(0.02654266, dtype=float64),\n", 66 | " DeviceArray(0.00259586, dtype=float64),\n", 67 | " DeviceArray(0.03629472, dtype=float64),\n", 68 | " DeviceArray(0.04088747, dtype=float64))" 69 | ] 70 | }, 71 | "execution_count": 4, 72 | "metadata": {}, 73 | "output_type": "execute_result" 74 | } 75 | ], 76 | "source": [ 77 | "np.min(PCANet[:,4]), np.min(FNO[:,4]), np.min(DeepONet[:, 4]), np.min(Para[:, 4])" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": 5, 83 | "id": "6c5e4ba4", 84 | "metadata": {}, 85 | "outputs": [], 86 | "source": [ 87 | "#The columns = [Nexamples, network width, Train, Test]" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 6, 93 | "id": "a989201f", 94 | "metadata": {}, 95 | "outputs": [], 96 | "source": [ 97 | "Inputs = np.load('data/NavierStokes_inputs.npy')\n", 98 | "Outputs = np.load('data/NavierStokes_outputs.npy')" 99 | ] 100 | }, 101 | { 102 | "cell_type": "code", 103 | "execution_count": 7, 104 | "id": "2f967df0", 105 | "metadata": { 106 | "scrolled": true 107 | }, 108 | "outputs": [ 109 | { 110 | "data": { 111 | "text/plain": [ 112 | "(64, 64, 40000)" 113 | ] 114 | }, 115 | "execution_count": 7, 116 | "metadata": {}, 117 | "output_type": "execute_result" 118 | } 119 | ], 120 | "source": [ 121 | "Inputs.shape" 122 | ] 123 | }, 124 | { 125 | "cell_type": "code", 126 | "execution_count": 8, 127 | "id": "7d27a7a7", 128 | "metadata": {}, 129 | "outputs": [], 130 | "source": [ 131 | "Inputs = Inputs.transpose((2,1,0))\n", 132 | "Outputs = Outputs.transpose((2,1,0))\n", 133 | "\n", 134 | "Inputs_fl = Inputs.reshape(len(Inputs), 64*64)\n", 135 | "Outputs_fl = Outputs.reshape(len(Outputs), 64*64)" 136 | ] 137 | }, 138 | { 139 | "cell_type": "markdown", 140 | "id": "e74c76d7", 141 | "metadata": {}, 142 | "source": [ 143 | "Linear regression" 144 | ] 145 | }, 146 | { 147 | "cell_type": "code", 148 | "execution_count": 9, 149 | "id": "4c430294", 150 | "metadata": { 151 | "scrolled": false 152 | }, 153 | "outputs": [ 154 | { 155 | "name": "stdout", 156 | "output_type": "stream", 157 | "text": [ 158 | "20000 128\n", 159 | "0.053725325383721885 0.054129107629736904\n", 160 | "20000 256\n", 161 | "0.053724771853986414 0.0541287837480367\n", 162 | "20000 512\n", 163 | "0.053725442394692256 0.054128941233027035\n", 164 | "20000 1024\n", 165 | "0.05372536128518232 0.0541288361220119\n" 166 | ] 167 | } 168 | ], 169 | "source": [ 170 | "results = []\n", 171 | "for Ntrain in [20000]:\n", 172 | " for N_components in [128, 256, 512, 1024]:\n", 173 | " print(Ntrain, N_components)\n", 174 | " Ytr = Outputs_fl[:Ntrain]\n", 175 | " Xtr = Inputs_fl[:Ntrain]\n", 176 | " pca = PCA(n_components=min(N_components,Ntrain))\n", 177 | " Xtr = pca.fit_transform(Xtr)\n", 178 | " reg = LinearRegression(n_jobs = -1).fit(Xtr, Ytr)\n", 179 | " #Ypred Ypredtr = reg.predict(Xtr)\n", 180 | " Ypredtr = reg.predict(Xtr)\n", 181 | " train_error = np.mean(np.linalg.norm(Ypredtr-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 182 | " Xtest = Inputs_fl[20000:]\n", 183 | " Ytest = Outputs_fl[20000:]\n", 184 | " Xtest = pca.transform(Xtest)\n", 185 | " Ypred = reg.predict(Xtest)\n", 186 | " test_error = np.mean(np.linalg.norm(Ypred-Ytest, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 187 | " print(train_error, test_error)\n", 188 | " results.append([Ntrain, N_components, train_error, test_error])\n", 189 | "\n", 190 | "results = np.array(results)" 191 | ] 192 | }, 193 | { 194 | "cell_type": "markdown", 195 | "id": "d5235802", 196 | "metadata": {}, 197 | "source": [ 198 | "GP regression" 199 | ] 200 | }, 201 | { 202 | "cell_type": "code", 203 | "execution_count": 10, 204 | "id": "eecfb3f4", 205 | "metadata": {}, 206 | "outputs": [], 207 | "source": [ 208 | "# from sklearn.gaussian_process import GaussianProcessRegressor\n", 209 | "# from sklearn.gaussian_process.kernels import Matern, RBF, RationalQuadratic\n", 210 | "\n", 211 | "# kernel = Matern(nu = 2.5)\n", 212 | "\n", 213 | "# Xtr.shape\n", 214 | "\n", 215 | "# resultsgp = []\n", 216 | "# for Ntrain in [156, 312, 624, 1250, 2500]:\n", 217 | "# print(Ntrain)\n", 218 | "# Ytr = Outputs_fl[:Ntrain]\n", 219 | "# Xtr = Inputs_fl[:Ntrain]\n", 220 | "# pca = PCA(n_components=128)\n", 221 | "# Xtr = pca.fit_transform(Xtr)\n", 222 | " \n", 223 | "# model = GaussianProcessRegressor(kernel, alpha = 1e-10)\n", 224 | "# model.fit(Xtr, Ytr)\n", 225 | "# #Ypred Ypredtr = reg.predict(Xtr)\n", 226 | "# Ypredtr = model.predict(Xtr)\n", 227 | "# train_error = np.mean(np.linalg.norm(Ypredtr-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 228 | "# Xtest = Inputs_fl[20000:]\n", 229 | "# Ytest = Outputs_fl[20000:]\n", 230 | "# Xtest = pca.transform(Xtest)\n", 231 | "# Ypred= model.predict(Xtest)\n", 232 | "# test_error = np.mean(np.linalg.norm(Ypred-Ytest, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 233 | "# print(train_error, test_error)\n", 234 | "# resultsgp.append([Ntrain, train_error, test_error])" 235 | ] 236 | }, 237 | { 238 | "cell_type": "code", 239 | "execution_count": 11, 240 | "id": "35530bd5", 241 | "metadata": {}, 242 | "outputs": [], 243 | "source": [ 244 | "#Jax regression" 245 | ] 246 | }, 247 | { 248 | "cell_type": "code", 249 | "execution_count": null, 250 | "id": "74327ec9", 251 | "metadata": {}, 252 | "outputs": [], 253 | "source": [ 254 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 255 | " return np.sum( (x - y) ** 2)\n", 256 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 257 | "\n", 258 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 259 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 260 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 261 | "\n", 262 | "\n", 263 | "@jit\n", 264 | "def matern(v1, v2, sigma = 50):\n", 265 | " #V1 is a [k1] vector\n", 266 | " #V2 is a [k2] vector\n", 267 | " #returns a k1xk2 matrix\n", 268 | " d = sqdists(v1, v2)\n", 269 | " #return a*np.exp(-d**2/sigma)\n", 270 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 271 | "\n", 272 | "@jit\n", 273 | "def exp(v1, v2, sigma):\n", 274 | " #V1 is a [k1] vector\n", 275 | " #V2 is a [k2] vector\n", 276 | " #returns a k1xk2 matrix\n", 277 | " d = dists(v1, v2)\n", 278 | " return np.exp(-d/sigma)\n", 279 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 280 | "\n", 281 | "@jit\n", 282 | "def iq(v1, v2, sigma):\n", 283 | " #V1 is a [k1] vector\n", 284 | " #V2 is a [k2] vector\n", 285 | " #returns a k1xk2 matrix\n", 286 | " d = dists(v1, v2)\n", 287 | " #return a*np.exp(-d**2/sigma)\n", 288 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 289 | " return 1/np.sqrt(d+sigma)" 290 | ] 291 | }, 292 | { 293 | "cell_type": "code", 294 | "execution_count": 13, 295 | "id": "c53c7c21", 296 | "metadata": {}, 297 | "outputs": [], 298 | "source": [ 299 | "Ntrain = 20000\n", 300 | "n_components = 128" 301 | ] 302 | }, 303 | { 304 | "cell_type": "code", 305 | "execution_count": 18, 306 | "id": "5dc9353e", 307 | "metadata": {}, 308 | "outputs": [], 309 | "source": [ 310 | "Ytr = Outputs_fl[:Ntrain]\n", 311 | "Xtr = Inputs_fl[:Ntrain]\n", 312 | "pca = PCA(n_components=128)\n", 313 | "Xtr = pca.fit_transform(Xtr)\n", 314 | "Xtest = pca.transform(Inputs_fl[20000:])\n", 315 | "Ytest = Outputs_fl[20000:]" 316 | ] 317 | }, 318 | { 319 | "cell_type": "code", 320 | "execution_count": 19, 321 | "id": "155103cb", 322 | "metadata": {}, 323 | "outputs": [], 324 | "source": [ 325 | "def aux(kernel, s, nugget):\n", 326 | " k = kernel\n", 327 | " Kxx = k(Xtr, Xtr, s)\n", 328 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 329 | " L = cho_factor(nuggeted_matrix)\n", 330 | " result = cho_solve(L, Ytr)\n", 331 | " Train_pred = Kxx@result #train predictions\n", 332 | " K_te_tr = k(Xtest, Xtr,s)\n", 333 | " Test_pred = K_te_tr@result #test predictions\n", 334 | "\n", 335 | " np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 336 | "\n", 337 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 338 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 339 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 340 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 341 | " print(s, nugget)\n", 342 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (abs): {2} \\n Test error (rel): {3}\".format(aux1, aux2, aux3, aux4))\n", 343 | " print('---')" 344 | ] 345 | }, 346 | { 347 | "cell_type": "code", 348 | "execution_count": 21, 349 | "id": "5eeda8a0", 350 | "metadata": {}, 351 | "outputs": [ 352 | { 353 | "name": "stdout", 354 | "output_type": "stream", 355 | "text": [ 356 | "10 1e-08\n", 357 | "\n", 358 | " Train error (abs): 7.200404681824904e-05 \n", 359 | " Train error (rel): 3.03446390315076e-05 \n", 360 | " Test error (abs): 0.003295011932480988 \n", 361 | " Test error (rel): 0.0012717308826757372\n", 362 | "---\n" 363 | ] 364 | } 365 | ], 366 | "source": [ 367 | "for kernel in [iq]:\n", 368 | " for s in [10]:\n", 369 | " for nugget in [1e-8]:\n", 370 | " aux(kernel, s, nugget)" 371 | ] 372 | }, 373 | { 374 | "cell_type": "code", 375 | "execution_count": 25, 376 | "id": "5761112e", 377 | "metadata": {}, 378 | "outputs": [], 379 | "source": [ 380 | "Kxx = iq(Xtr, Xtr, 10)\n", 381 | "nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 382 | "L = cho_factor(nuggeted_matrix)\n", 383 | "result = cho_solve(L, Ytr)\n", 384 | "Train_pred = Kxx@result #train predictions\n", 385 | "K_te_tr = iq(Xtest, Xtr,10)\n", 386 | "Test_pred = K_te_tr@result #test predictions\n" 387 | ] 388 | }, 389 | { 390 | "cell_type": "code", 391 | "execution_count": 37, 392 | "id": "92942cd1", 393 | "metadata": {}, 394 | "outputs": [], 395 | "source": [ 396 | "import pickle" 397 | ] 398 | }, 399 | { 400 | "cell_type": "code", 401 | "execution_count": 39, 402 | "id": "c5d91382", 403 | "metadata": {}, 404 | "outputs": [], 405 | "source": [ 406 | "pickle.dump(obj=[Ytest[42], Test_pred[42]], file = open('PredictedNS.pkl', 'wb'))" 407 | ] 408 | }, 409 | { 410 | "cell_type": "code", 411 | "execution_count": 41, 412 | "id": "d148ef50", 413 | "metadata": {}, 414 | "outputs": [ 415 | { 416 | "name": "stdout", 417 | "output_type": "stream", 418 | "text": [ 419 | "5 1e-08\n", 420 | "\n", 421 | " Train error (abs): 7.276826314842877e-06 \n", 422 | " Train error (rel): 3.089005883597936e-06 \n", 423 | " Test error (abs): 0.0036650247452169396 \n", 424 | " Test error (rel): 0.001408151899488941\n", 425 | "---\n", 426 | "10 1e-08\n", 427 | "\n", 428 | " Train error (abs): 7.200404742330143e-05 \n", 429 | " Train error (rel): 3.0344639302522636e-05 \n", 430 | " Test error (abs): 0.003295011932740077 \n", 431 | " Test error (rel): 0.0012717308827894362\n", 432 | "---\n", 433 | "20 1e-08\n", 434 | "\n", 435 | " Train error (abs): 0.0005751168252746178 \n", 436 | " Train error (rel): 0.00023795777233394865 \n", 437 | " Test error (abs): 0.003558931576589692 \n", 438 | " Test error (rel): 0.0013742244987143153\n", 439 | "---\n", 440 | "40 1e-08\n", 441 | "\n", 442 | " Train error (abs): 0.0025715950223758775 \n", 443 | " Train error (rel): 0.0010307540484672058 \n", 444 | " Test error (abs): 0.005443076746567158 \n", 445 | " Test error (rel): 0.002097828482226641\n", 446 | "---\n", 447 | "80 1e-08\n", 448 | "\n", 449 | " Train error (abs): 0.007101622836243661 \n", 450 | " Train error (rel): 0.0027757126412045426 \n", 451 | " Test error (abs): 0.010035304870783596 \n", 452 | " Test error (rel): 0.003849685796898841\n", 453 | "---\n", 454 | "100 1e-08\n", 455 | "\n", 456 | " Train error (abs): 0.008777021698441391 \n", 457 | " Train error (rel): 0.0034134716017403914 \n", 458 | " Test error (abs): 0.011648809706353166 \n", 459 | " Test error (rel): 0.00446285613578873\n", 460 | "---\n", 461 | "5 1e-08\n", 462 | "\n", 463 | " Train error (abs): 1.8680382227438588e-05 \n", 464 | " Train error (rel): 7.715601158446827e-06 \n", 465 | " Test error (abs): 0.004082134181028857 \n", 466 | " Test error (rel): 0.0015439475541831824\n", 467 | "---\n", 468 | "10 1e-08\n", 469 | "\n", 470 | " Train error (abs): 0.0004593451867777649 \n", 471 | " Train error (rel): 0.00018792238790783902 \n", 472 | " Test error (abs): 0.004298729724052864 \n", 473 | " Test error (rel): 0.0016312560985817922\n", 474 | "---\n", 475 | "20 1e-08\n", 476 | "\n", 477 | " Train error (abs): 0.00441939982350507 \n", 478 | " Train error (rel): 0.001732601979238959 \n", 479 | " Test error (abs): 0.007564911314853524 \n", 480 | " Test error (rel): 0.0028775780601858606\n", 481 | "---\n", 482 | "40 1e-08\n", 483 | "\n", 484 | " Train error (abs): 0.011935068497307105 \n", 485 | " Train error (rel): 0.004609202332044532 \n", 486 | " Test error (abs): 0.014018198868345053 \n", 487 | " Test error (rel): 0.005357200943388285\n", 488 | "---\n", 489 | "80 1e-08\n", 490 | "\n", 491 | " Train error (abs): 0.028390596741171125 \n", 492 | " Train error (rel): 0.011160969489161255 \n", 493 | " Test error (abs): 0.029991121530365435 \n", 494 | " Test error (rel): 0.011725741509377191\n", 495 | "---\n", 496 | "100 1e-08\n", 497 | "\n", 498 | " Train error (abs): 0.04295939242209847 \n", 499 | " Train error (rel): 0.016883225497084167 \n", 500 | " Test error (abs): 0.044632569692721974 \n", 501 | " Test error (rel): 0.017459576399767546\n", 502 | "---\n" 503 | ] 504 | } 505 | ], 506 | "source": [ 507 | "for kernel in [iq, matern]:\n", 508 | " for s in [5, 10, 20, 40, 80, 100]:\n", 509 | " for nugget in [1e-8]:\n", 510 | " aux(kernel, s, nugget)" 511 | ] 512 | } 513 | ], 514 | "metadata": { 515 | "kernelspec": { 516 | "display_name": "Python 3", 517 | "language": "python", 518 | "name": "python3" 519 | }, 520 | "language_info": { 521 | "codemirror_mode": { 522 | "name": "ipython", 523 | "version": 3 524 | }, 525 | "file_extension": ".py", 526 | "mimetype": "text/x-python", 527 | "name": "python", 528 | "nbconvert_exporter": "python", 529 | "pygments_lexer": "ipython3", 530 | "version": "3.8.8" 531 | } 532 | }, 533 | "nbformat": 4, 534 | "nbformat_minor": 5 535 | } 536 | -------------------------------------------------------------------------------- /HighDataRegime/PredictedHH.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/PredictedHH.pkl -------------------------------------------------------------------------------- /HighDataRegime/PredictedNS.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/PredictedNS.pkl -------------------------------------------------------------------------------- /HighDataRegime/PredictedSM.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/PredictedSM.pkl -------------------------------------------------------------------------------- /HighDataRegime/Struc-JaxKernels-OutputPCAd.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "id": "5ca7bac0", 7 | "metadata": {}, 8 | "outputs": [], 9 | "source": [ 10 | "import matplotlib.pyplot as plt\n", 11 | "from sklearn.decomposition import PCA\n", 12 | "from sklearn.linear_model import LinearRegression\n", 13 | "from sklearn.metrics import pairwise_distances\n", 14 | "import numpy as onp\n", 15 | "import jax.numpy as np\n", 16 | "from jax import jit, vmap\n", 17 | "import matplotlib.pyplot as plt\n", 18 | "from tqdm.notebook import tqdm as t\n", 19 | "from ipywidgets import interact\n", 20 | "from jax import grad\n", 21 | "from jax.scipy.optimize import minimize\n", 22 | "from jax.config import config\n", 23 | "config.update(\"jax_enable_x64\", True)\n", 24 | "import jax\n", 25 | "from jax.scipy.linalg import cholesky, cho_factor, cho_solve\n", 26 | "from jax.scipy.optimize import minimize\n", 27 | "from jaxopt import ProjectedGradient\n", 28 | "from jaxopt.projection import projection_box\n", 29 | "import pandas as pd" 30 | ] 31 | }, 32 | { 33 | "cell_type": "code", 34 | "execution_count": 2, 35 | "id": "1a79b907", 36 | "metadata": {}, 37 | "outputs": [], 38 | "source": [ 39 | "PCANet = pd.read_csv(\"data/PCA_NS.csv\", header = None).to_numpy()\n", 40 | "DeepONet = pd.read_csv(\"data/DeepONet_NS.csv\", header = None).to_numpy()\n", 41 | "Para = pd.read_csv(\"data/PARA_NS.csv\", header = None).to_numpy()\n", 42 | "FNO = pd.read_csv(\"data/FNO_NS.csv\", header = None).to_numpy()" 43 | ] 44 | }, 45 | { 46 | "cell_type": "code", 47 | "execution_count": 3, 48 | "id": "6c5e4ba4", 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [ 52 | "#The columns = [Nexamples, network width, Train, Test]" 53 | ] 54 | }, 55 | { 56 | "cell_type": "code", 57 | "execution_count": 4, 58 | "id": "a989201f", 59 | "metadata": {}, 60 | "outputs": [], 61 | "source": [ 62 | "Inputs = onp.load('data/StructuralMechanics_inputs.npy')\n", 63 | "Outputs = onp.load('data/StructuralMechanics_outputs.npy')" 64 | ] 65 | }, 66 | { 67 | "cell_type": "code", 68 | "execution_count": 5, 69 | "id": "7d27a7a7", 70 | "metadata": {}, 71 | "outputs": [], 72 | "source": [ 73 | "Inputs = Inputs[:,0,:]\n", 74 | "Outputs = Outputs.transpose((2,1,0))\n", 75 | "Inputs_fl = Inputs.T.reshape(len(Inputs.T), 41)\n", 76 | "Outputs_fl = Outputs.reshape(40000, 41*41)" 77 | ] 78 | }, 79 | { 80 | "cell_type": "markdown", 81 | "id": "d5235802", 82 | "metadata": {}, 83 | "source": [ 84 | "GP regression" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 6, 90 | "id": "74327ec9", 91 | "metadata": {}, 92 | "outputs": [], 93 | "source": [ 94 | "def sqeuclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 95 | " return np.sum( (x - y) ** 2)\n", 96 | "dists = jit(vmap(vmap(sqeuclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 97 | "\n", 98 | "def euclidean_distances(x: np.ndarray, y: np.ndarray) -> float:\n", 99 | " return np.sqrt(np.sum( (x - y) ** 2))\n", 100 | "sqdists = jit(vmap(vmap(euclidean_distances, in_axes=(None, 0)), in_axes=(0, None)))\n", 101 | "\n", 102 | "\n", 103 | "@jit\n", 104 | "def matern(v1, v2, sigma = 50):\n", 105 | " #V1 is a [k1] vector\n", 106 | " #V2 is a [k2] vector\n", 107 | " #returns a k1xk2 matrix\n", 108 | " d = sqdists(v1, v2)\n", 109 | " #return a*np.exp(-d**2/sigma)\n", 110 | " return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 111 | "\n", 112 | "@jit\n", 113 | "def exp(v1, v2, sigma):\n", 114 | " #V1 is a [k1] vector\n", 115 | " #V2 is a [k2] vector\n", 116 | " #returns a k1xk2 matrix\n", 117 | " d = dists(v1, v2)\n", 118 | " return np.exp(-d/sigma)\n", 119 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 120 | "\n", 121 | "@jit\n", 122 | "def iq(v1, v2, sigma):\n", 123 | " #V1 is a [k1] vector\n", 124 | " #V2 is a [k2] vector\n", 125 | " #returns a k1xk2 matrix\n", 126 | " d = dists(v1, v2)\n", 127 | " #return a*np.exp(-d**2/sigma)\n", 128 | " #return (1+np.sqrt(5)*d/sigma +5*d**2/(3*sigma**2))*np.exp(-np.sqrt(5)*d/sigma)\n", 129 | " return 1/np.sqrt(d+sigma)" 130 | ] 131 | }, 132 | { 133 | "cell_type": "code", 134 | "execution_count": 7, 135 | "id": "c53c7c21", 136 | "metadata": {}, 137 | "outputs": [], 138 | "source": [ 139 | "Ntrain = 20000" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": 18, 145 | "id": "c5fb23e6", 146 | "metadata": {}, 147 | "outputs": [], 148 | "source": [ 149 | "Xtr = Inputs_fl[:Ntrain]\n", 150 | "#pca_inp = PCA(n_components=35)\n", 151 | "#Xtr = pca_inp.fit_transform(Xtr)\n", 152 | "#Xtest = pca_inp.transform(Inputs_fl[20000:])\n", 153 | "Xtest = Inputs_fl[20000:]\n", 154 | "\n", 155 | "Ytr = Outputs_fl[:Ntrain]\n", 156 | "pca_out = PCA(n_components=100)\n", 157 | "Ytr = pca_out.fit_transform(Ytr)\n", 158 | "Ytest = pca_out.transform(Outputs_fl[20000:])" 159 | ] 160 | }, 161 | { 162 | "cell_type": "code", 163 | "execution_count": 19, 164 | "id": "5dc9353e", 165 | "metadata": { 166 | "scrolled": false 167 | }, 168 | "outputs": [ 169 | { 170 | "name": "stdout", 171 | "output_type": "stream", 172 | "text": [ 173 | "10000 1e-12\n", 174 | "\n", 175 | " Train error (abs): 4.129879428307515e-08 \n", 176 | " Train error (rel): 1.631668000336936e-11 \n", 177 | " Test error (PCA space, abs): 303.4831191983046 \n", 178 | " Test error (PCA space, rel): 0.11814056211487367 \n", 179 | " Test error (Real space, abs): 305.35767084143157 \n", 180 | " Test error (Real space, rel): 0.11883479738467909 \n", 181 | "---\n", 182 | "50000 1e-12\n", 183 | "\n", 184 | " Train error (abs): 1.625539027115163e-07 \n", 185 | " Train error (rel): 6.684228275448217e-11 \n", 186 | " Test error (PCA space, abs): 286.48962396341915 \n", 187 | " Test error (PCA space, rel): 0.11391309775842931 \n", 188 | " Test error (Real space, abs): 288.4949173470075 \n", 189 | " Test error (Real space, rel): 0.11464589783499701 \n", 190 | "---\n", 191 | "100000 1e-12\n", 192 | "\n", 193 | " Train error (abs): 4.143103960322901e-07 \n", 194 | " Train error (rel): 1.742083355519427e-10 \n", 195 | " Test error (PCA space, abs): 287.8885468466032 \n", 196 | " Test error (PCA space, rel): 0.11536263795851878 \n", 197 | " Test error (Real space, abs): 289.89786767291605 \n", 198 | " Test error (Real space, rel): 0.11609253049269971 \n", 199 | "---\n" 200 | ] 201 | } 202 | ], 203 | "source": [ 204 | "for kernel in [iq]:\n", 205 | " for s in [10000, 50000, 100000]:\n", 206 | " for nugget in [1e-12]:\n", 207 | " k = kernel\n", 208 | " Kxx = k(Xtr, Xtr, s)\n", 209 | " nuggeted_matrix = Kxx.at[np.diag_indices_from(Kxx)].add(nugget)\n", 210 | " L = cho_factor(nuggeted_matrix)\n", 211 | " result = cho_solve(L, Ytr)\n", 212 | " Train_pred = Kxx@result #train predictions\n", 213 | " K_te_tr = k(Xtest, Xtr,s)\n", 214 | " Test_pred = K_te_tr@result #test predictions\n", 215 | "\n", 216 | " aux1 = np.mean(np.linalg.norm(Ytr-Train_pred, axis = 1))\n", 217 | " aux2 = np.mean(np.linalg.norm(Train_pred-Ytr, axis = 1)/np.linalg.norm(Ytr, axis = 1))\n", 218 | " aux3 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1))\n", 219 | " aux4 = np.mean(np.linalg.norm(Ytest-Test_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 220 | "\n", 221 | " true_pred = pca_out.inverse_transform(Test_pred)\n", 222 | " true_ytest = Outputs_fl[20000:]\n", 223 | "\n", 224 | " aux5 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1))\n", 225 | " aux6 = np.mean(np.linalg.norm(true_ytest-true_pred, axis = 1)/np.linalg.norm(Ytest, axis = 1))\n", 226 | "\n", 227 | " print(s, nugget)\n", 228 | " print(\"\\n Train error (abs): {0} \\n Train error (rel): {1} \\n Test error (PCA space, abs): {2} \\n Test error (PCA space, rel): {3} \\n Test error (Real space, abs): {4} \\n Test error (Real space, rel): {5} \".format(aux1, aux2, aux3, aux4, aux5, aux6))\n", 229 | " print('---')" 230 | ] 231 | }, 232 | { 233 | "cell_type": "code", 234 | "execution_count": 43, 235 | "id": "dc3b0fa4", 236 | "metadata": {}, 237 | "outputs": [ 238 | { 239 | "data": { 240 | "text/plain": [ 241 | "DeviceArray(0.47840715, dtype=float64)" 242 | ] 243 | }, 244 | "execution_count": 43, 245 | "metadata": {}, 246 | "output_type": "execute_result" 247 | } 248 | ], 249 | "source": [ 250 | "np.mean(np.linalg.norm(Ytest-np.tile(np.mean(Ytr, axis = 0), (20000, 1)), axis = 1)/np.linalg.norm(Ytest, axis = 1))\n" 251 | ] 252 | }, 253 | { 254 | "cell_type": "code", 255 | "execution_count": 30, 256 | "id": "bd3888fe", 257 | "metadata": {}, 258 | "outputs": [ 259 | { 260 | "data": { 261 | "text/plain": [ 262 | "(20000, 1681)" 263 | ] 264 | }, 265 | "execution_count": 30, 266 | "metadata": {}, 267 | "output_type": "execute_result" 268 | } 269 | ], 270 | "source": [ 271 | "Test_pred.shape" 272 | ] 273 | }, 274 | { 275 | "cell_type": "code", 276 | "execution_count": null, 277 | "id": "2578438f", 278 | "metadata": {}, 279 | "outputs": [], 280 | "source": [] 281 | } 282 | ], 283 | "metadata": { 284 | "kernelspec": { 285 | "display_name": "Python 3 (ipykernel)", 286 | "language": "python", 287 | "name": "python3" 288 | }, 289 | "language_info": { 290 | "codemirror_mode": { 291 | "name": "ipython", 292 | "version": 3 293 | }, 294 | "file_extension": ".py", 295 | "mimetype": "text/x-python", 296 | "name": "python", 297 | "nbconvert_exporter": "python", 298 | "pygments_lexer": "ipython3", 299 | "version": "3.10.4" 300 | } 301 | }, 302 | "nbformat": 4, 303 | "nbformat_minor": 5 304 | } 305 | -------------------------------------------------------------------------------- /HighDataRegime/data/DeepONet_Adv.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,93984.0,0.5070580248489251,1.6189549263542216 2 | 156.0,64.0,155568.0,0.32871913156023735,1.05655180168334 3 | 156.0,128.0,280688.0,0.2606783749183887,0.9833009532472692 4 | 156.0,256.0,678384.0,0.22213076778154234,0.7997425615738476 5 | 156.0,512.0,2.0636e6,0.21050424108552226,0.812098064989847 6 | 312.0,16.0,93984.0,0.4828297177863973,0.8937357900524027 7 | 312.0,64.0,155568.0,0.2970174212435104,0.7599257161720466 8 | 312.0,128.0,280688.0,0.23086576840032252,0.6293243710790005 9 | 312.0,256.0,678384.0,0.18494241982334578,0.589066222274057 10 | 312.0,512.0,2.0636e6,0.19701723237384777,0.5579974212453305 11 | 625.0,16.0,93984.0,0.43298696261339126,0.5313266016900908 12 | 625.0,64.0,155568.0,0.2631497661524192,0.4134477063990766 13 | 625.0,128.0,280688.0,0.20069787008685003,0.3675204990011779 14 | 625.0,256.0,678384.0,0.17377767621363227,0.341175346198033 15 | 625.0,512.0,2.0636e6,0.16269238388969665,0.3079901534920736 16 | 1250.0,16.0,93984.0,0.42307395906430395,0.4280699948288257 17 | 1250.0,64.0,155568.0,0.23294048914977353,0.2677328089642323 18 | 1250.0,128.0,280688.0,0.17600211564692708,0.23835284569033693 19 | 1250.0,256.0,678384.0,0.15419882031211463,0.22262201754015723 20 | 1250.0,512.0,2.0636e6,0.14989769193582542,0.20782632134121376 21 | 2500.0,16.0,93984.0,0.34443226320742926,0.34953051365985766 22 | 2500.0,64.0,155568.0,0.20569867654672117,0.2184996732720151 23 | 2500.0,128.0,280688.0,0.1635424020233522,0.1923301554094833 24 | 2500.0,256.0,678384.0,0.13727318342908684,0.1826352111262968 25 | 2500.0,512.0,2.0636e6,0.142441122510508,0.17971471014935514 26 | 5000.0,16.0,93984.0,0.3390015311176906,0.339854837990065 27 | 5000.0,64.0,155568.0,0.19125903806697445,0.19462081525486363 28 | 5000.0,128.0,280688.0,0.15178129141255828,0.17090106431329896 29 | 5000.0,256.0,678384.0,0.1256369182009571,0.1629317373210825 30 | 5000.0,512.0,2.0636e6,0.12829018558872063,0.16149004169295325 31 | 10000.0,16.0,93984.0,0.31485445315516086,0.3147192442972554 32 | 10000.0,64.0,155568.0,0.1754354707417321,0.17691830407099424 33 | 10000.0,128.0,280688.0,0.13959321318814621,0.1595090071011537 34 | 10000.0,256.0,678384.0,0.12371872580493146,0.15864968584320482 35 | 10000.0,512.0,2.0636e6,0.1186759055943948,0.1524074389194938 36 | 20000.0,16.0,93984.0,0.2818526103174339,0.2824034516936106 37 | 20000.0,64.0,155568.0,0.17532498957747206,0.17641142396665413 38 | 20000.0,128.0,280688.0,0.1412348384360671,0.1534566701805047 39 | 20000.0,256.0,678384.0,0.12131616487757463,0.15380293653956004 40 | 20000.0,512.0,2.0636e6,0.126880080082424,0.1540948772027392 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/DeepONet_Helmhotz.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,2.381548e6,0.4464179367924748,0.47541716934985717 2 | 156.0,64.0,3.393724e6,0.35746061405267426,0.4167513778516056 3 | 156.0,128.0,4.7863e6,0.3839609759547692,0.4296086427925428 4 | 156.0,256.0,7.718908e6,0.3019464664746078,0.38519306575751916 5 | 156.0,512.0,1.4173948e7,0.35175939888296315,0.4056213926400919 6 | 312.0,16.0,2.381548e6,0.45931304168560727,0.48314408749043264 7 | 312.0,64.0,3.393724e6,0.32141494919159225,0.3533587671746104 8 | 312.0,128.0,4.7863e6,0.3204343121407505,0.3594690754479747 9 | 312.0,256.0,7.718908e6,0.29090380464091353,0.3173899191587519 10 | 312.0,512.0,1.4173948e7,0.3066088626685617,0.33744121300799734 11 | 625.0,16.0,2.381548e6,0.47156451904542035,0.46180417737571516 12 | 625.0,64.0,3.393724e6,0.3065137842554645,0.3097638061930632 13 | 625.0,128.0,4.7863e6,0.2799988480912917,0.2840206588874471 14 | 625.0,256.0,7.718908e6,0.2711628961935042,0.28210667581498283 15 | 625.0,512.0,1.4173948e7,0.25767508316060495,0.2698821562024787 16 | 1250.0,16.0,2.381548e6,0.46627495697105725,0.46493348990784805 17 | 1250.0,64.0,3.393724e6,0.28335454628147383,0.2854612054008432 18 | 1250.0,128.0,4.7863e6,0.2153513062418223,0.22269598693738535 19 | 1250.0,256.0,7.718908e6,0.19615720652755342,0.20331844136662375 20 | 1250.0,512.0,1.4173948e7,0.1774973428481402,0.18671867431769476 21 | 2500.0,16.0,2.381548e6,0.4655908506979233,0.4661885415738167 22 | 2500.0,64.0,3.393724e6,0.24696639017282004,0.2522520568525474 23 | 2500.0,128.0,4.7863e6,0.17400965610062152,0.18316958643138703 24 | 2500.0,256.0,7.718908e6,0.1675875580998187,0.17547286554615343 25 | 2500.0,512.0,1.4173948e7,0.1476300629499529,0.15540660637168516 26 | 5000.0,16.0,2.381548e6,0.4658888596162364,0.46342068192518526 27 | 5000.0,64.0,3.393724e6,0.17591487814063075,0.17941539221363215 28 | 5000.0,128.0,4.7863e6,0.17062648409596815,0.17460166554118958 29 | 5000.0,256.0,7.718908e6,0.14499696063209172,0.14981931294043124 30 | 5000.0,512.0,1.4173948e7,0.14590352048653632,0.15024389622113962 31 | 10000.0,16.0,2.381548e6,0.4646090341207693,0.462664085695401 32 | 10000.0,64.0,3.393724e6,0.16442925358431773,0.16427412723819834 33 | 10000.0,128.0,4.7863e6,0.1531700066717697,0.15425525411299607 34 | 10000.0,256.0,7.718908e6,0.12455106665159268,0.12622178420420432 35 | 10000.0,512.0,1.4173948e7,0.08498476539159071,0.08746846598757073 36 | 20000.0,16.0,2.381548e6,0.46355517363663096,0.46395605592177863 37 | 20000.0,64.0,3.393724e6,0.15065822115253055,0.15109945741687988 38 | 20000.0,128.0,4.7863e6,0.10980380286726128,0.1106621605432007 39 | 20000.0,256.0,7.718908e6,0.08820359453020912,0.08939091588388164 40 | 20000.0,512.0,1.4173948e7,0.05695118218513826,0.05882818892277169 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/DeepONet_NS.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,1.181104e6,0.6823236037995135,1.0965994258088223 2 | 156.0,64.0,1.609792e6,0.22332388843052683,0.8685441901822833 3 | 156.0,128.0,2.224384e6,0.13788389818369423,0.7217327642810997 4 | 156.0,256.0,3.601024e6,0.0926387926888328,0.6270829225776512 5 | 156.0,512.0,6.944128e6,0.11959660024045686,0.6124303985625325 6 | 312.0,16.0,1.181104e6,0.5920918415620254,0.7132703193464228 7 | 312.0,64.0,1.609792e6,0.20438609611081196,0.5916774049906257 8 | 312.0,128.0,2.224384e6,0.10547281394364656,0.4873756682449709 9 | 312.0,256.0,3.601024e6,0.06358655652570984,0.39945583181483313 10 | 312.0,512.0,6.944128e6,0.08633713718451563,0.3363341079048183 11 | 625.0,16.0,1.181104e6,0.505488787180168,0.5125248732928046 12 | 625.0,64.0,1.609792e6,0.18731977969516037,0.321295130258568 13 | 625.0,128.0,2.224384e6,0.08938945211160969,0.36520905045410174 14 | 625.0,256.0,3.601024e6,0.049705610314521066,0.29954551132510143 15 | 625.0,512.0,6.944128e6,0.04729276596314312,0.24727751635001988 16 | 1250.0,16.0,1.181104e6,0.48375488633763053,0.48802059716270585 17 | 1250.0,64.0,1.609792e6,0.1463045225320293,0.16121094726135068 18 | 1250.0,128.0,2.224384e6,0.09054544032860942,0.18562608901755462 19 | 1250.0,256.0,3.601024e6,0.05281790836345452,0.21806865859666133 20 | 1250.0,512.0,6.944128e6,0.04544998746006488,0.17450553353410342 21 | 2500.0,16.0,1.181104e6,0.4449047468628387,0.4483444513676299 22 | 2500.0,64.0,1.609792e6,0.11664017523614394,0.12329129833723948 23 | 2500.0,128.0,2.224384e6,0.0651567139043255,0.0783663627736766 24 | 2500.0,256.0,3.601024e6,0.04941679620912793,0.10260458796460414 25 | 2500.0,512.0,6.944128e6,0.046842023801196356,0.11638213968757355 26 | 5000.0,16.0,1.181104e6,0.44060786051061207,0.4468531587113586 27 | 5000.0,64.0,1.609792e6,0.10384854525693495,0.10765609765628274 28 | 5000.0,128.0,2.224384e6,0.05923312147415374,0.06496502959565158 29 | 5000.0,256.0,3.601024e6,0.03945328447453681,0.04864137469300518 30 | 5000.0,512.0,6.944128e6,0.0679997757933887,0.07808885045365166 31 | 10000.0,16.0,1.181104e6,0.4408954004181099,0.4437397361818173 32 | 10000.0,64.0,1.609792e6,0.09654046071748165,0.0982182973525812 33 | 10000.0,128.0,2.224384e6,0.05224020509405385,0.05517650146380279 34 | 10000.0,256.0,3.601024e6,0.03677390596071996,0.04110120931348545 35 | 10000.0,512.0,6.944128e6,0.05021867729921666,0.05299066989203525 36 | 20000.0,16.0,1.181104e6,0.41246251132533335,0.4121163467766536 37 | 20000.0,64.0,1.609792e6,0.0870199999205234,0.08764693351758904 38 | 20000.0,128.0,2.224384e6,0.05090797087191457,0.05247415834110915 39 | 20000.0,256.0,3.601024e6,0.034273759354919914,0.03629471638135709 40 | 20000.0,512.0,6.944128e6,0.04030919341495455,0.04193620966281372 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/DeepONet_Solid.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,124948.0,0.14262153473786143,0.20911700972455477 2 | 156.0,64.0,311524.0,0.0825461629468253,0.19916936629656584 3 | 156.0,128.0,603300.0,0.0641641532454597,0.16563255786773382 4 | 156.0,256.0,1.334308e6,0.044255925081537216,0.15127393976307635 5 | 156.0,512.0,3.386148e6,0.03811256536137279,0.14573781939613803 6 | 312.0,16.0,124948.0,0.14343064570456243,0.16446094056008415 7 | 312.0,64.0,311524.0,0.07178047815061973,0.14051986776538725 8 | 312.0,128.0,603300.0,0.0501239646953582,0.12588693831756098 9 | 312.0,256.0,1.334308e6,0.03367887659480562,0.12146449232378018 10 | 312.0,512.0,3.386148e6,0.033550645716084626,0.11555347780650226 11 | 625.0,16.0,124948.0,0.1333004665686784,0.14259541545274743 12 | 625.0,64.0,311524.0,0.06316670217364806,0.1111525155887363 13 | 625.0,128.0,603300.0,0.04136898984351309,0.10405714732813212 14 | 625.0,256.0,1.334308e6,0.024995251338080646,0.10021888340633221 15 | 625.0,512.0,3.386148e6,0.02456987712904521,0.09220676893161515 16 | 1250.0,16.0,124948.0,0.11216805347881273,0.11420346606112022 17 | 1250.0,64.0,311524.0,0.05779067057862701,0.08695544034015643 18 | 1250.0,128.0,603300.0,0.03455626561063574,0.08472193283425433 19 | 1250.0,256.0,1.334308e6,0.020715468874403977,0.07933179702239943 20 | 1250.0,512.0,3.386148e6,0.017953511095994305,0.07584540043217332 21 | 2500.0,16.0,124948.0,0.10080369414676142,0.10171799749855132 22 | 2500.0,64.0,311524.0,0.054940701752072246,0.07135116663367723 23 | 2500.0,128.0,603300.0,0.03201521595577919,0.07287209885152629 24 | 2500.0,256.0,1.334308e6,0.018432590252114155,0.07110235271260323 25 | 2500.0,512.0,3.386148e6,0.015496711897852357,0.06732758228280428 26 | 5000.0,16.0,124948.0,0.10067461807061681,0.10119316827304131 27 | 5000.0,64.0,311524.0,0.052689070700674814,0.06161910728686778 28 | 5000.0,128.0,603300.0,0.034052042605518966,0.06608319049336267 29 | 5000.0,256.0,1.334308e6,0.021703010813491578,0.06740272601048589 30 | 5000.0,512.0,3.386148e6,0.017313206604374368,0.06580866265873055 31 | 10000.0,16.0,124948.0,0.09629186957432598,0.09650476270208726 32 | 10000.0,64.0,311524.0,0.051094177404038627,0.05535873675459766 33 | 10000.0,128.0,603300.0,0.03697136997184957,0.0595448008144785 34 | 10000.0,256.0,1.334308e6,0.02800886536647485,0.06303770903394633 35 | 10000.0,512.0,3.386148e6,0.020595466556320857,0.06386476327391244 36 | 20000.0,16.0,124948.0,0.08214447922175039,0.0824746149540089 37 | 20000.0,64.0,311524.0,0.05029818244161458,0.052014380370673234 38 | 20000.0,128.0,603300.0,0.04050047397807624,0.052232461655715316 39 | 20000.0,256.0,1.334308e6,0.03114209951595663,0.05872446339965451 40 | 20000.0,512.0,3.386148e6,0.02250886706988622,0.06377522281721379 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/FNO_Adv.csv: -------------------------------------------------------------------------------- 1 | 156.0,2.0,70195.80839857644,0.2051168642938137,0.21406275731248733 2 | 156.0,4.0,150567.61679715288,0.21156492752906603,0.2198023907840252 3 | 156.0,8.0,341839.23359430576,0.13471204567796144,0.1494840533974079 4 | 156.0,16.0,846494.4671886114,0.12607009470080718,0.15144135707463974 5 | 156.0,32.0,2.344252934377223e6,0.11370245087891817,0.16165934355022052 6 | 312.0,2.0,70195.80839857644,0.19108589361302364,0.19073670137769136 7 | 312.0,4.0,150567.61679715288,0.14754398847715214,0.14888319387458837 8 | 312.0,8.0,341839.23359430576,0.1352646030151309,0.14089221532384938 9 | 312.0,16.0,846494.4671886114,0.1294010821968699,0.1423940741074964 10 | 312.0,32.0,2.344252934377223e6,0.10910749247966287,0.15440682837596306 11 | 625.0,2.0,70195.80839857644,0.17426703526973725,0.17689754164218902 12 | 625.0,4.0,150567.61679715288,0.13767674671411514,0.14177297602891922 13 | 625.0,8.0,341839.23359430576,0.13417764952778816,0.14181496809124947 14 | 625.0,16.0,846494.4671886114,0.12538815760016442,0.14485083962082862 15 | 625.0,32.0,2.344252934377223e6,0.11140193836688995,0.15564713965654373 16 | 1250.0,2.0,70195.80839857644,0.16731160047650337,0.1655568196117878 17 | 1250.0,4.0,150567.61679715288,0.1384904202580452,0.13728790825009346 18 | 1250.0,8.0,341839.23359430576,0.13437056879997253,0.13791822636425496 19 | 1250.0,16.0,846494.4671886114,0.1284076879411936,0.14177002581655979 20 | 1250.0,32.0,2.344252934377223e6,0.10854364714026452,0.16034921472370625 21 | 2500.0,2.0,70195.80839857644,0.1594782737880945,0.16085675894320012 22 | 2500.0,4.0,150567.61679715288,0.14385600249767302,0.14574280208349227 23 | 2500.0,8.0,341839.23359430576,0.13498388704657555,0.1389519686192274 24 | 2500.0,16.0,846494.4671886114,0.12913804715573787,0.14208188624978066 25 | 2500.0,32.0,2.344252934377223e6,0.10941157456636429,0.16408271417617798 26 | 5000.0,2.0,70195.80839857644,0.1548476398691535,0.15462387750148773 27 | 5000.0,4.0,150567.61679715288,0.13682951852232217,0.13707658811956644 28 | 5000.0,8.0,341839.23359430576,0.135198894803226,0.1363590141147375 29 | 5000.0,16.0,846494.4671886114,0.12994978654012085,0.14053343777284028 30 | 5000.0,32.0,2.344252934377223e6,0.11144432251080871,0.1603648282378912 31 | 10000.0,2.0,70195.80839857644,0.13867879876121877,0.13827973230853677 32 | 10000.0,4.0,150567.61679715288,0.13617397269681097,0.13611278236731886 33 | 10000.0,8.0,341839.23359430576,0.13506276313066481,0.13575140339285136 34 | 10000.0,16.0,846494.4671886114,0.1310804683532566,0.13813221438005566 35 | 10000.0,32.0,2.344252934377223e6,0.11997361319586634,0.1501739291805774 36 | 20000.0,2.0,70195.80839857644,0.14910044556483626,0.14937098366469145 37 | 20000.0,4.0,150567.61679715288,0.13602104738764464,0.13615077067576348 38 | 20000.0,8.0,341839.23359430576,0.13453743835501372,0.13488332782052456 39 | 20000.0,16.0,846494.4671886114,0.1322681881096214,0.13639375850073993 40 | 20000.0,32.0,2.344252934377223e6,0.12491583560388535,0.1448642684707418 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/FNO_Helmhotz.csv: -------------------------------------------------------------------------------- 1 | 156.0,2.0,5.978485327075723e6,0.22632910741063264,0.24231149943975303 2 | 156.0,4.0,1.2453530654151445e7,0.13260126968797964,0.1635531785014348 3 | 156.0,8.0,2.6893301308302894e7,0.08721543750606287,0.13635566673026636 4 | 156.0,16.0,6.173156261660579e7,0.03797176885060393,0.11769932011763255 5 | 156.0,32.0,1.5524296523321158e8,0.020320030639712244,0.12663329841616827 6 | 312.0,2.0,5.978485327075723e6,0.16222083845581764,0.17689555167005613 7 | 312.0,4.0,1.2453530654151445e7,0.10263211824573003,0.1271524697016829 8 | 312.0,8.0,2.6893301308302894e7,0.07378061165889868,0.10832725102320695 9 | 312.0,16.0,6.173156261660579e7,0.034385983038168304,0.08949016204151587 10 | 312.0,32.0,1.5524296523321158e8,0.019688175827002104,0.10027602196742709 11 | 625.0,2.0,5.978485327075723e6,0.13771168867349626,0.14206319049596786 12 | 625.0,4.0,1.2453530654151445e7,0.08766238362193107,0.098838044911623 13 | 625.0,8.0,2.6893301308302894e7,0.061962609326839446,0.0818267064332962 14 | 625.0,16.0,6.173156261660579e7,0.03160615977942943,0.06439979311525822 15 | 625.0,32.0,1.5524296523321158e8,0.017547413294017315,0.06920490819513797 16 | 1250.0,2.0,5.978485327075723e6,0.12329470276236534,0.12581499956250192 17 | 1250.0,4.0,1.2453530654151445e7,0.07679203314483166,0.08271237556934356 18 | 1250.0,8.0,2.6893301308302894e7,0.054882411889731884,0.0645092890381813 19 | 1250.0,16.0,6.173156261660579e7,0.028927531659603118,0.046320013728737834 20 | 1250.0,32.0,1.5524296523321158e8,0.01757366208508611,0.0428986438959837 21 | 2500.0,2.0,5.978485327075723e6,0.11154323557317257,0.1136949557095766 22 | 2500.0,4.0,1.2453530654151445e7,0.06699073839783669,0.07028259042799473 23 | 2500.0,8.0,2.6893301308302894e7,0.04737173019126058,0.05268851287215948 24 | 2500.0,16.0,6.173156261660579e7,0.02695343062542379,0.035876765291020275 25 | 2500.0,32.0,1.5524296523321158e8,0.01672629150226712,0.02989988396503031 26 | 5000.0,2.0,5.978485327075723e6,0.10022655726522207,0.10152929573506117 27 | 5000.0,4.0,1.2453530654151445e7,0.05939052623361349,0.06136104569360614 28 | 5000.0,8.0,2.6893301308302894e7,0.040165199933573606,0.042902923982962964 29 | 5000.0,16.0,6.173156261660579e7,0.023075358336791398,0.02736391989812255 30 | 5000.0,32.0,1.5524296523321158e8,0.01683697405625135,0.022943896873109042 31 | 10000.0,2.0,5.978485327075723e6,0.09094001621566714,0.09083860254622995 32 | 10000.0,4.0,1.2453530654151445e7,0.05260641264431178,0.05306467284243554 33 | 10000.0,8.0,2.6893301308302894e7,0.0348694276239723,0.03589802196566016 34 | 10000.0,16.0,6.173156261660579e7,0.021710383084602655,0.023609937405772507 35 | 10000.0,32.0,1.5524296523321158e8,0.01737685339199379,0.020028879312239588 36 | 20000.0,2.0,5.978485327075723e6,0.08456324730440974,0.08493604139201343 37 | 20000.0,4.0,1.2453530654151445e7,0.04989414618192241,0.05039579219762236 38 | 20000.0,8.0,2.6893301308302894e7,0.03147153898780234,0.03227179053444415 39 | 20000.0,16.0,6.173156261660579e7,0.021153421758906915,0.02219181383489631 40 | 20000.0,32.0,1.5524296523321158e8,0.01739364651220385,0.018643237187713383 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/FNO_NS.csv: -------------------------------------------------------------------------------- 1 | 156.0,2.0,2.177838213132946e6,0.12436639665602109,0.13066622557548377 2 | 156.0,4.0,4.559196426265892e6,0.06956763384051812,0.07543512085118355 3 | 156.0,8.0,9.932472852531783e6,0.035967720015786395,0.04621080514521171 4 | 156.0,16.0,2.3121265705063567e7,0.01666304794474481,0.029567214731986705 5 | 156.0,32.0,5.926781141012713e7,0.007460149685637309,0.02202051191423566 6 | 312.0,2.0,2.177838213132946e6,0.09304173699078652,0.09686619272598854 7 | 312.0,4.0,4.559196426265892e6,0.052950446613323994,0.05743772924567262 8 | 312.0,8.0,9.932472852531783e6,0.023300011928838033,0.02844143126350947 9 | 312.0,16.0,2.3121265705063567e7,0.011953431760701232,0.017981786245050337 10 | 312.0,32.0,5.926781141012713e7,0.0062185149021948185,0.013566786978537073 11 | 625.0,2.0,2.177838213132946e6,0.07174551630020141,0.0725860321700573 12 | 625.0,4.0,4.559196426265892e6,0.040638938769698145,0.04202167872786522 13 | 625.0,8.0,9.932472852531783e6,0.01732669576704502,0.01928133088797331 14 | 625.0,16.0,2.3121265705063567e7,0.008977463494241238,0.011373279851675034 15 | 625.0,32.0,5.926781141012713e7,0.005009095503389836,0.007428740917891264 16 | 1250.0,2.0,2.177838213132946e6,0.062377307346463205,0.06331759619414806 17 | 1250.0,4.0,4.559196426265892e6,0.027120942832529544,0.027775928173959255 18 | 1250.0,8.0,9.932472852531783e6,0.013605309657007457,0.014367855332791805 19 | 1250.0,16.0,2.3121265705063567e7,0.006122434207797051,0.006938581191003323 20 | 1250.0,32.0,5.926781141012713e7,0.004148121610470117,0.00499350701905787 21 | 2500.0,2.0,2.177838213132946e6,0.05801520475000143,0.058439082188904284 22 | 2500.0,4.0,4.559196426265892e6,0.022661587482318283,0.023031392083317042 23 | 2500.0,8.0,9.932472852531783e6,0.010777731089293956,0.01120716875307262 24 | 2500.0,16.0,2.3121265705063567e7,0.00485314907040447,0.005212976129446179 25 | 2500.0,32.0,5.926781141012713e7,0.0033382658204063774,0.003755237498879433 26 | 5000.0,2.0,2.177838213132946e6,0.05336691351011395,0.05325734074227512 27 | 5000.0,4.0,4.559196426265892e6,0.01891608584355563,0.01904977576266974 28 | 5000.0,8.0,9.932472852531783e6,0.0091022975564003,0.009284027730487287 29 | 5000.0,16.0,2.3121265705063567e7,0.003979922512639314,0.0041198300197254865 30 | 5000.0,32.0,5.926781141012713e7,0.002780657776235603,0.0029334558861330152 31 | 10000.0,2.0,2.177838213132946e6,0.04603272743150592,0.04622506144270301 32 | 10000.0,4.0,4.559196426265892e6,0.016235519807599484,0.01630803159205243 33 | 10000.0,8.0,9.932472852531783e6,0.007495516244694591,0.007584054466942325 34 | 10000.0,16.0,2.3121265705063567e7,0.003504203468747437,0.003573085482767783 35 | 10000.0,32.0,5.926781141012713e7,0.0027884209246723914,0.0028631170742446557 36 | 20000.0,2.0,2.177838213132946e6,0.041023037175182256,0.041140878275502474 37 | 20000.0,4.0,4.559196426265892e6,0.014811816173791886,0.014898816977767274 38 | 20000.0,8.0,9.932472852531783e6,0.006966772340424359,0.00701965861315839 39 | 20000.0,16.0,2.3121265705063567e7,0.003113048084039474,0.003160468403308187 40 | 20000.0,32.0,5.926781141012713e7,0.0025544390789524187,0.002595855883444892 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/FNO_Solid.csv: -------------------------------------------------------------------------------- 1 | 156.0,2.0,805485.7572955929,0.14119735070929545,0.15283161331205306 2 | 156.0,4.0,1.6985715145911858e6,0.08821194992584382,0.10060368402794302 3 | 156.0,8.0,3.7475430291823717e6,0.0664915235320525,0.08040180917582768 4 | 156.0,16.0,8.896686058364743e6,0.04738861909726549,0.0715617746625178 5 | 156.0,32.0,2.3399772116729487e7,0.02808841156366247,0.07992962591566488 6 | 312.0,2.0,805485.7572955929,0.11640860209777902,0.12471997902320123 7 | 312.0,4.0,1.6985715145911858e6,0.07651077437339676,0.08323361486102189 8 | 312.0,8.0,3.7475430291823717e6,0.057695854106178106,0.06603520537563604 9 | 312.0,16.0,8.896686058364743e6,0.046071932838175636,0.0618151709502102 10 | 312.0,32.0,2.3399772116729487e7,0.028054297203132704,0.07172296575929113 11 | 625.0,2.0,805485.7572955929,0.09495625825555813,0.09841053815758341 12 | 625.0,4.0,1.6985715145911858e6,0.06789910343100687,0.07157184604417512 13 | 625.0,8.0,3.7475430291823717e6,0.05433669396999876,0.05960409784227043 14 | 625.0,16.0,8.896686058364743e6,0.04557078322095342,0.05674212831048107 15 | 625.0,32.0,2.3399772116729487e7,0.02732857211247553,0.06899905256346697 16 | 1250.0,2.0,805485.7572955929,0.08181817560744718,0.08382295663483855 17 | 1250.0,4.0,1.6985715145911858e6,0.061266241239100454,0.06272610994031283 18 | 1250.0,8.0,3.7475430291823717e6,0.051663337110649944,0.054689355249941334 19 | 1250.0,16.0,8.896686058364743e6,0.04549468411990174,0.053278403683997735 20 | 1250.0,32.0,2.3399772116729487e7,0.025817531236422782,0.06621926759983425 21 | 2500.0,2.0,805485.7572955929,0.07599307824860009,0.07666797837839674 22 | 2500.0,4.0,1.6985715145911858e6,0.056172241412513986,0.056329471908447816 23 | 2500.0,8.0,3.7475430291823717e6,0.050007435169493075,0.05133682108823732 24 | 2500.0,16.0,8.896686058364743e6,0.04552116323012916,0.05005622242543262 25 | 2500.0,32.0,2.3399772116729487e7,0.0259079136255971,0.0649240225185117 26 | 5000.0,2.0,805485.7572955929,0.07141254727111314,0.07202433166355708 27 | 5000.0,4.0,1.6985715145911858e6,0.05361121337721645,0.05423441624007733 28 | 5000.0,8.0,3.7475430291823717e6,0.04895213998966112,0.05038707752830543 29 | 5000.0,16.0,8.896686058364743e6,0.045471842966358575,0.04936140818035211 30 | 5000.0,32.0,2.3399772116729487e7,0.02685957809776686,0.06417689955606036 31 | 10000.0,2.0,805485.7572955929,0.06827087966093963,0.0686533351351791 32 | 10000.0,4.0,1.6985715145911858e6,0.052276930350490365,0.05250929729672855 33 | 10000.0,8.0,3.7475430291823717e6,0.048584533766965164,0.04937707534129941 34 | 10000.0,16.0,8.896686058364743e6,0.045895826265823086,0.04835732645531449 35 | 10000.0,32.0,2.3399772116729487e7,0.028286067445906383,0.06390062176944342 36 | 20000.0,2.0,805485.7572955929,0.06587055339678079,0.06628692344279258 37 | 20000.0,4.0,1.6985715145911858e6,0.051385963678418696,0.051745504267111345 38 | 20000.0,8.0,3.7475430291823717e6,0.04801212470325045,0.0486230481086057 39 | 20000.0,16.0,8.896686058364743e6,0.046243011141379624,0.0476537741173857 40 | 20000.0,32.0,2.3399772116729487e7,0.031084406545032556,0.06326041158253722 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PARA_Adv.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,1.587e6,0.26762557309627255,10.567036352369554 2 | 156.0,64.0,8.5662e6,0.22871510111268242,5.051620374844744 3 | 156.0,128.0,2.36062e7,0.22316206109768727,2.428105823731627 4 | 156.0,256.0,7.3347e7,0.2037239725826691,1.247770079930493 5 | 156.0,512.0,2.514718e8,0.19134236082736825,1.2310723634497105 6 | 312.0,16.0,1.587e6,0.34807542249653095,2.56904571069103 7 | 312.0,64.0,8.5662e6,0.22759407907858623,1.8656539839038173 8 | 312.0,128.0,2.36062e7,0.2228739292529412,1.2377686059868398 9 | 312.0,256.0,7.3347e7,0.19699755814187636,0.9336052197877641 10 | 312.0,512.0,2.514718e8,0.18817812997884098,0.8444843272033618 11 | 625.0,16.0,1.587e6,0.22156512484489194,0.849356584652454 12 | 625.0,64.0,8.5662e6,0.19877872260630947,0.8350517037576246 13 | 625.0,128.0,2.36062e7,0.2033529973759153,0.7162350142261116 14 | 625.0,256.0,7.3347e7,0.17583636190051297,0.5982148373186592 15 | 625.0,512.0,2.514718e8,0.17841499435441988,0.5895871621781661 16 | 1250.0,16.0,1.587e6,0.21027730502993128,0.4907082794919668 17 | 1250.0,64.0,8.5662e6,0.16518972108805097,0.52652695437646 18 | 1250.0,128.0,2.36062e7,0.16261006510116932,0.4575275881074447 19 | 1250.0,256.0,7.3347e7,0.1647856129194096,0.4064735011136244 20 | 1250.0,512.0,2.514718e8,0.16059090954537034,0.40761957854180036 21 | 2500.0,16.0,1.587e6,0.20639510082715798,0.32398266195456715 22 | 2500.0,64.0,8.5662e6,0.14981098224826628,0.3815895700807757 23 | 2500.0,128.0,2.36062e7,0.13859260792424988,0.3253177858931568 24 | 2500.0,256.0,7.3347e7,0.1376911985317166,0.31370981848926477 25 | 2500.0,512.0,2.514718e8,0.1400510848122096,0.30180196308948837 26 | 5000.0,16.0,1.587e6,0.19055711923265867,0.22876288245332427 27 | 5000.0,64.0,8.5662e6,0.140744880128135,0.26782993190745713 28 | 5000.0,128.0,2.36062e7,0.13022641055224213,0.25138773938080056 29 | 5000.0,256.0,7.3347e7,0.12813148382959771,0.249383753223002 30 | 5000.0,512.0,2.514718e8,0.11914794570625588,0.233556070282211 31 | 10000.0,16.0,1.587e6,0.17818617510566212,0.18938821704508652 32 | 10000.0,64.0,8.5662e6,0.13537191187042774,0.20500198815404946 33 | 10000.0,128.0,2.36062e7,0.1179429144528301,0.2133090602045811 34 | 10000.0,256.0,7.3347e7,0.11286498847465651,0.20326229111377805 35 | 10000.0,512.0,2.514718e8,0.11133452466670658,0.19839667703581082 36 | 20000.0,16.0,1.587e6,0.1657959197563843,0.1713110576132001 37 | 20000.0,64.0,8.5662e6,0.1341554075674926,0.16459538628063677 38 | 20000.0,128.0,2.36062e7,0.11983618958668557,0.17752374839594073 39 | 20000.0,256.0,7.3347e7,0.10621718390607414,0.17848990209261975 40 | 20000.0,512.0,2.514718e8,0.1049167472534716,0.17596032934323255 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PARA_Helmhotz.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,4.6618469e7,0.7126512366618195,1.47183176192018 2 | 156.0,64.0,3.05642261e8,0.4014240255523844,1.9307405343174797 3 | 156.0,128.0,9.43490389e8,0.29818599336394586,1.8535062023392141 4 | 156.0,256.0,3.221985749e9,0.25854730972704243,2.6145162190622786 5 | 156.0,512.0,1.1790172885e10,0.24334716050852123,2.0554503202498724 6 | 312.0,16.0,4.6618469e7,0.5706882380930323,0.5863699432265533 7 | 312.0,64.0,3.05642261e8,0.3549385494012768,0.5529809403308175 8 | 312.0,128.0,9.43490389e8,0.23814148353263684,0.7958855690157927 9 | 312.0,256.0,3.221985749e9,0.22242582162882046,0.699106053083085 10 | 312.0,512.0,1.1790172885e10,0.15758445317758418,0.6183862025222118 11 | 625.0,16.0,4.6618469e7,0.6513559355910014,0.6515685315380557 12 | 625.0,64.0,3.05642261e8,0.22669844962701854,0.23425402926925876 13 | 625.0,128.0,9.43490389e8,0.21787156930582285,0.24740592155101485 14 | 625.0,256.0,3.221985749e9,0.18751620137259592,0.32231456032835626 15 | 625.0,512.0,1.1790172885e10,0.1549988703188558,0.2406247990078411 16 | 1250.0,16.0,4.6618469e7,0.521464963763346,0.5220406685522744 17 | 1250.0,64.0,3.05642261e8,0.23307308505087776,0.23633505515503284 18 | 1250.0,128.0,9.43490389e8,0.184936649202395,0.1902694393267026 19 | 1250.0,256.0,3.221985749e9,0.16308071644282424,0.17047908967137265 20 | 1250.0,512.0,1.1790172885e10,0.12746974134632616,0.13536599731104815 21 | 2500.0,16.0,4.6618469e7,0.6151673875147791,0.6163234339399811 22 | 2500.0,64.0,3.05642261e8,0.2447026268580481,0.24752377352819085 23 | 2500.0,128.0,9.43490389e8,0.19097965063380026,0.19363025115228152 24 | 2500.0,256.0,3.221985749e9,0.15411355969897303,0.1575513064033845 25 | 2500.0,512.0,1.1790172885e10,0.15479058142828084,0.1576683676565604 26 | 5000.0,16.0,4.6618469e7,0.5048633122636637,0.5048819360949051 27 | 5000.0,64.0,3.05642261e8,0.20671027915524745,0.20746721101675888 28 | 5000.0,128.0,9.43490389e8,0.15554094887762704,0.15667619438842628 29 | 5000.0,256.0,3.221985749e9,0.13763967561289975,0.1389181887152601 30 | 5000.0,512.0,1.1790172885e10,0.12401528243369539,0.1254281162561009 31 | 10000.0,16.0,4.6618469e7,0.5087282171844346,0.5075781060132977 32 | 10000.0,64.0,3.05642261e8,0.24469978815730478,0.2439626767301628 33 | 10000.0,128.0,9.43490389e8,0.18264840425115622,0.1823825183847716 34 | 10000.0,256.0,3.221985749e9,0.16628656585161194,0.16598296839316973 35 | 10000.0,512.0,1.1790172885e10,0.17347573267095162,0.17322422615312505 36 | 10000.0,16.0,4.6618469e7,0.5087282171844346,0.5075781060132977 37 | 10000.0,64.0,3.05642261e8,0.24469978815730478,0.2439626767301628 38 | 10000.0,128.0,9.43490389e8,0.18264840425115622,0.1823825183847716 39 | 10000.0,256.0,3.221985749e9,0.16628656585161194,0.16598296839316973 40 | 10000.0,512.0,1.1790172885e10,0.17347573267095162,0.17322422615312505 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PARA_NS.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,2.247872e7,0.4817009113503805,4.26485847731814 2 | 156.0,64.0,1.37101184e8,0.15920813520008936,8.016100511498273 3 | 156.0,128.0,4.07371648e8,0.09173316487379266,5.252461691140093 4 | 156.0,256.0,1.35056576e9,0.06186147816100523,2.475510719407746 5 | 156.0,512.0,4.84756672e9,0.07237383394187444,1.3392683749715506 6 | 312.0,16.0,2.247872e7,0.579911428751994,1.7362415424110673 7 | 312.0,64.0,1.37101184e8,0.219174605677275,5.573088372403878 8 | 312.0,128.0,4.07371648e8,0.17098124221618433,3.9123777827317143 9 | 312.0,256.0,1.35056576e9,0.07398615947722617,1.8569723013434924 10 | 312.0,512.0,4.84756672e9,0.04189733170414732,0.9556458355900904 11 | 625.0,16.0,2.247872e7,0.4718089797165145,0.49220149695729426 12 | 625.0,64.0,1.37101184e8,0.2903884192431171,2.039897951762062 13 | 625.0,128.0,4.07371648e8,0.15344959861995244,2.258432924131567 14 | 625.0,256.0,1.35056576e9,0.06890992408766512,1.2584854263994432 15 | 625.0,512.0,4.84756672e9,0.05196309891415873,0.7242116360031626 16 | 1250.0,16.0,2.247872e7,0.4746595258273534,0.485363079664304 17 | 1250.0,64.0,1.37101184e8,0.16129120267962568,0.1732828559992677 18 | 1250.0,128.0,4.07371648e8,0.13037294748959447,0.16637627915802317 19 | 1250.0,256.0,1.35056576e9,0.06533727337450614,0.6081945478692418 20 | 1250.0,512.0,4.84756672e9,0.03588343142822981,0.4439861268633558 21 | 2500.0,16.0,2.247872e7,0.4670612495076526,0.47109843025515186 22 | 2500.0,64.0,1.37101184e8,0.1520547705357872,0.15752028896254378 23 | 2500.0,128.0,4.07371648e8,0.08855955326435906,0.09651611101764256 24 | 2500.0,256.0,1.35056576e9,0.06290938134926248,0.09567441332150982 25 | 2500.0,512.0,4.84756672e9,0.060472142605845,0.2532183624901977 26 | 5000.0,16.0,2.247872e7,0.4655672815069447,0.47135633674639776 27 | 5000.0,64.0,1.37101184e8,0.15383802424202714,0.15735269684234243 28 | 5000.0,128.0,4.07371648e8,0.07426424418497594,0.07884265809298366 29 | 5000.0,256.0,1.35056576e9,0.04674108623915223,0.05425594791646079 30 | 5000.0,512.0,4.84756672e9,0.04379936653832022,0.05300132757279298 31 | 10000.0,16.0,2.247872e7,0.45759987791767087,0.46019298000329584 32 | 10000.0,64.0,1.37101184e8,0.13678016887620187,0.13804982738975685 33 | 10000.0,128.0,4.07371648e8,0.07564328630871214,0.07750627701519851 34 | 10000.0,256.0,1.35056576e9,0.04446516979231643,0.047193449539462674 35 | 10000.0,512.0,4.84756672e9,0.03741249818351838,0.0408874673219641 36 | 10000.0,16.0,2.247872e7,0.45759987791767087,0.46019298000329584 37 | 10000.0,64.0,1.37101184e8,0.13678016887620187,0.13804982738975685 38 | 10000.0,128.0,4.07371648e8,0.07564328630871214,0.07750627701519851 39 | 10000.0,256.0,1.35056576e9,0.04446516979231643,0.047193449539462674 40 | 10000.0,512.0,4.84756672e9,0.03741249818351838,0.0408874673219641 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PARA_Solid.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,3.109829e6,0.12126418187078628,0.155901216751596 2 | 156.0,64.0,3.2883701e7,0.08245048846883009,0.41591145950502917 3 | 156.0,128.0,1.20779829e8,0.061419083109788955,0.357271144783621 4 | 156.0,256.0,4.61821109e8,0.04460611304643863,0.24642358596844752 5 | 156.0,512.0,1.804899765e9,0.020462592671517718,0.2068158117051065 6 | 312.0,16.0,3.109829e6,0.10902622193760088,0.11630362419063865 7 | 312.0,64.0,3.2883701e7,0.06890630506550056,0.14513550583748028 8 | 312.0,128.0,1.20779829e8,0.040747435441389986,0.15815065218910362 9 | 312.0,256.0,4.61821109e8,0.02887442987046901,0.14906296011183218 10 | 312.0,512.0,1.804899765e9,0.019619023615749357,0.13566762377560024 11 | 625.0,16.0,3.109829e6,0.10877152930806612,0.11374351053573027 12 | 625.0,64.0,3.2883701e7,0.05386946046334069,0.07640636277074815 13 | 625.0,128.0,1.20779829e8,0.03547439489346798,0.086732827963942 14 | 625.0,256.0,4.61821109e8,0.019939377996368832,0.08422451133747831 15 | 625.0,512.0,1.804899765e9,0.013935312875606178,0.0786522827568006 16 | 1250.0,16.0,3.109829e6,0.1059231602704915,0.10758581411965022 17 | 1250.0,64.0,3.2883701e7,0.05595115201061856,0.06360704853494817 18 | 1250.0,128.0,1.20779829e8,0.034699818675691885,0.07040471408194512 19 | 1250.0,256.0,4.61821109e8,0.020329952513192077,0.06977129066766359 20 | 1250.0,512.0,1.804899765e9,0.012941735384026452,0.06481673088508715 21 | 2500.0,16.0,3.109829e6,0.10952269543325531,0.11075322470323072 22 | 2500.0,64.0,3.2883701e7,0.05273241326160547,0.05503011314962456 23 | 2500.0,128.0,1.20779829e8,0.037449122417834255,0.06231787379763691 24 | 2500.0,256.0,4.61821109e8,0.02279858533363507,0.0659675066794221 25 | 2500.0,512.0,1.804899765e9,0.014909880984090535,0.06216764057583373 26 | 5000.0,16.0,3.109829e6,0.10158911921752072,0.10191300548088568 27 | 5000.0,64.0,3.2883701e7,0.05102815179424756,0.05232287974647775 28 | 5000.0,128.0,1.20779829e8,0.04164499789361079,0.052333591220053904 29 | 5000.0,256.0,4.61821109e8,0.02618442197134807,0.06487806269774568 30 | 5000.0,512.0,1.804899765e9,0.017672231974254434,0.06327365592155092 31 | 10000.0,16.0,3.109829e6,0.09997978736445122,0.10006135662523578 32 | 10000.0,64.0,3.2883701e7,0.050298250430750265,0.05088164263264469 33 | 10000.0,128.0,1.20779829e8,0.04377474991972547,0.04694940425733192 34 | 10000.0,256.0,4.61821109e8,0.03012397095489149,0.060947419897955546 35 | 10000.0,512.0,1.804899765e9,0.023003220909326504,0.06427785429205589 36 | 20000.0,16.0,3.109829e6,0.09582615248576822,0.09617832666157253 37 | 20000.0,64.0,3.2883701e7,0.05170648529604365,0.05213040457095706 38 | 20000.0,128.0,1.20779829e8,0.044387002190457596,0.04550915230284199 39 | 20000.0,256.0,4.61821109e8,0.03588759048996521,0.055779106939107204 40 | 20000.0,512.0,1.804899765e9,0.025725793707126184,0.06773422219860994 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PCA_Adv.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,93984.0,0.41148450443381096,1.625810339255293 2 | 156.0,64.0,155568.0,0.16496452282641438,1.0629169437923072 3 | 156.0,128.0,280688.0,0.09474028821582185,0.9356175810089464 4 | 156.0,256.0,678384.0,0.031740080927560484,0.8089603786889419 5 | 156.0,512.0,2.0636e6,0.0032491146734920985,0.739368829983151 6 | 312.0,16.0,93984.0,0.35250528945185067,1.1101436777544917 7 | 312.0,64.0,155568.0,0.16151865699318377,0.7631874803789671 8 | 312.0,128.0,280688.0,0.09640880463645427,0.6478265381605203 9 | 312.0,256.0,678384.0,0.039790927726516344,0.5858922346261116 10 | 312.0,512.0,2.0636e6,0.008742270185856497,0.5330069291528844 11 | 625.0,16.0,93984.0,0.31609561130602726,0.4520118750684096 12 | 625.0,64.0,155568.0,0.16324623812752087,0.4057864120311623 13 | 625.0,128.0,280688.0,0.10051790706655708,0.3723980936905896 14 | 625.0,256.0,678384.0,0.04791087091548228,0.3433764106426739 15 | 625.0,512.0,2.0636e6,0.011116839599901868,0.30930197886407357 16 | 1250.0,16.0,93984.0,0.2602626102718969,0.2658266222693516 17 | 1250.0,64.0,155568.0,0.1556995448013612,0.19852913813760492 18 | 1250.0,128.0,280688.0,0.11249045256776424,0.22878979751720818 19 | 1250.0,256.0,678384.0,0.06274138235999062,0.23682843428824227 20 | 1250.0,512.0,2.0636e6,0.02310467444972777,0.21220755350122175 21 | 2500.0,16.0,93984.0,0.2911999786587446,0.2955836267903681 22 | 2500.0,64.0,155568.0,0.1447699662173425,0.15931452747039812 23 | 2500.0,128.0,280688.0,0.11231850175061957,0.16142522843480409 24 | 2500.0,256.0,678384.0,0.07510072071136398,0.18567479104726775 25 | 2500.0,512.0,2.0636e6,0.02695173948095355,0.17563196034495848 26 | 5000.0,16.0,93984.0,0.2704528647550728,0.27169091853385946 27 | 5000.0,64.0,155568.0,0.1506546960289392,0.15765421858879866 28 | 5000.0,128.0,280688.0,0.11084497756644236,0.13906545950753305 29 | 5000.0,256.0,678384.0,0.07371837976065146,0.16756864533451618 30 | 5000.0,512.0,2.0636e6,0.021291121921620602,0.1527408494549857 31 | 10000.0,16.0,93984.0,0.2707286331343262,0.27075248693298576 32 | 10000.0,64.0,155568.0,0.14286711040001046,0.14600134229109132 33 | 10000.0,128.0,280688.0,0.11268536549659852,0.1313018292445184 34 | 10000.0,256.0,678384.0,0.06250115808618784,0.16160805957839333 35 | 10000.0,512.0,2.0636e6,0.030635775419660706,0.15176696266648593 36 | 20000.0,16.0,93984.0,0.2609869382039488,0.26137727003888633 37 | 20000.0,64.0,155568.0,0.14509676681568734,0.14685110188186196 38 | 20000.0,128.0,280688.0,0.11496675471775764,0.12531453570808304 39 | 20000.0,256.0,678384.0,0.06300039146761455,0.1615296879140314 40 | 20000.0,512.0,2.0636e6,0.044766228513230574,0.153849630330182 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PCA_Helmhotz.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,2.381548e6,0.07850354252646415,0.5007982942898209 2 | 156.0,64.0,3.393724e6,0.027105783009462366,0.35910142242814286 3 | 156.0,128.0,4.7863e6,0.019477598393825384,0.3110620176092445 4 | 156.0,256.0,7.718908e6,0.014665736226588724,0.27992195570891937 5 | 156.0,512.0,1.4173948e7,0.011983896080432937,0.2507070301196629 6 | 312.0,16.0,2.381548e6,0.06185529440507974,0.273860904454842 7 | 312.0,64.0,3.393724e6,0.024856199581486563,0.20302636427753415 8 | 312.0,128.0,4.7863e6,0.0178391079325014,0.18427083793975046 9 | 312.0,256.0,7.718908e6,0.014555524953028361,0.155339999407995 10 | 312.0,512.0,1.4173948e7,0.012986721652128191,0.14175799363603417 11 | 625.0,16.0,2.381548e6,0.06837882573922822,0.18391673941463002 12 | 625.0,64.0,3.393724e6,0.023487423551447194,0.13629924463748833 13 | 625.0,128.0,4.7863e6,0.017152123861350826,0.10900417698843207 14 | 625.0,256.0,7.718908e6,0.014045735724878048,0.09359778716672872 15 | 625.0,512.0,1.4173948e7,0.013034605901319747,0.08395080375581404 16 | 1250.0,16.0,2.381548e6,0.06835675625388511,0.09391871969017805 17 | 1250.0,64.0,3.393724e6,0.02422075371648755,0.08974369863593668 18 | 1250.0,128.0,4.7863e6,0.016625505331961183,0.0745136357129236 19 | 1250.0,256.0,7.718908e6,0.014044612618774113,0.06307753125295636 20 | 1250.0,512.0,1.4173948e7,0.013719873763561355,0.05946274255998951 21 | 2500.0,16.0,2.381548e6,0.06060758869057927,0.06882442026538264 22 | 2500.0,64.0,3.393724e6,0.02556941729799243,0.056767651102786545 23 | 2500.0,128.0,4.7863e6,0.016943225393093102,0.04982010423355529 24 | 2500.0,256.0,7.718908e6,0.014858509615594142,0.04498550314131384 25 | 2500.0,512.0,1.4173948e7,0.014650344676070319,0.04330356425939093 26 | 5000.0,16.0,2.381548e6,0.05503388374482647,0.058479576358644036 27 | 5000.0,64.0,3.393724e6,0.024964396684771215,0.03538011579692855 28 | 5000.0,128.0,4.7863e6,0.017574838382724205,0.03380213747244003 29 | 5000.0,256.0,7.718908e6,0.016045046849788525,0.0337829123485522 30 | 5000.0,512.0,1.4173948e7,0.015901377852604127,0.03328945011101596 31 | 10000.0,16.0,2.381548e6,0.0533795175007759,0.054590175287560626 32 | 10000.0,64.0,3.393724e6,0.022931164367682305,0.02628585665903812 33 | 10000.0,128.0,4.7863e6,0.017969388817237187,0.02270693348164602 34 | 10000.0,256.0,7.718908e6,0.017261317169586742,0.024035110037250264 35 | 10000.0,512.0,1.4173948e7,0.017357672084471393,0.025509169509566134 36 | 20000.0,16.0,2.381548e6,0.0508467692419182,0.05185845934557424 37 | 20000.0,64.0,3.393724e6,0.02264250541560128,0.02430133484916205 38 | 20000.0,128.0,4.7863e6,0.019045649101122483,0.021280512949173273 39 | 20000.0,256.0,7.718908e6,0.018467421637686318,0.02168139575412656 40 | 20000.0,512.0,1.4173948e7,0.018383012619207505,0.021958703791031327 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PCA_NS.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,1.181104e6,0.4605269440790674,1.2186841774199568 2 | 156.0,64.0,1.609792e6,0.12295705740592087,0.8310629670468895 3 | 156.0,128.0,2.224384e6,0.053029945474354405,0.6645750325474368 4 | 156.0,256.0,3.601024e6,0.024155865746088735,0.5354438089860011 5 | 156.0,512.0,6.944128e6,0.007685656782677317,0.49707179832029413 6 | 312.0,16.0,1.181104e6,0.4061468138812397,0.46896098348017734 7 | 312.0,64.0,1.609792e6,0.11849051304339152,0.5336079010235679 8 | 312.0,128.0,2.224384e6,0.04880362119750032,0.44335853513590945 9 | 312.0,256.0,3.601024e6,0.0175888082263867,0.35221964021087676 10 | 312.0,512.0,6.944128e6,0.0065256781489666914,0.3118061568071539 11 | 625.0,16.0,1.181104e6,0.363093692415487,0.3773597898456187 12 | 625.0,64.0,1.609792e6,0.10687483216882657,0.2226816340754798 13 | 625.0,128.0,2.224384e6,0.05057964963015008,0.3275554870351507 14 | 625.0,256.0,3.601024e6,0.01581713332476597,0.2719887937186588 15 | 625.0,512.0,6.944128e6,0.006539251746777073,0.22988584363873793 16 | 1250.0,16.0,1.181104e6,0.34239901203976525,0.35394876213335447 17 | 1250.0,64.0,1.609792e6,0.09659145914305145,0.12568044962620772 18 | 1250.0,128.0,2.224384e6,0.05891511877191601,0.16230037447526588 19 | 1250.0,256.0,3.601024e6,0.020469093310919236,0.2059543400959292 20 | 1250.0,512.0,6.944128e6,0.007707235087991482,0.18018489432201865 21 | 2500.0,16.0,1.181104e6,0.3439587012689532,0.349524148546195 22 | 2500.0,64.0,1.609792e6,0.08516474312213532,0.09942572347111878 23 | 2500.0,128.0,2.224384e6,0.05081069150591965,0.06952146581640119 24 | 2500.0,256.0,3.601024e6,0.029418206369017742,0.12722447300083467 25 | 2500.0,512.0,6.944128e6,0.012571926083063841,0.15107817267176432 26 | 5000.0,16.0,1.181104e6,0.344605033726457,0.3514301322913124 27 | 5000.0,64.0,1.609792e6,0.0806649869215545,0.08787424285017831 28 | 5000.0,128.0,2.224384e6,0.04563902266467284,0.05441332747279016 29 | 5000.0,256.0,3.601024e6,0.022890382255635264,0.0399625735269843 30 | 5000.0,512.0,6.944128e6,0.020807149058156456,0.09732157680134786 31 | 10000.0,16.0,1.181104e6,0.34710749574442873,0.3511476522044054 32 | 10000.0,64.0,1.609792e6,0.07669613822195874,0.07983375349818746 33 | 10000.0,128.0,2.224384e6,0.045445755624857066,0.050102329075302314 34 | 10000.0,256.0,3.601024e6,0.02763190948655302,0.034348684443923375 35 | 10000.0,512.0,6.944128e6,0.024056045138034488,0.028777487401718076 36 | 20000.0,16.0,1.181104e6,0.34813341022140537,0.34936359398047145 37 | 20000.0,64.0,1.609792e6,0.0720341307586599,0.07377127531598891 38 | 20000.0,128.0,2.224384e6,0.041655531357016676,0.04403831596905797 39 | 20000.0,256.0,3.601024e6,0.030945830370406907,0.033546081579739 40 | 20000.0,512.0,6.944128e6,0.024654289891594947,0.02654266348914689 41 | -------------------------------------------------------------------------------- /HighDataRegime/data/PCA_Solid.csv: -------------------------------------------------------------------------------- 1 | 156.0,16.0,124948.0,0.11357795490419946,0.17300330266093625 2 | 156.0,64.0,311524.0,0.04785650604632496,0.1555171438097476 3 | 156.0,128.0,603300.0,0.027536000950855122,0.1579223654996282 4 | 156.0,256.0,1.334308e6,0.015768088568243764,0.14859757432301784 5 | 156.0,512.0,3.386148e6,0.008026710380706303,0.1458746046893197 6 | 312.0,16.0,124948.0,0.11162090081002625,0.1332856119927404 7 | 312.0,64.0,311524.0,0.04188688194109087,0.1259850142107492 8 | 312.0,128.0,603300.0,0.02505676992697201,0.11702500944052442 9 | 312.0,256.0,1.334308e6,0.012966973813441043,0.11168882987152419 10 | 312.0,512.0,3.386148e6,0.006281242717713232,0.11088791873659272 11 | 625.0,16.0,124948.0,0.08694705305316157,0.09876099162882608 12 | 625.0,64.0,311524.0,0.041527379397561216,0.09367221797535263 13 | 625.0,128.0,603300.0,0.021951621638207505,0.09447500807075779 14 | 625.0,256.0,1.334308e6,0.011416432893756585,0.0903977865257086 15 | 625.0,512.0,3.386148e6,0.005548063354824352,0.08796312961820399 16 | 1250.0,16.0,124948.0,0.08323959655787871,0.08807251119211822 17 | 1250.0,64.0,311524.0,0.0423289096188587,0.07397797829919026 18 | 1250.0,128.0,603300.0,0.02375796420488976,0.07633164395408479 19 | 1250.0,256.0,1.334308e6,0.01050288738441434,0.07367534794701522 20 | 1250.0,512.0,3.386148e6,0.005363692473632316,0.0709425149109577 21 | 2500.0,16.0,124948.0,0.07978360996581975,0.08121453080022611 22 | 2500.0,64.0,311524.0,0.04431792431430159,0.05986327061637096 23 | 2500.0,128.0,603300.0,0.0258367759724788,0.06715272160319648 24 | 2500.0,256.0,1.334308e6,0.012044078904295343,0.0678187783988049 25 | 2500.0,512.0,3.386148e6,0.006234549017533784,0.06433617711973359 26 | 5000.0,16.0,124948.0,0.07247650591487838,0.07333547620274454 27 | 5000.0,64.0,311524.0,0.04496860444322229,0.05373009715231799 28 | 5000.0,128.0,603300.0,0.029848955279902886,0.061380616373617115 29 | 5000.0,256.0,1.334308e6,0.014633140447374331,0.06562974057643944 30 | 5000.0,512.0,3.386148e6,0.009176110183490354,0.06345607667213714 31 | 10000.0,16.0,124948.0,0.07061621703634144,0.07085489891527146 32 | 10000.0,64.0,311524.0,0.04644917374013051,0.04975507772933423 33 | 10000.0,128.0,603300.0,0.03410576725858564,0.05636758222656388 34 | 10000.0,256.0,1.334308e6,0.020109419310930302,0.06465998120322289 35 | 10000.0,512.0,3.386148e6,0.012510275552019681,0.06519014232966086 36 | 20000.0,16.0,124948.0,0.06968902028945718,0.07010400380030836 37 | 20000.0,64.0,311524.0,0.04517700137929292,0.046707209402072826 38 | 20000.0,128.0,603300.0,0.03722111748615488,0.051998938594154616 39 | 20000.0,256.0,1.334308e6,0.025428953740643957,0.0624401348933131 40 | 20000.0,512.0,3.386148e6,0.01677502076551009,0.06612517934417321 41 | -------------------------------------------------------------------------------- /HighDataRegime/helmpca95.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/helmpca95.npy -------------------------------------------------------------------------------- /HighDataRegime/helmpca99Te.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/helmpca99Te.npy -------------------------------------------------------------------------------- /HighDataRegime/helmpca99Tr.npy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/helmpca99Tr.npy -------------------------------------------------------------------------------- /HighDataRegime/perdAdvection.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/perdAdvection.pkl -------------------------------------------------------------------------------- /HighDataRegime/plot_style-Examples.txt: -------------------------------------------------------------------------------- 1 | xtick.color: 323034 2 | ytick.color: 323034 3 | text.color: 323034 4 | lines.markeredgecolor: black 5 | patch.facecolor : bc80bd 6 | patch.force_edgecolor : True 7 | patch.linewidth: 0.8 8 | scatter.edgecolors: black 9 | grid.color: b1afb5 10 | axes.titlesize: 20 11 | legend.title_fontsize: 20 12 | xtick.labelsize: 30 13 | ytick.labelsize: 30 14 | axes.labelsize: 40 15 | font.size: 20 16 | image.cmap: coolwarm 17 | mathtext.fontset: stix 18 | font.family: STIXGeneral 19 | lines.linewidth: 2 20 | legend.frameon: True 21 | legend.framealpha: 0.8 22 | legend.fontsize: 16 23 | legend.edgecolor: 0.9 24 | legend.borderpad: 0.2 25 | legend.columnspacing: 1.5 26 | legend.labelspacing: 0.4 27 | text.usetex: True 28 | axes.titlelocation: left 29 | axes.formatter.use_mathtext: True 30 | axes.autolimit_mode: round_numbers 31 | axes.labelpad: 3 32 | axes.formatter.limits: -4, 4 33 | axes.labelcolor: black 34 | axes.edgecolor: black 35 | axes.linewidth: 0.6 36 | axes.spines.right : False 37 | axes.spines.top : False 38 | axes.grid: False 39 | figure.titlesize: 18 40 | figure.dpi: 300 41 | -------------------------------------------------------------------------------- /HighDataRegime/plot_style-coolwarm.txt: -------------------------------------------------------------------------------- 1 | xtick.color: 323034 2 | ytick.color: 323034 3 | text.color: 323034 4 | lines.markeredgecolor: black 5 | patch.facecolor : bc80bd 6 | patch.force_edgecolor : True 7 | patch.linewidth: 0.8 8 | scatter.edgecolors: black 9 | grid.color: b1afb5 10 | axes.titlesize: 20 11 | legend.title_fontsize: 20 12 | xtick.labelsize: 15 13 | ytick.labelsize: 15 14 | axes.labelsize: 20 15 | font.size: 20 16 | image.cmap: coolwarm 17 | mathtext.fontset: stix 18 | font.family: STIXGeneral 19 | lines.linewidth: 2 20 | legend.frameon: True 21 | legend.framealpha: 0.8 22 | legend.fontsize: 20 23 | legend.edgecolor: 0.9 24 | legend.borderpad: 0.2 25 | legend.columnspacing: 1.5 26 | legend.labelspacing: 0.4 27 | text.usetex: True 28 | axes.titlelocation: left 29 | axes.formatter.use_mathtext: True 30 | axes.autolimit_mode: round_numbers 31 | axes.labelpad: 3 32 | axes.formatter.limits: -4, 4 33 | axes.labelcolor: black 34 | axes.edgecolor: black 35 | axes.linewidth: 0.6 36 | axes.spines.right : False 37 | axes.spines.top : False 38 | axes.grid: False 39 | figure.titlesize: 18 40 | figure.dpi: 300 41 | -------------------------------------------------------------------------------- /HighDataRegime/plot_style.txt: -------------------------------------------------------------------------------- 1 | xtick.color: 323034 2 | ytick.color: 323034 3 | text.color: 323034 4 | lines.markeredgecolor: black 5 | patch.facecolor : bc80bd 6 | patch.force_edgecolor : True 7 | patch.linewidth: 0.8 8 | scatter.edgecolors: black 9 | grid.color: b1afb5 10 | axes.titlesize: 16 11 | legend.title_fontsize: 12 12 | xtick.labelsize: 12 13 | ytick.labelsize: 12 14 | axes.labelsize: 12 15 | font.size: 10 16 | axes.prop_cycle : (cycler('color', ['bc80bd' ,'fb8072', 'b3de69','fdb462','fccde5','8dd3c7','ffed6f','bebada','80b1d3', 'ccebc5', 'd9d9d9'])) 17 | mathtext.fontset: stix 18 | font.family: STIXGeneral 19 | lines.linewidth: 2 20 | legend.frameon: True 21 | legend.framealpha: 0.8 22 | legend.fontsize: 10 23 | legend.edgecolor: 0.9 24 | legend.borderpad: 0.2 25 | legend.columnspacing: 1.5 26 | legend.labelspacing: 0.4 27 | text.usetex: True 28 | axes.titlelocation: left 29 | axes.formatter.use_mathtext: True 30 | axes.autolimit_mode: round_numbers 31 | axes.labelpad: 3 32 | axes.formatter.limits: -4, 4 33 | axes.labelcolor: black 34 | axes.edgecolor: black 35 | axes.linewidth: 0.6 36 | axes.spines.right : False 37 | axes.spines.top : False 38 | axes.grid: False 39 | figure.titlesize: 18 40 | figure.dpi: 300 -------------------------------------------------------------------------------- /HighDataRegime/plots.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots.tar.gz -------------------------------------------------------------------------------- /HighDataRegime/plots_output/ErrorAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/ErrorAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/ErrorHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/ErrorHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/ErrorMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/ErrorMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/ErrorNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/ErrorNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/InputAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/InputAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/InputHelmoltz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/InputHelmoltz.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/InputNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/InputNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/InputStructural.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/InputStructural.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/OutputAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/OutputAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/OutputHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/OutputHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/OutputNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/OutputNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/OutputStructuralMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/OutputStructuralMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/OverlayAdvectionII.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/OverlayAdvectionII.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/PredAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/PredAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/PredictedHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/PredictedHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/PredictedMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/PredictedMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/PredictedNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/PredictedNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/TrueAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/TrueAdvection.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/TrueHelmholtz.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/TrueHelmholtz.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/TrueMechanics.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/TrueMechanics.pdf -------------------------------------------------------------------------------- /HighDataRegime/plots_output/TrueNavierStokes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/plots_output/TrueNavierStokes.pdf -------------------------------------------------------------------------------- /HighDataRegime/predAdvection.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/HighDataRegime/predAdvection.pkl -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/ErrorAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/ErrorAdvection.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/InputAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/InputAdvection.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/InputAdvection2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/InputAdvection2.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/OutputAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/OutputAdvection.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/OverlayAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/OverlayAdvection.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/PredAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/PredAdvection.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/PredictedAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/PredictedAdvection.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/Readme.md: -------------------------------------------------------------------------------- 1 | # Advection equation (I) 2 | For the data, see: 3 | 4 | https://github.com/lu-group/deeponet-fno/tree/main/data/advection 5 | 6 | **As of 12/10/24 the following links do not work anymore** 7 | - [Data I](https://drive.google.com/drive/folders/14BaWDkNq3wBabGFWkERgDbcPeowU6utX?usp=sharing) 8 | -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/TrueAdvection.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Advection equation I/TrueAdvection.pdf -------------------------------------------------------------------------------- /LowDataRegime/Advection equation I/plot_style-Examples.txt: -------------------------------------------------------------------------------- 1 | xtick.color: 323034 2 | ytick.color: 323034 3 | text.color: 323034 4 | lines.markeredgecolor: black 5 | patch.facecolor : bc80bd 6 | patch.force_edgecolor : True 7 | patch.linewidth: 0.8 8 | scatter.edgecolors: black 9 | grid.color: b1afb5 10 | axes.titlesize: 20 11 | legend.title_fontsize: 20 12 | xtick.labelsize: 30 13 | ytick.labelsize: 30 14 | axes.labelsize: 40 15 | font.size: 20 16 | image.cmap: coolwarm 17 | mathtext.fontset: stix 18 | font.family: STIXGeneral 19 | lines.linewidth: 2 20 | legend.frameon: True 21 | legend.framealpha: 0.8 22 | legend.fontsize: 16 23 | legend.edgecolor: 0.9 24 | legend.borderpad: 0.2 25 | legend.columnspacing: 1.5 26 | legend.labelspacing: 0.4 27 | text.usetex: True 28 | axes.titlelocation: left 29 | axes.formatter.use_mathtext: True 30 | axes.autolimit_mode: round_numbers 31 | axes.labelpad: 3 32 | axes.formatter.limits: -4, 4 33 | axes.labelcolor: black 34 | axes.edgecolor: black 35 | axes.linewidth: 0.6 36 | axes.spines.right : False 37 | axes.spines.top : False 38 | axes.grid: False 39 | figure.titlesize: 18 40 | figure.dpi: 300 41 | -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/Choleksy.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Mon Mar 6 17:26:42 2023 5 | 6 | @author: matthieudarcy 7 | """ 8 | 9 | from scipy import io 10 | import numpy as np 11 | 12 | import matplotlib.pyplot as plt 13 | 14 | plt.style.use("seaborn") 15 | 16 | from sklearn.decomposition import PCA 17 | 18 | from sklearn.linear_model import Ridge, LinearRegression 19 | 20 | from sklearn.preprocessing import PolynomialFeatures 21 | from tqdm import tqdm 22 | 23 | from scipy.linalg import cholesky, cho_factor, cho_solve 24 | 25 | 26 | from sklearn.gaussian_process import GaussianProcessRegressor 27 | from sklearn.gaussian_process.kernels import Matern, RBF 28 | 29 | 30 | 31 | 32 | from math import inf 33 | 34 | 35 | import scipy 36 | 37 | #%% 38 | 39 | def get_data(ntrain, ntest): 40 | sub_x = 2 ** 6 41 | sub_y = 2 ** 6 42 | 43 | # Data is of the shape (number of samples = 2048, grid size = 2^13) 44 | data = io.loadmat("burgers_data_R10.mat") 45 | x_data = data["a"][:, ::sub_x].astype(np.float64) 46 | y_data = data["u"][:, ::sub_y].astype(np.float64) 47 | x_branch_train = x_data[:ntrain, :] 48 | y_train = y_data[:ntrain, :] 49 | x_branch_test = x_data[-ntest:, :] 50 | y_test = y_data[-ntest:, :] 51 | 52 | 53 | s = 2 ** 13 // sub_y # total grid size divided by the subsampling rate 54 | grid = np.linspace(0, 1, num=2 ** 13)[::sub_y, None] 55 | 56 | return x_branch_train, y_train, x_branch_test, y_test, grid 57 | 58 | 59 | x_train = (x_branch_train, grid) 60 | x_test = (x_branch_test, grid) 61 | return x_train, y_train, x_test, y_test 62 | 63 | 64 | x, y, x_test, y_test, grid = get_data(1000, 200) 65 | 66 | 67 | idx = 2 68 | 69 | plt.figure() 70 | plt.plot(grid, x[idx]) 71 | plt.xlabel(r'$x$', size= 15) 72 | plt.ylabel(r'$u_0(x)$', size= 15) 73 | 74 | 75 | #%% No Cholesky 76 | 77 | 78 | def train_test(x_train, x_test, y_train, y_test): 79 | kernel = Matern(nu = 2.5, length_scale = 1.0) 80 | gp = GaussianProcessRegressor(kernel, alpha = 1e-10, normalize_y = True, random_state= 6032023) 81 | 82 | gp.fit(x_train, y_train) 83 | pred= gp.predict(x_test) 84 | #pred_train = gp.predict(x_train) 85 | 86 | #e = compute_error_dataset(y_test, pred, knots, k) 87 | 88 | return pred, gp 89 | 90 | pred, GP = train_test(x, x_test, y, y_test) 91 | pred_train = GP.predict(x) 92 | e = np.mean(np.linalg.norm(pred - y_test, axis = -1)/np.linalg.norm(y_test, axis = -1)) 93 | e_train = np.mean(np.linalg.norm(pred_train - y, axis = -1)/np.linalg.norm(y, axis = -1)) 94 | 95 | 96 | print(e, e_train) 97 | idx = 15 98 | i = 0 99 | 100 | fig, (ax1, ax2) = plt.subplots(1,2, figsize = (15,5)) 101 | ax1.plot(grid, y[idx], label = "True") 102 | ax1.plot(grid, pred_train[idx], label = "Prediction") 103 | ax1.set_xlabel(r'$x$', size= 15) 104 | ax1.set_ylabel(r'$u(x,1)$', size= 15) 105 | ax1.set_title("Prediction on the training set", size = 15) 106 | ax1.legend() 107 | 108 | 109 | 110 | 111 | #%% Choleksy transform 112 | 113 | # kernel_u = Matern(nu = 0.5, length_scale = 0.1) 114 | # kernel_v = Matern(nu = 0.5, length_scale = 0.1) 115 | 116 | # K = kernel_u.__call__(grid) 117 | # G = kernel_v.__call__(grid) 118 | 119 | # L_K = cholesky(K, lower=False) 120 | # L_G = cholesky(G, lower = False) 121 | 122 | # tau = 1e-8 123 | # L_K_inv = np.linalg.inv(L_K + tau*np.eye(K.shape[0])) 124 | # L_G_inv = np.linalg.inv(L_G + tau*np.eye(K.shape[0])) 125 | 126 | 127 | # #%% Cholesky transformation 128 | 129 | # x_train = [] 130 | # for i in range(x.shape[0]): 131 | # x_train.append(L_K_inv.T@x[i]) 132 | # x_train = np.array(x_train) 133 | 134 | # y_train = [] 135 | # for i in range(y.shape[0]): 136 | # y_train.append(L_G_inv.T@y[i]) 137 | # y_train = np.array(y_train) 138 | 139 | 140 | # x_val = [] 141 | # for i in range(x_test.shape[0]): 142 | # x_val.append(L_K_inv.T@x_test[i]) 143 | # x_val = np.array(x_val) 144 | 145 | # y_val = [] 146 | # for i in range(y_test.shape[0]): 147 | # y_val.append(L_G_inv.T@y_test[i]) 148 | # y_val = np.array(y_val) 149 | 150 | 151 | #%% Choelsky precondition 152 | 153 | kernel_u = Matern(nu = 0.5, length_scale = 0.1) 154 | kernel_v = Matern(nu = 0.5, length_scale = 0.1) 155 | def cholesky_transform(kernel_u, kernel_v, grid, u, v): 156 | K = kernel_u(grid) 157 | G = kernel_v(grid) 158 | 159 | L_K = cholesky(K, lower=False) 160 | L_G = cholesky(G, lower = False) 161 | 162 | tau = 1e-8 163 | L_K_inv = np.linalg.inv(L_K + tau*np.eye(K.shape[0])) 164 | L_G_inv = np.linalg.inv(L_G + tau*np.eye(K.shape[0])) 165 | 166 | 167 | return (L_K_inv.T @ u[:, :, None]).squeeze(-1), (L_G_inv.T @ v[:, :, None]).squeeze(-1) 168 | 169 | x_train, y_train = cholesky_transform(kernel_u, kernel_v, grid, x, y) 170 | x_val, y_val = cholesky_transform(kernel_u, kernel_v, grid, x_test, y_test) 171 | 172 | 173 | #%% Optimal recovery: pointwize values 174 | 175 | def optimal_recovery(kernel_u, kernel_v, grid, u, v): 176 | K = kernel_u(grid) 177 | G = kernel_v(grid) 178 | 179 | L_K = cholesky(K, lower=False) 180 | L_G = cholesky(G, lower = False) 181 | 182 | tau = 1e-8 183 | L_K_inv = np.linalg.inv(L_K + tau*np.eye(K.shape[0])) 184 | L_G_inv = np.linalg.inv(L_G + tau*np.eye(K.shape[0])) 185 | 186 | u_recov = np.squeeze(K@L_K_inv@u[:, :, None]) 187 | v_recov = np.squeeze(G@L_G_inv@v[:, :, None]) 188 | 189 | return u_recov, v_recov 190 | 191 | u_recov, v_recov = optimal_recovery(kernel_u, kernel_v, grid, x_train, y_train) 192 | 193 | e_u = np.mean(np.linalg.norm(u_recov - x, axis = -1)/np.linalg.norm(x, axis = -1)) 194 | e_v = np.mean(np.linalg.norm(v_recov - y, axis = -1)/np.linalg.norm(y, axis = -1)) 195 | 196 | print(e_u, e_v) 197 | 198 | 199 | u_recov, v_recov = optimal_recovery(kernel_u, kernel_v, grid, x_val, y_val) 200 | 201 | e_u = np.mean(np.linalg.norm(u_recov - x_test, axis = -1)/np.linalg.norm(x_test, axis = -1)) 202 | e_v = np.mean(np.linalg.norm(v_recov - y_test, axis = -1)/np.linalg.norm(y_test, axis = -1)) 203 | 204 | print(e_u, e_v) 205 | #%% Optimal recovery: pointwise values 206 | 207 | # u_recov = [] 208 | # for i in range(x.shape[0]): 209 | # u_recov.append(K@L_K_inv@x_train[i]) 210 | # u_recov = np.array(u_recov) 211 | 212 | 213 | # v_recov = [] 214 | # for i in range(y.shape[0]): 215 | # v_recov.append(G@L_G_inv@pred_train[i]) 216 | # v_recov = np.array(v_recov) 217 | 218 | # e_u = np.mean(np.linalg.norm(u_recov - x, axis = -1)/np.linalg.norm(x, axis = -1)) 219 | # e_v = np.mean(np.linalg.norm(v_recov - y, axis = -1)/np.linalg.norm(y, axis = -1)) 220 | 221 | # print(e_u, e_v) 222 | 223 | # u_recov = [] 224 | # for i in range(x_test.shape[0]): 225 | # u_recov.append(K@L_K_inv@x_val[i]) 226 | # u_recov = np.array(u_recov) 227 | 228 | 229 | # v_recov = [] 230 | # for i in range(y_test.shape[0]): 231 | # v_recov.append(G@L_G_inv@y_val[i]) 232 | # v_recov = np.array(v_recov) 233 | 234 | # e_u = np.mean(np.linalg.norm(u_recov - x_test, axis = -1)/np.linalg.norm(x_test, axis = -1)) 235 | # e_v = np.mean(np.linalg.norm(v_recov - y_test, axis = -1)/np.linalg.norm(y_test, axis = -1)) 236 | 237 | # print(e_u, e_v) 238 | 239 | 240 | #%% 241 | 242 | pred, gp = train_test(x, x_test, y_train, y_val) 243 | pred_train = gp.predict(x) 244 | e = np.mean(np.linalg.norm(pred - y_val, axis = -1)/np.linalg.norm(y_val, axis = -1)) 245 | e_train = np.mean(np.linalg.norm(pred_train - y_train, axis = -1)/np.linalg.norm(y_train, axis = -1)) 246 | 247 | print(e, e_train) 248 | 249 | print(gp.kernel_) 250 | 251 | #%% Recovering the pointwise measurements 252 | 253 | 254 | 255 | 256 | # pred_point = [] 257 | # for i in range(y_test.shape[0]): 258 | # pred_point.append(G@L_G_inv@pred[i]) 259 | 260 | # pred_point = np.array(pred_point) 261 | 262 | # pred_point_train = [] 263 | # for i in range(x.shape[0]): 264 | # pred_point_train.append(G@L_G_inv@pred_train[i]) 265 | # pred_point_train = np.array(pred_point_train) 266 | 267 | pred_point_train, pred_point = optimal_recovery(kernel_u, kernel_v, grid, pred_train, pred) 268 | 269 | e = np.mean(np.linalg.norm(pred_point - y_test, axis = -1)/np.linalg.norm(y_test, axis = -1)) 270 | e_train = np.mean(np.linalg.norm(pred_point_train - y, axis = -1)/np.linalg.norm(y, axis = -1)) 271 | 272 | print(e, e_train) 273 | 274 | idx = 15 275 | 276 | fig, (ax1, ax2) = plt.subplots(1,2, figsize = (15,5)) 277 | ax1.plot(grid, y[idx], label = "True") 278 | ax1.plot(grid, pred_point_train[idx], label = "Prediction") 279 | ax1.set_xlabel(r'$x$', size= 15) 280 | ax1.set_ylabel(r'$u(x,1)$', size= 15) 281 | ax1.set_title("Prediction on the training set", size = 15) 282 | ax1.legend() 283 | 284 | ax2.plot(grid, y_test[idx], label = "True") 285 | ax2.plot(grid, pred_point[idx], label = "Prediction") 286 | ax2.set_xlabel(r'$x$', size= 15) 287 | ax2.set_ylabel(r'$u(x, 1)$', size= 15) 288 | ax2.set_title("Prediction on the test set", size = 15) 289 | ax2.legend() 290 | 291 | #%% optimizing the K, G parameters 292 | # kernel_u = Matern(nu = 0.5, length_scale = 1.0) 293 | # gp_u = GaussianProcessRegressor(kernel_u, alpha = 1e-10, normalize_y = False, random_state= 6032023, optimizer = None) 294 | # gp_u.fit(grid, x[0]) 295 | 296 | 297 | # theta_test = np.array([1.0]) 298 | # #gp_u.theta = theta_te1t 299 | 300 | # #K, grad_k = gp_u.log_marginal_likelihood(np.array([10.0]),eval_gradient=True, clone_kernel=False) 301 | 302 | # K, grad_k = kernel_u(grid, eval_gradient = True) 303 | 304 | 305 | 306 | # def log_marginal_likelihood(y, gp, theta): 307 | # values = [] 308 | # #print(theta) 309 | # for sample in y: 310 | # #print(sample[50]) 311 | # gp.y_train_ = sample 312 | # #gp.fit(grid,sample) 313 | # #print(sample[0]) 314 | # #print(sample.shape) 315 | # #print(gp.L_) 316 | # #print(gp.alpha_) 317 | # values.append(gp.log_marginal_likelihood(theta = theta, eval_gradient = True)) 318 | 319 | 320 | # return np.mean(np.array(values, dtype = object), axis = 0) 321 | 322 | 323 | # values =log_marginal_likelihood(x, gp_u, theta_test) 324 | # #print() 325 | 326 | # #%% 327 | 328 | 329 | # def obj_func(theta, gp, y): 330 | 331 | # value, grad = log_marginal_likelihood(y, gp, theta) 332 | # return -value, -grad 333 | 334 | # initial_theta = np.array([1.0]) 335 | # print(obj_func(initial_theta, gp_u, x)) 336 | # #%% 337 | # bnds = ((1e-5, 1e5)) 338 | # opt_res = scipy.optimize.minimize( 339 | # obj_func, 340 | # initial_theta, 341 | # args = (gp_u, x), 342 | # method="BFGS", 343 | # jac=True, 344 | # options = {"disp": True}) 345 | 346 | 347 | # #%% 348 | 349 | # print(opt_res.x) 350 | 351 | #%% Choosing the parmaters using MLE 352 | 353 | def log_marginal_likelihood(y, gp, theta): 354 | values = [] 355 | for sample in y: 356 | gp.y_train_ = sample 357 | values.append(gp.log_marginal_likelihood(theta = theta, eval_gradient = True)) 358 | 359 | 360 | return np.mean(np.array(values, dtype = object), axis = 0) 361 | 362 | def mle(grid, function_samples, kernel, theta_init, bnds): 363 | gp = GaussianProcessRegressor(kernel, alpha = 1e-10, normalize_y = False, optimizer = None) 364 | gp.fit(grid, function_samples[0]) 365 | 366 | 367 | def obj_func(theta, gp, y): 368 | 369 | value, grad = log_marginal_likelihood(y, gp, theta) 370 | return -value, -grad 371 | 372 | opt_res = scipy.optimize.minimize( 373 | obj_func, 374 | theta_init, 375 | args = (gp, function_samples), 376 | method="L-BFGS-B", 377 | jac=True, 378 | bounds= bnds, 379 | options = {"disp": False}) 380 | print(opt_res.message) 381 | return opt_res.x 382 | 383 | #%% 384 | theta_init = np.array([1.0]) 385 | bnds = ((1e-5, 1e5),) 386 | kernel_u = Matern(nu = 0.5, length_scale = 1.0) 387 | param_u = mle(grid, x, kernel_u, theta_init, bnds) 388 | 389 | #%% 390 | theta_init = np.array([1.0]) 391 | bnds = ((1e-10, 1e5),) 392 | kernel_v = Matern(nu = 0.5, length_scale = 1.0) 393 | param_v = mle(grid, y, kernel_v, theta_init, bnds) 394 | 395 | #%% 396 | 397 | print(param_u, param_v) 398 | 399 | 400 | #%% 401 | 402 | 403 | 404 | 405 | #%% Choleksy factors 406 | 407 | kernel_u = Matern(nu = 0.5, length_scale = 0.1) 408 | kernel_v = Matern(nu = 0.5, length_scale = 0.1) 409 | 410 | 411 | 412 | 413 | #%% Cholesky transformation 414 | 415 | 416 | 417 | 418 | #%% Optimal recovery: pointwise values 419 | 420 | u_recov = [] 421 | for i in range(x.shape[0]): 422 | u_recov.append(K@L_K_inv@x_train[i]) 423 | u_recov = np.array(u_recov) 424 | 425 | 426 | v_recov = [] 427 | for i in range(y.shape[0]): 428 | v_recov.append(G@L_G_inv@pred_train[i]) 429 | v_recov = np.array(v_recov) 430 | 431 | e_u = np.mean(np.linalg.norm(u_recov - x, axis = -1)/np.linalg.norm(x, axis = -1)) 432 | e_v = np.mean(np.linalg.norm(v_recov - y, axis = -1)/np.linalg.norm(y, axis = -1)) 433 | 434 | print(e_u, e_v) 435 | 436 | u_recov = [] 437 | for i in range(x_test.shape[0]): 438 | u_recov.append(K@L_K_inv@x_val[i]) 439 | u_recov = np.array(u_recov) 440 | 441 | 442 | v_recov = [] 443 | for i in range(y_test.shape[0]): 444 | v_recov.append(G@L_G_inv@y_val[i]) 445 | v_recov = np.array(v_recov) 446 | 447 | e_u = np.mean(np.linalg.norm(u_recov - x_test, axis = -1)/np.linalg.norm(x_test, axis = -1)) 448 | e_v = np.mean(np.linalg.norm(v_recov - y_test, axis = -1)/np.linalg.norm(y_test, axis = -1)) 449 | 450 | print(e_u, e_v) 451 | 452 | 453 | #%% 454 | 455 | pred, gp = train_test(x, x_test, y_train, y_val) 456 | pred_train = gp.predict(x) 457 | e = np.mean(np.linalg.norm(pred - y_val, axis = -1)/np.linalg.norm(y_val, axis = -1)) 458 | e_train = np.mean(np.linalg.norm(pred_train - y_train, axis = -1)/np.linalg.norm(y_train, axis = -1)) 459 | 460 | print(e, e_train) 461 | 462 | print(gp.kernel_) 463 | 464 | #%% Recovering the pointwise measurements 465 | 466 | 467 | pred_point = [] 468 | for i in range(y_test.shape[0]): 469 | pred_point.append(G@L_G_inv@pred[i]) 470 | 471 | pred_point = np.array(pred_point) 472 | 473 | pred_point_train = [] 474 | for i in range(x.shape[0]): 475 | pred_point_train.append(G@L_G_inv@pred_train[i]) 476 | pred_point_train = np.array(pred_point_train) 477 | 478 | e = np.mean(np.linalg.norm(pred_point - y_test, axis = -1)/np.linalg.norm(y_test, axis = -1)) 479 | e_train = np.mean(np.linalg.norm(pred_point_train - y, axis = -1)/np.linalg.norm(y, axis = -1)) 480 | 481 | print(e, e_train) 482 | 483 | idx = 15 484 | 485 | fig, (ax1, ax2) = plt.subplots(1,2, figsize = (15,5)) 486 | ax1.plot(grid, y[idx], label = "True") 487 | ax1.plot(grid, pred_point_train[idx], label = "Prediction") 488 | ax1.set_xlabel(r'$x$', size= 15) 489 | ax1.set_ylabel(r'$u(x,1)$', size= 15) 490 | ax1.set_title("Prediction on the training set", size = 15) 491 | ax1.legend() 492 | 493 | ax2.plot(grid, y_test[idx], label = "True") 494 | ax2.plot(grid, pred_point[idx], label = "Prediction") 495 | ax2.set_xlabel(r'$x$', size= 15) 496 | ax2.set_ylabel(r'$u(x, 1)$', size= 15) 497 | ax2.set_title("Prediction on the test set", size = 15) 498 | ax2.legend() 499 | #%% 500 | 501 | 502 | 503 | # #%% 504 | # def log_marginal_likelihood(y, kernel, theta): 505 | # kernel.length_scale =theta 506 | # #print(kernel) 507 | # K, grad_K = kernel(grid, eval_gradient = True) 508 | 509 | # #print(K.shape) 510 | # # Compute the log likelihood 511 | # L = cholesky(K + 1e-10*np.eye(K.shape[0]), lower = True, check_finite=True) 512 | # #print(L) 513 | # alpha = scipy.linalg.solve(K + 1e-10*np.eye(K.shape[0]), y.T, assume_a='pos').T 514 | # print(alpha) 515 | 516 | # #print((y*alpha).shape) 517 | # log_p = -0.5*np.sum(y*alpha, axis = -1) 518 | # log_p -= 0.5*np.log(np.diag(L)).sum() 519 | # log_p -=K.shape[0] / 2 * np.log(2 * np.pi) 520 | 521 | # # Compute the gradient 522 | # grad = 0 523 | # # #print(grad_K.shape, y.shape) 524 | # # temp = (np.squeeze(grad_K) @ alpha[:, :, None]).squeeze(-1) 525 | # # #print(temp.shape) 526 | # # #print(K.shape, temp.shape) 527 | # # alpha_2 = scipy.linalg.solve(K+ 1e-10*np.eye(K.shape[0]), temp.T, assume_a = 'pos').T 528 | # # #print(alpha_2.shape) 529 | 530 | # # grad = 0.5*np.sum(np.sum(y*alpha_2, axis = -1)) 531 | # # grad = -0.5*y.shape[0]*np.trace(scipy.linalg.solve(K+ 1e-10*np.eye(K.shape[0]), grad_K, assume_a= "pos")) 532 | 533 | # return log_p, grad 534 | 535 | 536 | # print(log_marginal_likelihood(x[:1], kernel_u, theta_test)) 537 | 538 | # #%% 539 | 540 | # def obj_func(theta, kernel, y): 541 | 542 | # value, grad = log_marginal_likelihood(y, kernel, theta) 543 | # return -value, -grad 544 | 545 | 546 | # #%% 547 | 548 | # # initial_theta = np.array([10.0]) 549 | # # bnds = ((0.0, 10)) 550 | # # opt_res = scipy.optimize.minimize( 551 | # # obj_func, 552 | # # initial_theta, 553 | # # args = (kernel_u, x), 554 | # # method="BFGS", 555 | # # jac=True) 556 | 557 | # #%% 558 | 559 | # # print(opt_res.x) -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/ErrorBurger.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/ErrorBurger.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/InputBurger.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/InputBurger.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/InputBurger2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/InputBurger2.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/OutputBurger.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/OutputBurger.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/OutputBurger2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/OutputBurger2.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/OverlaidBurger.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/OverlaidBurger.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/PredBurger.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/PredBurger.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/Readme.md: -------------------------------------------------------------------------------- 1 | # Burgers' equation 2 | For the data, see: 3 | 4 | [https://github.com/lu-group/deeponet-fno/tree/main/data/advection](https://github.com/lu-group/deeponet-fno/tree/main/data/burgers) 5 | 6 | **As of 12/10/24 the following links do not work anymore** 7 | 8 | Code and data are taken from https://github.com/zongyi-li/fourier_neural_operator/tree/master/data_generation/burgers. 9 | 10 | - [Data](https://drive.google.com/drive/folders/1Pekes7BJaRTix591fhAb76GjdE2JLPX8?usp=sharing) 11 | 12 | -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/TrueBurger.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Burger's equation/TrueBurger.pdf -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/cholesky_bayesian.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | """ 4 | Created on Mon Mar 13 12:44:06 2023 5 | 6 | @author: matthieudarcy 7 | """ 8 | 9 | from scipy import io 10 | import numpy as np 11 | 12 | import matplotlib.pyplot as plt 13 | 14 | 15 | from sklearn.gaussian_process import GaussianProcessRegressor 16 | plt.style.use("seaborn") 17 | 18 | from sklearn.gaussian_process.kernels import Matern, RBF, ConstantKernel 19 | 20 | 21 | from scipy.linalg import cholesky, cho_factor, cho_solve 22 | 23 | import scipy 24 | 25 | #%% 26 | 27 | def get_data(ntrain, ntest): 28 | sub_x = 2 ** 6 29 | sub_y = 2 ** 6 30 | 31 | # Data is of the shape (number of samples = 2048, grid size = 2^13) 32 | data = io.loadmat("burgers_data_R10.mat") 33 | x_data = data["a"][:, ::sub_x].astype(np.float64) 34 | y_data = data["u"][:, ::sub_y].astype(np.float64) 35 | x_branch_train = x_data[:ntrain, :] 36 | y_train = y_data[:ntrain, :] 37 | x_branch_test = x_data[-ntest:, :] 38 | y_test = y_data[-ntest:, :] 39 | 40 | 41 | s = 2 ** 13 // sub_y # total grid size divided by the subsampling rate 42 | grid = np.linspace(0, 1, num=2 ** 13)[::sub_y, None] 43 | 44 | return x_branch_train, y_train, x_branch_test, y_test, grid 45 | 46 | 47 | x_train = (x_branch_train, grid) 48 | x_test = (x_branch_test, grid) 49 | return x_train, y_train, x_test, y_test 50 | 51 | 52 | x, y, x_test, y_test, grid = get_data(1000, 200) 53 | 54 | 55 | idx = 2 56 | 57 | plt.figure() 58 | plt.plot(grid, x[idx]) 59 | plt.xlabel(r'$x$', size= 15) 60 | plt.ylabel(r'$u_0(x)$', size= 15) 61 | 62 | #%% 63 | 64 | def compute_cho(kernel_u, kernel_v, grid): 65 | K = kernel_u(grid) 66 | G = kernel_v(grid) 67 | #print(np.linalg.cond(K)) 68 | 69 | print(kernel_u, kernel_v) 70 | 71 | tau = 1e-8 72 | L_K = cholesky(K + tau*np.eye(K.shape[0]), lower=True) 73 | L_G = cholesky(G+ tau*np.eye(K.shape[0]), lower = False) 74 | 75 | return L_K, L_G 76 | 77 | def precondition(L_K, L_G, u ,v): 78 | tau = 1e-8 79 | L_G_inv = np.linalg.inv(L_G + tau*np.eye(L_G.shape[0])) 80 | return (L_K.T @ u[:, :, None]).squeeze(-1), (L_G_inv.T @ v[:, :, None]).squeeze(-1) 81 | 82 | def compute_error(prediction, target): 83 | e = np.mean(np.linalg.norm(prediction - target, axis = -1)/np.linalg.norm(target, axis = -1)) 84 | 85 | return e 86 | 87 | def optimal_recovery(K, G, L_K, L_G, u, v): 88 | tau = 0 89 | #L_K_inv = np.linalg.inv(L_K + tau*np.eye(K.shape[0])) 90 | L_G_inv = np.linalg.inv(L_G + tau*np.eye(K.shape[0])) 91 | 92 | u = np.linalg.solve(L_K.T, u[:, :, None]).squeeze(-1) 93 | #u_recov = np.squeeze(K@scipy.linalg.cho_solve((L_K, True), u[None] )) 94 | u_recov = np.squeeze(K@scipy.linalg.solve(K, u.T, assume_a = 'pos' )).T 95 | v_recov = np.squeeze(G@L_G_inv@v[:, :, None]) 96 | 97 | return u_recov, v_recov 98 | 99 | def train_test(x_train, x_test, y_train, y_test): 100 | kernel = Matern(nu = 2.5, length_scale = 1.0) 101 | gp = GaussianProcessRegressor(kernel, alpha = 1e-10, normalize_y = False, random_state= 6032023) 102 | 103 | gp.fit(x_train, y_train) 104 | pred= gp.predict(x_test) 105 | #pred_train = gp.predict(x_train) 106 | 107 | #e = compute_error_dataset(y_test, pred, knots, k) 108 | 109 | return pred, gp 110 | 111 | 112 | #%% 113 | 114 | 115 | kernel_u =Matern(nu = 1.5, length_scale = 0.1) 116 | kernel_v = Matern(nu = 1.5, length_scale = 0.1) 117 | L_K, L_G = compute_cho(kernel_u, kernel_v, grid) 118 | 119 | x_train, y_train = precondition(L_K, L_G, x, y) 120 | x_val, y_val = precondition(L_K, L_G, x_test, y_test) 121 | 122 | 123 | pred, gp = train_test(x_train, x_val, y_train, y_val) 124 | pred_train = gp.predict(x_train) 125 | 126 | e = compute_error(pred, y_val) 127 | e_train = compute_error(pred_train, y_train) 128 | print(e, e_train) 129 | #%% 130 | 131 | # pointwise prediction 132 | K = kernel_u(grid) 133 | G = kernel_v(grid) 134 | _, pred_train_point = optimal_recovery(K, G, L_K, L_G, x_train, pred_train) 135 | _, pred_point = optimal_recovery(K, G, L_K, L_G, x_val, pred) 136 | 137 | e = compute_error(pred_point, y_test) 138 | e_train = compute_error(pred_train_point, y) 139 | print(e, e_train) 140 | 141 | 142 | #%% Bayesian optimization 143 | 144 | from skopt import gp_minimize 145 | from sklearn.model_selection import KFold 146 | 147 | def f_cv(x, y, nu_u, l_u, nu_v, l_v): 148 | 149 | kernel_u =Matern(nu = nu_u, length_scale = l_u) 150 | kernel_v = Matern(nu = nu_v, length_scale = l_v) 151 | 152 | print(kernel_u, kernel_v) 153 | 154 | kf = KFold(n_splits=5) 155 | 156 | L_K, L_G = compute_cho(kernel_u, kernel_v, grid) 157 | 158 | e = 0 159 | for train_index, test_index in kf.split(x): 160 | #print("TRAIN:", train_index, "TEST:", test_index) 161 | 162 | x_train, y_train = precondition(L_K, L_G, x[train_index], y[train_index]) 163 | x_val, y_val = precondition(L_K, L_G, x[test_index], y[test_index]) 164 | 165 | pred, gp = train_test(x_train, x_val, y_train, y_val) 166 | 167 | e += compute_error(pred, y_val) 168 | #print(e) 169 | return (e/5).item() 170 | 171 | 172 | f_opt = lambda param: f_cv(x, y, param[0], param[1], param[2], param[3]) 173 | 174 | #%% 175 | 176 | 177 | from skopt.space import Real, Integer, Categorical 178 | from skopt.utils import use_named_args 179 | 180 | space= [ Categorical([0.5, 1.5, 2.5, np.inf], name='nu_u'), 181 | Real(0.00001, 100000.0, name='length_scale_u'), 182 | Categorical([0.5, 1.5, 2.5, np.inf], name='nu_v'), 183 | Real(0.00001, 100000.0, name='length_scale_v') 184 | ] 185 | 186 | x0 = [1.5, 0.1, 1.5, 0.1] 187 | 188 | 189 | #x0 = [1.5, 10000, 1.5, 0.1] 190 | 191 | #%% 192 | 193 | print(f_opt(x0)) -------------------------------------------------------------------------------- /LowDataRegime/Burger's equation/plot_style-Examples.txt: -------------------------------------------------------------------------------- 1 | xtick.color: 323034 2 | ytick.color: 323034 3 | text.color: 323034 4 | lines.markeredgecolor: black 5 | patch.facecolor : bc80bd 6 | patch.force_edgecolor : True 7 | patch.linewidth: 0.8 8 | scatter.edgecolors: black 9 | grid.color: b1afb5 10 | axes.titlesize: 20 11 | legend.title_fontsize: 20 12 | xtick.labelsize: 30 13 | ytick.labelsize: 30 14 | axes.labelsize: 40 15 | font.size: 20 16 | image.cmap: coolwarm 17 | mathtext.fontset: stix 18 | font.family: STIXGeneral 19 | lines.linewidth: 2 20 | legend.frameon: True 21 | legend.framealpha: 0.8 22 | legend.fontsize: 16 23 | legend.edgecolor: 0.9 24 | legend.borderpad: 0.2 25 | legend.columnspacing: 1.5 26 | legend.labelspacing: 0.4 27 | text.usetex: True 28 | axes.titlelocation: left 29 | axes.formatter.use_mathtext: True 30 | axes.autolimit_mode: round_numbers 31 | axes.labelpad: 3 32 | axes.formatter.limits: -4, 4 33 | axes.labelcolor: black 34 | axes.edgecolor: black 35 | axes.linewidth: 0.6 36 | axes.spines.right : False 37 | axes.spines.top : False 38 | axes.grid: False 39 | figure.titlesize: 18 40 | figure.dpi: 300 41 | -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/ErrorDarcy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/ErrorDarcy.pdf -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/InputDarcy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/InputDarcy.pdf -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/OutputDarcy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/OutputDarcy.pdf -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/PredictedDarcy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/PredictedDarcy.pdf -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/Readme.md: -------------------------------------------------------------------------------- 1 | # Darcy problem in a rectangular domain (piecewise constant) 2 | 3 | See the following link for the data: 4 | https://github.com/lu-group/deeponet-fno/tree/main/data/darcy_rectangular_pwc 5 | 6 | **As of 10/12/24 the following links do not work anymore:** 7 | 8 | Code and data are taken from https://github.com/zongyi-li/fourier_neural_operator/tree/master/data_generation/darcy 9 | 10 | - [Data](https://drive.google.com/drive/folders/1Qzm64a2vN66is0LMYpO7cGwXxuhZHfPs?usp=sharing) 11 | -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/TrueDarcy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/TrueDarcy.pdf -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/example_prediction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/example_prediction.png -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/example_prediction2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/example_prediction2.png -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/example_prediction3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/example_prediction3.png -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/example_prediction4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/example_prediction4.png -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/example_prediction5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/example_prediction5.png -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/example_prediction_test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/example_prediction_test.png -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/plot_style-Examples.txt: -------------------------------------------------------------------------------- 1 | xtick.color: 323034 2 | ytick.color: 323034 3 | text.color: 323034 4 | lines.markeredgecolor: black 5 | patch.facecolor : bc80bd 6 | patch.force_edgecolor : True 7 | patch.linewidth: 0.8 8 | scatter.edgecolors: black 9 | grid.color: b1afb5 10 | axes.titlesize: 20 11 | legend.title_fontsize: 20 12 | xtick.labelsize: 30 13 | ytick.labelsize: 30 14 | axes.labelsize: 40 15 | font.size: 20 16 | image.cmap: coolwarm 17 | mathtext.fontset: stix 18 | font.family: STIXGeneral 19 | lines.linewidth: 2 20 | legend.frameon: True 21 | legend.framealpha: 0.8 22 | legend.fontsize: 16 23 | legend.edgecolor: 0.9 24 | legend.borderpad: 0.2 25 | legend.columnspacing: 1.5 26 | legend.labelspacing: 0.4 27 | text.usetex: True 28 | axes.titlelocation: left 29 | axes.formatter.use_mathtext: True 30 | axes.autolimit_mode: round_numbers 31 | axes.labelpad: 3 32 | axes.formatter.limits: -4, 4 33 | axes.labelcolor: black 34 | axes.edgecolor: black 35 | axes.linewidth: 0.6 36 | axes.spines.right : False 37 | axes.spines.top : False 38 | axes.grid: False 39 | figure.titlesize: 18 40 | figure.dpi: 300 41 | -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/test_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/test_example.png -------------------------------------------------------------------------------- /LowDataRegime/Darcy problem/training_example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MatthieuDarcy/KernelsOperatorLearning/b4b4a1f2cae630c452b4fe08258821f0464b9a6e/LowDataRegime/Darcy problem/training_example.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KernelsOperatorLearning 2 | 3 | Data for the high data regime needs to be downloaded from https://data.caltech.edu/records/20091, following the instructions in https://github.com/Zhengyu-Huang/Operator-Learning. 4 | 5 | For the low data regime, see the individual folders. 6 | --------------------------------------------------------------------------------