Skip to content

Commit 886a298

Browse files
MatteB03ndem0
authored andcommitted
Update tutorials 1 through 12 to current version 0.2
1 parent a765a9f commit 886a298

File tree

4 files changed

+70
-62
lines changed

4 files changed

+70
-62
lines changed

tutorials/tutorial1/tutorial.ipynb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,15 @@
137137
"execution_count": 2,
138138
"id": "f2608e2e",
139139
"metadata": {},
140-
"outputs": [],
140+
"outputs": [
141+
{
142+
"name": "stderr",
143+
"output_type": "stream",
144+
"text": [
145+
"/home/matte_b/PINA/pina/operators.py: DeprecationWarning: 'pina.operators' is deprecated and will be removed in future versions. Please use 'pina.operator' instead.\n"
146+
]
147+
}
148+
],
141149
"source": [
142150
"from pina.problem import SpatialProblem\n",
143151
"from pina.operator import grad\n",

tutorials/tutorial1/tutorial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class TimeSpaceODE(SpatialProblem, TimeDependentProblem):
8989
#
9090
# Once the `Problem` class is initialized, we need to represent the differential equation in **PINA**. In order to do this, we need to load the **PINA** operators from `pina.operators` module. Again, we'll consider Equation (1) and represent it in **PINA**:
9191

92-
# In[2]:
92+
# In[ ]:
9393

9494

9595
from pina.problem import SpatialProblem

tutorials/tutorial4/tutorial.ipynb

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -869,16 +869,16 @@
869869
"output = net(input_data).detach()\n",
870870
"\n",
871871
"# visualize data\n",
872-
"fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))\n",
873-
"pic1 = axes[0].scatter(grid[:, 0], grid[:, 1], c=input_data[0, 0, :, -1])\n",
874-
"axes[0].set_title(\"Real\")\n",
875-
"fig.colorbar(pic1)\n",
876-
"plt.subplot(1, 2, 2)\n",
877-
"pic2 = axes[1].scatter(grid[:, 0], grid[:, 1], c=output[0, 0, :, -1])\n",
878-
"axes[1].set_title(\"Autoencoder\")\n",
879-
"fig.colorbar(pic2)\n",
880-
"plt.tight_layout()\n",
881-
"plt.show()\n"
872+
"#fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))\n",
873+
"#pic1 = axes[0].scatter(grid[:, 0], grid[:, 1], c=input_data[0, 0, :, -1])\n",
874+
"#axes[0].set_title(\"Real\")\n",
875+
"#fig.colorbar(pic1)\n",
876+
"#plt.subplot(1, 2, 2)\n",
877+
"#pic2 = axes[1].scatter(grid[:, 0], grid[:, 1], c=output[0, 0, :, -1])\n",
878+
"#axes[1].set_title(\"Autoencoder\")\n",
879+
"#fig.colorbar(pic2)\n",
880+
"#plt.tight_layout()\n",
881+
"#plt.show()\n"
882882
]
883883
},
884884
{
@@ -963,16 +963,16 @@
963963
"output = net.decoder(latent, input_data2).detach()\n",
964964
"\n",
965965
"# show the picture\n",
966-
"fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))\n",
967-
"pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])\n",
968-
"axes[0].set_title(\"Real\")\n",
969-
"fig.colorbar(pic1)\n",
970-
"plt.subplot(1, 2, 2)\n",
971-
"pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])\n",
972-
"axes[1].set_title(\"Up-sampling\")\n",
973-
"fig.colorbar(pic2)\n",
974-
"plt.tight_layout()\n",
975-
"plt.show()\n"
966+
"#fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))\n",
967+
"#pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])\n",
968+
"#axes[0].set_title(\"Real\")\n",
969+
"#fig.colorbar(pic1)\n",
970+
"#plt.subplot(1, 2, 2)\n",
971+
"#pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])\n",
972+
"# axes[1].set_title(\"Up-sampling\")\n",
973+
"#fig.colorbar(pic2)\n",
974+
"#plt.tight_layout()\n",
975+
"#plt.show()\n"
976976
]
977977
},
978978
{
@@ -1051,16 +1051,16 @@
10511051
"output = net.decoder(latent, input_data2).detach()\n",
10521052
"\n",
10531053
"# show the picture\n",
1054-
"fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))\n",
1055-
"pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])\n",
1056-
"axes[0].set_title(\"Real\")\n",
1057-
"fig.colorbar(pic1)\n",
1058-
"plt.subplot(1, 2, 2)\n",
1059-
"pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])\n",
1060-
"axes[1].set_title(\"Autoencoder not re-trained\")\n",
1061-
"fig.colorbar(pic2)\n",
1062-
"plt.tight_layout()\n",
1063-
"plt.show()\n",
1054+
"#fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))\n",
1055+
"#pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])\n",
1056+
"#axes[0].set_title(\"Real\")\n",
1057+
"#fig.colorbar(pic1)\n",
1058+
"#plt.subplot(1, 2, 2)\n",
1059+
"#pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])\n",
1060+
"#axes[1].set_title(\"Autoencoder not re-trained\")\n",
1061+
"#fig.colorbar(pic2)\n",
1062+
"#plt.tight_layout()\n",
1063+
"#plt.show()\n",
10641064
"\n",
10651065
"# calculate l2 error\n",
10661066
"print(f'l2 error: {l2_error(input_data2[0, 0, :, -1], output[0, 0, :, -1]):.2%}')"

tutorials/tutorial4/tutorial.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -530,16 +530,16 @@ class CircleProblem(AbstractProblem):
530530
output = net(input_data).detach()
531531

532532
# visualize data
533-
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))
534-
pic1 = axes[0].scatter(grid[:, 0], grid[:, 1], c=input_data[0, 0, :, -1])
535-
axes[0].set_title("Real")
536-
fig.colorbar(pic1)
537-
plt.subplot(1, 2, 2)
538-
pic2 = axes[1].scatter(grid[:, 0], grid[:, 1], c=output[0, 0, :, -1])
539-
axes[1].set_title("Autoencoder")
540-
fig.colorbar(pic2)
541-
plt.tight_layout()
542-
plt.show()
533+
#fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))
534+
#pic1 = axes[0].scatter(grid[:, 0], grid[:, 1], c=input_data[0, 0, :, -1])
535+
#axes[0].set_title("Real")
536+
#fig.colorbar(pic1)
537+
#plt.subplot(1, 2, 2)
538+
#pic2 = axes[1].scatter(grid[:, 0], grid[:, 1], c=output[0, 0, :, -1])
539+
#axes[1].set_title("Autoencoder")
540+
#fig.colorbar(pic2)
541+
#plt.tight_layout()
542+
#plt.show()
543543

