pinn-ics
PINN framework
Installation
pip install pinn-ics
Latest version: 1.0.2
- New Features: `RAR algorithm` - generate data where the loss is higher
Syntax
Var Configuration
-
pinnicsrequires configurations for all variables.-
VarSpeccan import directly frompinnics -
VarSpecobject containsindentify characterandlimitof this variable.
-
-
Example:
-
Your solution depends on 2 domains:
dimensionandtime. -
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
-
pinnicssupports solving partial differential equation with the simple syntax.- Define a
functionwith 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:
-
resis 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 valuexfor the model.
-
- Define a
Network
pinnicsprovides aNetworkclass to help people solvePDEproblems 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,layersare required to create a new network.-
variablesis thelistwhich contains allvariables(VarSpecobject) of model. -
lossesis thelistwhich contains allequations(function defined in previous part). -
layersis thelistthat represents network's architecture.
-
-
Non-required arguments:
-
activation_func: the activation function after each layer (expect result layer),defaultbytf.keras.activations.tanh -
optimizer: the optimizer of model,defaultbytf.keras.optimizers.Adam() -
initializer_func: the initializer for model's parameters,defaultbytf.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
from pinnics import NetWork, VarSpec
import matplotlib.pyplot as plt
import numpy as np
t = VarSpec('t', limit=(0, 5))
def pde(res):
u = res(t='t', num=1000)
return u.diff('t', 't') + 3*u.diff('t') + 2*u()
def bound(res):
u_pos = res(t=0, num=50)
return u_pos() - 3
def bound_t(res):
u_zero = res(t=0, num=50)
return u_zero.diff('t') - 1
net = NetWork(variables=[t], losses=[pde, bound, bound_t], layers=[1, 20, 20, 1])
net.solve(epochs=1000, show_every=100)
plt.plot(net.history_loss)
plt.show()
x = np.linspace(0, 5, 300).reshape(-1, 1)
y = 7 * np.exp(-x) - 4 * np.exp(-2 * x)
y_pred = net(x)
plt.plot(x, y, label='truth', linewidth=3)
plt.plot(x, y_pred, label='predict', linewidth=3, linestyle='dashed')
plt.plot(x, y-y_pred, label='different')
plt.show()
Metadata
Release files for pinn-ics 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pinn-ics-1.0.2.tar.gz | 6.8 kB | Without provenance | Details for pinn-ics-1.0.2.tar.gz |
Release files / pinn-ics-1.0.2.tar.gz
| Download URL | pinn-ics-1.0.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
714a8ebf0a325c59b68b582e2d0282794abcea66d430d9b5d3781d58bd17392a
|
|
BLAKE2b-256 checksum How to use checksums |
debe35404488bfbc8d5acb2f309ef53a740478db064adbf388cc8b8c080813bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for pinn-ics 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.