Update tutorial 1,3,4,9 plots
This commit is contained in:
21113
tutorials/tutorial1/tutorial.ipynb
vendored
21113
tutorials/tutorial1/tutorial.ipynb
vendored
File diff suppressed because one or more lines are too long
4
tutorials/tutorial1/tutorial.py
vendored
4
tutorials/tutorial1/tutorial.py
vendored
@@ -38,7 +38,7 @@
|
||||
#
|
||||
# ```python
|
||||
# from pina.problem import SpatialProblem
|
||||
# from pina.geometry import CartesianProblem
|
||||
# from pina.domain import CartesianProblem
|
||||
#
|
||||
# class SimpleODE(SpatialProblem):
|
||||
#
|
||||
@@ -233,7 +233,6 @@ trainer.train()
|
||||
|
||||
# inspecting final loss
|
||||
trainer.logged_metrics
|
||||
print(type(problem.truth_solution))
|
||||
|
||||
|
||||
# By using `matplotlib` we can also do some qualitative plots of the solution.
|
||||
@@ -260,7 +259,6 @@ list_ = [
|
||||
idx for idx, s in enumerate(trainer.callbacks)
|
||||
if isinstance(s, MetricTracker)
|
||||
]
|
||||
print(list_[0])
|
||||
trainer_metrics = trainer.callbacks[list_[0]].metrics
|
||||
|
||||
loss = trainer_metrics['val_loss']
|
||||
|
||||
28118
tutorials/tutorial3/tutorial.ipynb
vendored
28118
tutorials/tutorial3/tutorial.ipynb
vendored
File diff suppressed because one or more lines are too long
25
tutorials/tutorial3/tutorial.py
vendored
25
tutorials/tutorial3/tutorial.py
vendored
@@ -9,7 +9,7 @@
|
||||
#
|
||||
# First of all, some useful imports.
|
||||
|
||||
# In[12]:
|
||||
# In[1]:
|
||||
|
||||
|
||||
## routine needed to run the notebook on Google Colab
|
||||
@@ -50,7 +50,7 @@ from pina import Condition, LabelTensor
|
||||
|
||||
# Now, the wave problem is written in PINA code as a class, inheriting from `SpatialProblem` and `TimeDependentProblem` since we deal with spatial, and time dependent variables. The equations are written as `conditions` that should be satisfied in the corresponding domains. `truth_solution` is the exact solution which will be compared with the predicted one.
|
||||
|
||||
# In[13]:
|
||||
# In[2]:
|
||||
|
||||
|
||||
class Wave(TimeDependentProblem, SpatialProblem):
|
||||
@@ -96,7 +96,7 @@ problem = Wave()
|
||||
#
|
||||
# where $NN$ is the neural net output. This neural network takes as input the coordinates (in this case $x$, $y$ and $t$) and provides the unknown field $u$. By construction, it is zero on the boundaries. The residuals of the equations are evaluated at several sampling points (which the user can manipulate using the method `discretise_domain`) and the loss minimized by the neural network is the sum of the residuals.
|
||||
|
||||
# In[14]:
|
||||
# In[3]:
|
||||
|
||||
|
||||
class HardMLP(torch.nn.Module):
|
||||
@@ -120,7 +120,7 @@ class HardMLP(torch.nn.Module):
|
||||
|
||||
# In this tutorial, the neural network is trained for 1000 epochs with a learning rate of 0.001 (default in `PINN`). Training takes approximately 3 minutes.
|
||||
|
||||
# In[15]:
|
||||
# In[4]:
|
||||
|
||||
|
||||
# generate the data
|
||||
@@ -136,16 +136,13 @@ trainer.train()
|
||||
|
||||
# Notice that the loss on the boundaries of the spatial domain is exactly zero, as expected! After the training is completed one can now plot some results using the `Plotter` class of **PINA**.
|
||||
|
||||
# In[16]:
|
||||
# In[5]:
|
||||
|
||||
|
||||
#plotter = Plotter()
|
||||
|
||||
method='contourf'
|
||||
# plotting at fixed time t = 0.0
|
||||
print('Plotting at t=0')
|
||||
#plotter.plot(pinn, fixed_variables={'t': 0.0})
|
||||
fixed_variables={'t': 0.0}
|
||||
method='contourf'
|
||||
pts = pinn.problem.spatial_domain.sample(256, 'grid', variables=['x','y'])
|
||||
grids = [p_.reshape(256, 256) for p_ in pts.extract(['x','y']).T]
|
||||
fixed_pts = torch.ones(pts.shape[0], len(fixed_variables))
|
||||
@@ -228,7 +225,7 @@ ax[2].title.set_text('Residual')
|
||||
#
|
||||
# Let us build the network first
|
||||
|
||||
# In[17]:
|
||||
# In[6]:
|
||||
|
||||
|
||||
class HardMLPtime(torch.nn.Module):
|
||||
@@ -251,7 +248,7 @@ class HardMLPtime(torch.nn.Module):
|
||||
|
||||
# Now let's train with the same configuration as thre previous test
|
||||
|
||||
# In[18]:
|
||||
# In[7]:
|
||||
|
||||
|
||||
# generate the data
|
||||
@@ -267,16 +264,12 @@ trainer.train()
|
||||
|
||||
# We can clearly see that the loss is way lower now. Let's plot the results
|
||||
|
||||
# In[19]:
|
||||
# In[8]:
|
||||
|
||||
|
||||
#plotter = Plotter()
|
||||
|
||||
# plotting at fixed time t = 0.0
|
||||
print('Plotting at t=0')
|
||||
#plotter.plot(pinn, fixed_variables={'t': 0.0})
|
||||
fixed_variables={'t': 0.0}
|
||||
method='contourf'
|
||||
pts = pinn.problem.spatial_domain.sample(256, 'grid', variables=['x','y'])
|
||||
grids = [p_.reshape(256, 256) for p_ in pts.extract(['x','y']).T]
|
||||
fixed_pts = torch.ones(pts.shape[0], len(fixed_variables))
|
||||
|
||||
2165
tutorials/tutorial4/tutorial.ipynb
vendored
2165
tutorials/tutorial4/tutorial.ipynb
vendored
File diff suppressed because one or more lines are too long
4
tutorials/tutorial4/tutorial.py
vendored
4
tutorials/tutorial4/tutorial.py
vendored
@@ -25,10 +25,10 @@ import torch
|
||||
import matplotlib.pyplot as plt
|
||||
plt.style.use('tableau-colorblind10')
|
||||
from pina.problem import AbstractProblem
|
||||
from pina.solvers import SupervisedSolver
|
||||
from pina.solver import SupervisedSolver
|
||||
from pina.trainer import Trainer
|
||||
from pina import Condition, LabelTensor
|
||||
from pina.model.layers import ContinuousConvBlock
|
||||
from pina.model.block import ContinuousConvBlock
|
||||
import torchvision # for MNIST dataset
|
||||
from pina.model import FeedForward # for building AE and MNIST classification
|
||||
|
||||
|
||||
70044
tutorials/tutorial9/tutorial.ipynb
vendored
70044
tutorials/tutorial9/tutorial.ipynb
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user