544544

545545
# As we can see, the two solutions are really similar! We can compute the $l_2$ error quite easily as well:
@@ -579,16 +579,16 @@ def l2_error(input_, target):
579579
output = net.decoder(latent, input_data2).detach()
580580

581581
# show the picture
582-
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))
583-
pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])
584-
axes[0].set_title("Real")
585-
fig.colorbar(pic1)
586-
plt.subplot(1, 2, 2)
587-
pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])
588-
axes[1].set_title("Up-sampling")
589-
fig.colorbar(pic2)
590-
plt.tight_layout()
591-
plt.show()
582+
#fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))
583+
#pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])
584+
#axes[0].set_title("Real")
585+
#fig.colorbar(pic1)
586+
#plt.subplot(1, 2, 2)
587+
#pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])
588+
# axes[1].set_title("Up-sampling")
589+
#fig.colorbar(pic2)
590+
#plt.tight_layout()
591+
#plt.show()
592592

593593

594594
# As we can see we have a very good approximation of the original function, even thought some noise is present. Let's calculate the error now:
@@ -621,16 +621,16 @@ def l2_error(input_, target):
621621
output = net.decoder(latent, input_data2).detach()
622622

623623
# show the picture
624-
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))
625-
pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])
626-
axes[0].set_title("Real")
627-
fig.colorbar(pic1)
628-
plt.subplot(1, 2, 2)
629-
pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])
630-
axes[1].set_title("Autoencoder not re-trained")
631-
fig.colorbar(pic2)
632-
plt.tight_layout()
633-
plt.show()
624+
#fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(8, 3))
625+
#pic1 = axes[0].scatter(grid2[:, 0], grid2[:, 1], c=input_data2[0, 0, :, -1])
626+
#axes[0].set_title("Real")
627+
#fig.colorbar(pic1)
628+
#plt.subplot(1, 2, 2)
629+
#pic2 = axes[1].scatter(grid2[:, 0], grid2[:, 1], c=output[0, 0, :, -1])
630+
#axes[1].set_title("Autoencoder not re-trained")
631+
#fig.colorbar(pic2)
632+
#plt.tight_layout()
633+
#plt.show()
634634

635635
# calculate l2 error
636636
print(f'l2 error: {l2_error(input_data2[0, 0, :, -1], output[0, 0, :, -1]):.2%}')

0 commit comments

Comments
 (0)