Skip to content

Commit 7cc9679

Browse files
committed
docs: fix issues flagged by linter
1 parent fd3dfb0 commit 7cc9679

34 files changed

+399
-206
lines changed

examples/ala2_nys_tutorial.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139
},
140140
{
141141
"cell_type": "code",
142-
"execution_count": 4,
142+
"execution_count": null,
143143
"metadata": {
144144
"ExecuteTime": {
145145
"end_time": "2024-03-05T12:52:36.732175427Z",
@@ -175,7 +175,9 @@
175175
"x_tickslabels = [f\"{x:.0f}\" for x in (time_ns[::subsample])[::2000]]\n",
176176
"\n",
177177
"fig, ax = plt.subplots(figsize=(4, 4))\n",
178-
"ax.scatter(test_dihedrals[::subsample, 0], test_dihedrals[::subsample, 1], s=2, color = 'k', alpha = 0.2)\n",
178+
"ax.scatter(\n",
179+
" test_dihedrals[::subsample, 0], test_dihedrals[::subsample, 1], s=2, color='k', alpha=0.2\n",
180+
" )\n",
179181
"ax.set_xlabel(r\"Dihedral $\\phi$\")\n",
180182
"ax.set_ylabel(r\"Dihedral $\\psi$\")\n",
181183
"ax.set_xticks([-np.pi, 0, np.pi], [r\"$-\\pi$\", \"$0$\", r\"$\\pi$\"])\n",

examples/fluid_flow_dmd.ipynb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,13 @@
146146
},
147147
{
148148
"cell_type": "code",
149-
"execution_count": 5,
149+
"execution_count": null,
150150
"id": "dde80382",
151151
"metadata": {},
152152
"outputs": [],
153153
"source": [
154-
"# Custom scaler. Can't use sklearn StandardScaler, as it improperly averages over every dimension, while we want to keep the field-wise means and stds separate.\n",
154+
"# Custom scaler. Can't use sklearn StandardScaler, as it improperly averages over every dimension,\n",
155+
"# while we want to keep the field-wise means and stds separate.\n",
155156
"class FlowScaler(BaseEstimator, TransformerMixin):\n",
156157
" def fit(self, X, y=None):\n",
157158
" # Save shape for inverse_transform\n",
@@ -183,14 +184,15 @@
183184
},
184185
{
185186
"cell_type": "code",
186-
"execution_count": 6,
187+
"execution_count": null,
187188
"id": "84804b38",
188189
"metadata": {},
189190
"outputs": [],
190191
"source": [
191192
"from kooplearn.kernel import KernelRidge\n",
192193
"\n",
193-
"model = KernelRidge(n_components=128, reduced_rank=False, alpha=1e-5).fit(data_pipe.fit_transform(X))\n",
194+
"model = KernelRidge(n_components=128, reduced_rank=False, alpha=1e-5)\n",
195+
"model.fit(data_pipe.fit_transform(X))\n",
194196
"# Compute the dynamical modes\n",
195197
"dmd = model.dynamical_modes(data_pipe.fit_transform(X))"
196198
]
@@ -347,6 +349,7 @@
347349
"source": [
348350
"# Some nice plots\n",
349351
"import warnings\n",
352+
"\n",
350353
"warnings.filterwarnings(\"ignore\") # Suppress warning from annoying sklearn pipelines (see https://stackoverflow.com/questions/67943229/sklearn-pipeline-instance-is-not-fitted-yet-error-even-though-it-is)\n",
351354
"t_id = 100\n",
352355
"fig, axs = plt.subplots(ncols=2, nrows=2, figsize=(12, 3), dpi=200)\n",

examples/kernel_methods.ipynb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
{
6868
"cell_type": "code",
69-
"execution_count": 2,
69+
"execution_count": null,
7070
"metadata": {},
7171
"outputs": [
7272
{
@@ -85,7 +85,15 @@
8585
"\n",
8686
"fig = plt.figure(figsize=(6,6))\n",
8787
"ax = fig.add_subplot(111, projection='3d')\n",
88-
"ax.plot(train_set[:, 0], train_set[:, 1], train_set[:, 2], lw=1, label='Training Set', color='k', alpha=0.3)\n",
88+
"ax.plot(\n",
89+
" train_set[:, 0],\n",
90+
" train_set[:, 1],\n",
91+
" train_set[:, 2],\n",
92+
" lw=1,\n",
93+
" label='Training Set',\n",
94+
" color='k',\n",
95+
" alpha=0.3\n",
96+
" )\n",
8997
"ax.plot(test_set[:, 0], test_set[:, 1], test_set[:, 2], lw=2, label='Test Set', color='#e60049')\n",
9098
"\n",
9199
"plt.legend(frameon=False)\n",
@@ -416,7 +424,7 @@
416424
"provenance": []
417425
},
418426
"kernelspec": {
419-
"display_name": "kooplearn",
427+
"display_name": ".venv",
420428
"language": "python",
421429
"name": "python3"
422430
},
@@ -430,7 +438,7 @@
430438
"name": "python",
431439
"nbconvert_exporter": "python",
432440
"pygments_lexer": "ipython3",
433-
"version": "3.13.1"
441+
"version": "3.13.7"
434442
},
435443
"widgets": {
436444
"application/vnd.jupyter.widget-state+json": {

examples/linear_system.ipynb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
{
3535
"cell_type": "code",
36-
"execution_count": 1,
36+
"execution_count": null,
3737
"id": "a8d750ebf6efec3f",
3838
"metadata": {
3939
"ExecuteTime": {
@@ -61,7 +61,9 @@
6161
"# Dataset generation and splitting\n",
6262
"train_samples = int(1e5)\n",
6363
"test_samples = int(1e3)\n",
64-
"data = make_linear_system(X0 = X0, A=A, n_steps=train_samples + 100 + train_samples, noise=0.1, random_state=seed)\n",
64+
"data = make_linear_system(\n",
65+
" X0 = X0, A=A, n_steps=train_samples + 100 + train_samples, noise=0.1, random_state=seed\n",
66+
" )\n",
6567
"train_set = data[: train_samples + 1]\n",
6668
"test_set = data[: test_samples + 1]"
6769
]
@@ -188,7 +190,7 @@
188190
],
189191
"metadata": {
190192
"kernelspec": {
191-
"display_name": "kooplearn",
193+
"display_name": ".venv",
192194
"language": "python",
193195
"name": "python3"
194196
},
@@ -202,7 +204,7 @@
202204
"name": "python",
203205
"nbconvert_exporter": "python",
204206
"pygments_lexer": "ipython3",
205-
"version": "3.13.1"
207+
"version": "3.13.7"
206208
}
207209
},
208210
"nbformat": 4,

examples/logistic_map.ipynb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@
332332
},
333333
{
334334
"cell_type": "code",
335-
"execution_count": 7,
335+
"execution_count": null,
336336
"metadata": {},
337337
"outputs": [],
338338
"source": [
@@ -390,7 +390,8 @@
390390
"\n",
391391
" if (epoch + 1) % 5 == 0 or (epoch == 0):\n",
392392
" print(\n",
393-
" f\"EPOCH {epoch + 1:>2} Loss: {np.mean(train_loss):.2f} (train) - {np.mean(val_loss):.2f} (val)\"\n",
393+
" f\"EPOCH {epoch + 1:>2} Loss: {np.mean(train_loss):.2f} (train) - \" \\\n",
394+
" f\"{np.mean(val_loss):.2f} (val)\"\n",
394395
" )\n",
395396
"\n",
396397
" embedder = FeatureMapEmbedder(encoder=model)\n",
@@ -600,7 +601,7 @@
600601
},
601602
{
602603
"cell_type": "code",
603-
"execution_count": 11,
604+
"execution_count": null,
604605
"metadata": {},
605606
"outputs": [
606607
{
@@ -625,7 +626,8 @@
625626
" spectral_dist = directed_hausdorff_distance(OLS_eigs, ref_eigs)\n",
626627
" empirical_spectral_dist = directed_hausdorff_distance(empirical_OLS_eigs, ref_eigs)\n",
627628
" print(\n",
628-
" f\"{key} - Spectral Dist: {spectral_dist:.4f} - Empirical Spectral Dist: {empirical_spectral_dist:.4f}\"\n",
629+
" f\"{key} - Spectral Dist: {spectral_dist:.4f} - Empirical Spectral Dist: \" \\\n",
630+
" f\"{empirical_spectral_dist:.4f}\"\n",
629631
" )"
630632
]
631633
}
@@ -636,7 +638,7 @@
636638
"version": ""
637639
},
638640
"kernelspec": {
639-
"display_name": "kooplearn",
641+
"display_name": ".venv",
640642
"language": "python",
641643
"name": "python3"
642644
},
@@ -650,7 +652,7 @@
650652
"name": "python",
651653
"nbconvert_exporter": "python",
652654
"pygments_lexer": "ipython3",
653-
"version": "3.13.1"
655+
"version": "3.13.7"
654656
}
655657
},
656658
"nbformat": 4,

examples/ordered_mnist_jax.ipynb

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@
505505
},
506506
{
507507
"cell_type": "code",
508-
"execution_count": 9,
508+
"execution_count": null,
509509
"id": "7ba18357",
510510
"metadata": {},
511511
"outputs": [
@@ -544,7 +544,8 @@
544544
"from kooplearn.jax.nn import spectral_contrastive_loss, vamp_loss\n",
545545
"\n",
546546
"_vamp_loss = partial(vamp_loss, center_covariances=False)\n",
547-
"for name, criterion in zip([\"VAMPNets\", \"Spectral Contrastive Loss\"], [ _vamp_loss, spectral_contrastive_loss]):\n",
547+
"for name, criterion in zip([\"VAMPNets\", \"Spectral Contrastive Loss\"],\n",
548+
" [ _vamp_loss, spectral_contrastive_loss]):\n",
548549
" print(f\"Fitting {name}\")\n",
549550
" trained_models[name] = train_encoder_only(criterion)"
550551
]
@@ -784,7 +785,7 @@
784785
},
785786
{
786787
"cell_type": "code",
787-
"execution_count": 13,
788+
"execution_count": null,
788789
"id": "9a43f6cd",
789790
"metadata": {},
790791
"outputs": [
@@ -802,7 +803,9 @@
802803
"source": [
803804
"nun_models = len(report)\n",
804805
"num_cols = len(report['Linear']['times'])\n",
805-
"fig, axes = plt.subplots(nun_models, num_cols, figsize=(num_cols, nun_models), sharex=True, sharey=True)\n",
806+
"fig, axes = plt.subplots(\n",
807+
" nun_models, num_cols, figsize=(num_cols, nun_models), sharex=True, sharey=True\n",
808+
" )\n",
806809
"\n",
807810
"test_seed_idx = 0\n",
808811
"# Remove margins between columns\n",
@@ -815,7 +818,9 @@
815818
" ax.set_axis_off()\n",
816819
" for prediction_step in range(num_cols - 1):\n",
817820
" pred_label = report[model_name]['label'][prediction_step][test_seed_idx]\n",
818-
" true_label = (test_labels[test_seed_idx] + report[model_name]['times'][prediction_step])%num_digits\n",
821+
" true_label = (\n",
822+
" test_labels[test_seed_idx] + report[model_name]['times'][prediction_step]\n",
823+
" )%num_digits\n",
819824
" img = report[model_name]['image'][prediction_step][test_seed_idx]\n",
820825
" logit = report[model_name]['logits'][prediction_step][test_seed_idx]\n",
821826
"\n",
@@ -848,7 +853,15 @@
848853
"\n",
849854
"# Display the model names on the left of each row\n",
850855
"for model_idx, model_name in enumerate(report.keys()):\n",
851-
" axes[model_idx, 0].text(-0.1, 0.5, model_name.replace('_', ' '), fontsize=14, ha='right', va='center', transform=axes[model_idx, 0].transAxes)\n",
856+
" axes[model_idx, 0].text(\n",
857+
" -0.1,\n",
858+
" 0.5,\n",
859+
" model_name.replace('_', ' '),\n",
860+
" fontsize=14,\n",
861+
" ha='right',\n",
862+
" va='center',\n",
863+
" transform=axes[model_idx, 0].transAxes\n",
864+
" )\n",
852865
"\n",
853866
"for class_idx in range(num_cols):\n",
854867
" title = (test_labels[test_seed_idx] + class_idx)%num_digits\n",
@@ -879,7 +892,7 @@
879892
},
880893
{
881894
"cell_type": "code",
882-
"execution_count": 14,
895+
"execution_count": null,
883896
"id": "617e1987",
884897
"metadata": {},
885898
"outputs": [
@@ -906,9 +919,13 @@
906919
" ax.title.set_text(model_name.replace('_', ' '))\n",
907920
" fitted_model = trained_models[model_name]['model']\n",
908921
" embedder = trained_models[model_name]['embedder']\n",
909-
" vals, lfuncs, rfuncs = fitted_model.eig(eval_right_on=embedder.transform(test_data), eval_left_on=embedder.transform(test_data))\n",
922+
" vals, lfuncs, rfuncs = fitted_model.eig(\n",
923+
" eval_right_on=embedder.transform(test_data),\n",
924+
" eval_left_on=embedder.transform(test_data)\n",
925+
" )\n",
910926
"\n",
911-
" unique_vals, idx_start = np.unique(np.abs(vals), return_index=True) # returns the unique values and the index of the first occurrence of a value\n",
927+
" unique_vals, idx_start = np.unique(np.abs(vals), return_index=True) # returns the unique values\n",
928+
" # and the index of the first occurrence of a value\n",
912929
"\n",
913930
" vals, lfuncs, rfuncs = vals[idx_start], lfuncs[:, idx_start], rfuncs[:, idx_start]\n",
914931
" top_vals, top_indices = stable_topk(np.abs(vals), 2)\n",
@@ -923,7 +940,9 @@
923940
"\n",
924941
"# remove last axis and add legend\n",
925942
"ax = axes[n_models-1]\n",
926-
"legend = ax.legend(*scatter.legend_elements(num=4), title=\"Digits\", frameon=True, bbox_to_anchor=(1.3, 1))\n",
943+
"legend = ax.legend(\n",
944+
" *scatter.legend_elements(num=4), title=\"Digits\", frameon=True, bbox_to_anchor=(1.3, 1)\n",
945+
" )\n",
927946
"ax.add_artist(legend)\n",
928947
"fig.delaxes(axes[n_models])\n",
929948
"\n",
@@ -943,7 +962,7 @@
943962
],
944963
"metadata": {
945964
"kernelspec": {
946-
"display_name": "kooplearn",
965+
"display_name": ".venv",
947966
"language": "python",
948967
"name": "python3"
949968
},
@@ -957,7 +976,7 @@
957976
"name": "python",
958977
"nbconvert_exporter": "python",
959978
"pygments_lexer": "ipython3",
960-
"version": "3.13.1"
979+
"version": "3.13.7"
961980
}
962981
},
963982
"nbformat": 4,

0 commit comments

Comments
 (0)