Solving physics problems by using Deep Learning
Project description
pinn-ics
PINN framework
Installation
pip install pinn-ics
- Remark : The lastest version is
1.0.0
Syntax
Var Configuration
-
pinnics
requires configurations for all variables.-
VarSpec
can import directly frompinnics
-
VarSpec
object containsindentify character
andlimit
of this variable.
-
-
Example:
-
Your solution depends on 2 domains:
dimension
andtime
. -
Format
u(x, t)
-
from pinnics import VarSpec
x = VarSpec('x', limit=(-1, 1))
t = VarSpec('x') # which defaults the limit of var t from 0 to 1
Function Definition
-
pinnics
supports solving partial differential equation with the simple syntax.- Define a
function
with format:
import numpy as np import tensorflow as tf def pde_loss(res): # that presents u = u(x, t) u = res(x='x', t='t', num=10000) # u't + u * u'x = 3 * u''xx + sin(pi * x) return u.diff('t') + u() * u.diff('x') - 3 * u.diff('x', 'x') - tf.sin(np.pi * res.var['x'])
-
Whereas:
-
res
is the required predefine argument, that will store all information. -
u = res(x='x', t='t', num==10000)
that representsu = u(x, t)
. -
You can also use like that
u = res(x=-1., t='t')
that representsu = u(-1, t)
-
u()
will return the value ofu(x, t)
-
u.diff('x')
returns the first order partial derivative ofu(x, t)
byx
-
u.diff('x', 'x')
returns the second order partial derivative -
res.var['x']
is the input valuex
for the model.
-
- Define a
Network
pinnics
provides aNetwork
class to help people solvePDE
problems by easy way.
Example:
from pinnics import NetWork
# define network to solve pde problem.
net = NetWork(variables=[x, t],
losses = [pde_loss],
layers=[2, 20, 20, 20, 1])
net.solve(epochs=10000, show_every=1000)
-
Whereas:
-
variables
,losses
,layers
are required to create a new network.-
variables
is thelist
which contains allvariables
(VarSpec
object) of model. -
losses
is thelist
which contains allequations
(function defined in previous part). -
layers
is thelist
that represents network's architecture.
-
-
Non-required arguments:
-
activation_func
: the activation function after each layer (expect result layer),default
bytf.keras.activations.tanh
-
optimizer
: the optimizer of model,default
bytf.keras.optimizers.Adam()
-
initializer_func
: the initializer for model's parameters,default
bytf.keras.initializer.glorut_normal
-
-
net.solve(10000)
will training and approximate the result.
-
After obtaining the model, you can get predict by using call() function.
x = np.linspace (-1, 1, 200).reshape(-1, 1)
t = np.linspace (0, 1, 200).reshape(-1, 1)
input = np.concatentate([x, t], axis=1)
y_pred = net(input)
A completely example
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file pinn_ics-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: pinn_ics-1.0.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0f9e9a2580c1e58b21162dc5df67cb8db63e13eeffb9cc07dcac61187ea8e56 |
|
MD5 | 42aa1e9744a1d278e5973c7fcb4d8b24 |
|
BLAKE2b-256 | cc86e4a34abad422b07a3bd171851c1084e5a67d577cce2a93f462f4832ab8ff |