|
12 | 12 | }, |
13 | 13 | { |
14 | 14 | "cell_type": "code", |
15 | | - "execution_count": 1, |
| 15 | + "execution_count": 3, |
16 | 16 | "id": "5e5ea3c3-aed3-4b8d-a7c7-1db05fc73f3c", |
17 | 17 | "metadata": {}, |
18 | 18 | "outputs": [], |
|
31 | 31 | "from pynumdiff.utils.simulate import sine, triangle, pop_dyn, linear_autonomous, pi_cruise_control, lorenz_x\n", |
32 | 32 | "from pynumdiff.utils.evaluate import rmse, error_correlation\n", |
33 | 33 | "from pynumdiff.finite_difference import finitediff\n", |
34 | | - "from pynumdiff.smooth_finite_difference import mediandiff, meandiff, gaussiandiff, friedrichsdiff, butterdiff\n", |
| 34 | + "from pynumdiff.smooth_finite_difference import kerneldiff, butterdiff\n", |
35 | 35 | "from pynumdiff.polynomial_fit import splinediff, polydiff, savgoldiff\n", |
36 | 36 | "from pynumdiff.basis_fit import spectraldiff, rbfdiff\n", |
37 | 37 | "from pynumdiff.total_variation_regularization import tvrdiff, smooth_acceleration\n", |
|
49 | 49 | }, |
50 | 50 | { |
51 | 51 | "cell_type": "code", |
52 | | - "execution_count": 2, |
| 52 | + "execution_count": 4, |
53 | 53 | "id": "ef461de3-e615-4c32-8931-51bf60d8e16c", |
54 | 54 | "metadata": {}, |
55 | 55 | "outputs": [ |
|
74 | 74 | }, |
75 | 75 | { |
76 | 76 | "cell_type": "code", |
77 | | - "execution_count": 13, |
| 77 | + "execution_count": 5, |
78 | 78 | "id": "1eba51f1-bf31-4f84-b82b-176461319de6", |
79 | 79 | "metadata": {}, |
80 | 80 | "outputs": [], |
81 | 81 | "source": [ |
82 | | - "methods = [(meandiff, 'MeanDiff'),\n", |
83 | | - "\t\t\t(mediandiff, 'MedianDiff'),\n", |
84 | | - "\t\t\t(gaussiandiff, 'GaussianDiff'),\n", |
85 | | - "\t\t\t(friedrichsdiff, 'FriedrichsDiff'),\n", |
| 82 | + "methods = [(kerneldiff, 'KernelDiff'),\n", |
86 | 83 | "\t\t\t(butterdiff, 'ButterDiff'),\n", |
87 | 84 | "\t\t\t(splinediff, 'SplineDiff'),\n", |
88 | 85 | "\t\t\t(polydiff, 'PolyDiff'),\n", |
|
112 | 109 | }, |
113 | 110 | { |
114 | 111 | "cell_type": "code", |
115 | | - "execution_count": 5, |
| 112 | + "execution_count": 6, |
116 | 113 | "id": "275e4552-4479-40e3-b111-41c35d62ee9e", |
117 | 114 | "metadata": {}, |
118 | 115 | "outputs": [], |
|
121 | 118 | "\t\"\"\"Create and save a dataframe of results over all methods for all sims, given a certain\n", |
122 | 119 | "\thyperparameterization. Each one of these takes about 11 minutes on my machine\"\"\"\t\n", |
123 | 120 | "\ttry: # short circuit if the file already exists, just read in and display\n", |
124 | | - "\t\tres = pandas.read_csv(f\"~/Desktop/results2/{cutoff_frequency}_{dt}_{noise_type}_{noise_scale}_{outliers}_{random_seed}.csv\",\n", |
| 121 | + "\t\tres = pandas.read_csv(f\"~/Desktop/results/{cutoff_frequency}_{dt}_{noise_type}_{noise_scale}_{outliers}_{random_seed}.csv\",\n", |
125 | 122 | "\t\t\t\t\t\t\t index_col=0)\n", |
126 | 123 | "\t\tprint(\".\", end='')\n", |
127 | 124 | "\texcept FileNotFoundError:\n", |
128 | 125 | "\t\ttvgamma = np.exp(-1.6*np.log(cutoff_frequency) -0.71*np.log(dt) - 5.1)\n", |
129 | | - "\t\t#res = pandas.DataFrame(index=[x[1] for x in methods], columns=[x[1] for x in sims])\n", |
130 | | - "\t\tres = pandas.read_csv(f\"~/Desktop/results/{cutoff_frequency}_{dt}_{noise_type}_{noise_scale}_{outliers}_{random_seed}.csv\",\n", |
131 | | - "\t\t\t\t\t\t\t index_col=0)\n", |
| 126 | + "\t\tres = pandas.DataFrame(index=[x[1] for x in methods], columns=[x[1] for x in sims])\n", |
| 127 | + "\t\t#res = pandas.read_csv(f\"~/Desktop/results/{cutoff_frequency}_{dt}_{noise_type}_{noise_scale}_{outliers}_{random_seed}.csv\",\n", |
| 128 | + "\t\t#\t\t\t\t\t index_col=0)\n", |
132 | 129 | "\n", |
133 | 130 | "\t\tfor sim,sname in tqdm(sims):\n", |
134 | 131 | "\t\t\tx, x_truth, dxdt_truth = sim(duration=4, dt=dt, noise_type=noise_type,\n", |
|
137 | 134 | "\t\t\t#t = np.arange(0,dt*len(x), dt)\n", |
138 | 135 | "\t\t\n", |
139 | 136 | "\t\t\t#for method,mname in tqdm(methods):\n", |
140 | | - "\t\t\tmethod,mname = (robustdiff, 'RobustDiff') # ADDING A METHOD\n", |
| 137 | + "\t\t\tmethod,mname = (robustdiff, 'KernelDiff') # ADDING A METHOD\n", |
141 | 138 | "\t\t\t#best_params, best_rmse = optimize(method, x, dt, dxdt_truth=dxdt_truth, metric='rmse')\n", |
142 | 139 | "\t\t\t#best_params, best_ec = optimize(method, x, dt, dxdt_truth=dxdt_truth, metric='error_correlation')\n", |
143 | 140 | "\t\t\tbest_params, best_score = optimize(method, x, dt, tvgamma=tvgamma,\n", |
|
148 | 145 | "\t\t\tec = error_correlation(dxdt_hat, dxdt_truth)\n", |
149 | 146 | "\t\t\tres.loc[mname, sname] = f\"RMSE: {rms_dxdt:.5g}<br/>R^2: {ec:.5g}\"\n", |
150 | 147 | "\t\n", |
151 | | - "\t\tres.to_csv(f\"~/Desktop/results2/{cutoff_frequency}_{dt}_{noise_type}_{noise_scale}_{outliers}_{random_seed}.csv\")\n", |
| 148 | + "\t\tres.to_csv(f\"~/Desktop/results/{cutoff_frequency}_{dt}_{noise_type}_{noise_scale}_{outliers}_{random_seed}.csv\")\n", |
152 | 149 | "\n", |
153 | 150 | "\t\tdisplay(HTML(res.style.set_caption(\n", |
154 | 151 | "\t\t\tf\"cutoff_frequency={cutoff_frequency}, dt={dt}, noise_type={noise_type}, noise_scale={noise_scale}, outliers={outliers}, random_seed={random_seed}\").set_properties(\n", |
|
169 | 166 | "execution_count": null, |
170 | 167 | "id": "fac1f6c9-f657-492b-8b68-9bdc28298261", |
171 | 168 | "metadata": {}, |
172 | | - "outputs": [], |
| 169 | + "outputs": [ |
| 170 | + { |
| 171 | + "name": "stderr", |
| 172 | + "output_type": "stream", |
| 173 | + "text": [ |
| 174 | + " 0%| | 0/6 [00:00<?, ?it/s]" |
| 175 | + ] |
| 176 | + } |
| 177 | + ], |
173 | 178 | "source": [ |
174 | 179 | "for random_seed in random_seeds:\n", |
175 | 180 | "\t# Does dt matter? Vary dt, keeping everything else constant\n", |
176 | | - "\t# for dt in dts: # 4\n", |
177 | | - "\t# \tmain_loop(dt=dt, cutoff_frequency=3, noise_type='normal', noise_params=[0, 0.1], noise_scale=1,\n", |
178 | | - "\t# \t\t\t outliers=False, random_seed=random_seed)\n", |
| 181 | + "\tfor dt in dts: # 4\n", |
| 182 | + "\t\tmain_loop(dt=dt, cutoff_frequency=3, noise_type='normal', noise_params=[0, 0.1], noise_scale=1,\n", |
| 183 | + "\t\t\t\t outliers=False, random_seed=random_seed)\n", |
179 | 184 | "\n", |
180 | | - "\t# # Does noise type matter? Vary noise type, keeping everything else constant\n", |
181 | | - "\t# for noise_type,noise_params in noise_types: # 3\n", |
182 | | - "\t# \tmain_loop(dt=0.01, cutoff_frequency=3, noise_type=noise_type, noise_params=noise_params, noise_scale=1,\n", |
183 | | - "\t# \t\t\t outliers=False, random_seed=random_seed)\n", |
| 185 | + "\t# Does noise type matter? Vary noise type, keeping everything else constant\n", |
| 186 | + "\tfor noise_type,noise_params in noise_types: # 3\n", |
| 187 | + "\t\tmain_loop(dt=0.01, cutoff_frequency=3, noise_type=noise_type, noise_params=noise_params, noise_scale=1,\n", |
| 188 | + "\t\t\t\t outliers=False, random_seed=random_seed)\n", |
184 | 189 | "\t\n", |
185 | | - "\t# # Does noise scale matter? Vary noise scale, keeping everything else constant\n", |
186 | | - "\t# for noise_scale in noise_scales: # 4\n", |
187 | | - "\t# \tmain_loop(dt=0.01, cutoff_frequency=3, noise_type='normal', noise_params=[0,0.1], noise_scale=noise_scale,\n", |
188 | | - "\t# \t\t\t outliers=False, random_seed=random_seed)\n", |
| 190 | + "\t# Does noise scale matter? Vary noise scale, keeping everything else constant\n", |
| 191 | + "\tfor noise_scale in noise_scales: # 4\n", |
| 192 | + "\t\tmain_loop(dt=0.01, cutoff_frequency=3, noise_type='normal', noise_params=[0,0.1], noise_scale=noise_scale,\n", |
| 193 | + "\t\t\t\t outliers=False, random_seed=random_seed)\n", |
189 | 194 | "\t\n", |
190 | 195 | "\t# Does the presence of outliers matter? Vary presence of outliers, keeping everything else constant\n", |
191 | 196 | "\tfor outliers in [False, True]: # 2 Maybe try this one with more noise types too?\n", |
192 | 197 | "\t\tmain_loop(dt=0.01, cutoff_frequency=3, noise_type='normal', noise_params=[0, 0.1], noise_scale=1,\n", |
193 | 198 | "\t\t\t\t outliers=outliers, random_seed=random_seed)\n", |
194 | 199 | "\t\n", |
195 | | - "\t# #Does the cutoff frequency matter? Vary cutoff, keeping everything else constant\n", |
196 | | - "\t# for cutoff_frequency in cutoff_frequencies: # 5\n", |
197 | | - "\t# \tmain_loop(dt=0.01, cutoff_frequency=cutoff_frequency, noise_type='normal', noise_params=[0, 0.1], noise_scale=1,\n", |
198 | | - "\t# \t\t\t outliers=False, random_seed=random_seed)\n", |
| 200 | + "\t# Does the cutoff frequency matter? Vary cutoff, keeping everything else constant\n", |
| 201 | + "\tfor cutoff_frequency in cutoff_frequencies: # 5\n", |
| 202 | + "\t\tmain_loop(dt=0.01, cutoff_frequency=cutoff_frequency, noise_type='normal', noise_params=[0, 0.1], noise_scale=1,\n", |
| 203 | + "\t\t\t\t outliers=False, random_seed=random_seed)\n", |
199 | 204 | "\t\n", |
200 | | - "\t# Because they all pass through the central point, the number of unique runs here is 4 + 3 + 2 + 1 + 2 = 12 * 11 minutes = 2 hours\n", |
201 | | - "\t# repeat for each random seed = 10 hours?" |
| 205 | + "\t# Because they all pass through the central point, the number of unique runs here is 4 + 2 + 3 + 1 + 4 = 14" |
202 | 206 | ] |
203 | 207 | }, |
204 | 208 | { |
|
224 | 228 | "\t\"\"\"\n", |
225 | 229 | "\tfig, ax = plt.subplots(2, 1, figsize=(30, 12), sharex=True, gridspec_kw={'hspace': 0})\n", |
226 | 230 | "\n", |
227 | | - "\tmarkers = ['^', 's', 'p', 'h', 'd', '2', '+', 'x', '*', r'$\\rho$', 'o', r'$\\gamma$', r'$\\tilde{\\gamma}$', '.', r'$M$']\n", |
228 | | - "\tfacecolors = ['none' if i not in [5,6,7,13] else None for i in range(len(markers))] # 'none makes transparent'\n", |
229 | | - "\tsizes = [90, 70, 90, 90, 80, 120, 100, 70, 120, 90, 70, 90, 170, 70, 120]\n", |
| 231 | + "\tmarkers = ['p', 'd', '*', '2', '+', 'x', 'o', '.', r'$\\gamma$', r'$\\tilde{\\gamma}$', '^', 's']\n", |
| 232 | + "\tfacecolors = ['none' if i not in [3,4,5,7] else None for i in range(len(markers))] # 'none makes transparent'\n", |
| 233 | + "\tsizes = [90, 80, 120, 120, 100, 70, 70, 70, 90, 170, 90, 70]\n", |
230 | 234 | "\tcmap = plt.get_cmap('turbo', 6) # Assign a unique color for each simulation\n", |
231 | 235 | "\tcolors = [cmap(i) for i in range(6)]; colors[0] = 'purple'; colors[-1] = 'red'\n", |
232 | 236 | "\tcolors[2] = [x*0.8 for x in colors[2]]; colors[3] = mcolors.to_rgb('gold'); colors[3] = [x*0.9 for x in colors[3]]\n", |
|
0 commit comments