Skip to content

Commit

Permalink
doc: upd with alabaster theme
Browse files Browse the repository at this point in the history
  • Loading branch information
pkarnakov committed Jan 9, 2024
1 parent eaafdf5 commit 588cc2c
Show file tree
Hide file tree
Showing 53 changed files with 4,183 additions and 210 deletions.
4 changes: 4 additions & 0 deletions doc/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 838cceab9bf6970cab9bdd64855333e1
tags: 645f666f9bcd5a90fca523b33c5a78b7
Binary file not shown.
4 changes: 2 additions & 2 deletions doc/_downloads/1d585bf137ffd9906e08a8ecc825a674/plot_1d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# 1D Poisson\n"
"\n# 1D Poisson\n\nThis example solves the Poisson equation in 1D\n\n\\begin{align}\\frac{\\partial^2 u}{\\partial x^2} = f\\end{align}\n\nwhere $f=\\frac{\\partial^2 u_\\mathrm{ref}}{\\partial x^2}$ and\n$u_\\mathrm{ref}$ is a reference solution.\n"
]
},
{
Expand Down Expand Up @@ -46,7 +46,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions doc/_downloads/24eaf8dd253be2821d2f6eb64c3d9de4/fields.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# field\n"
"\n# Field\n"
]
},
{
Expand Down Expand Up @@ -46,7 +46,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
10 changes: 9 additions & 1 deletion doc/_downloads/42f8fd27774caacd783cf240e9bb5909/plot_1d.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/usr/bin/env python3
"""
r"""
1D Poisson
==========
This example solves the Poisson equation in 1D
.. math::
\frac{\partial^2 u}{\partial x^2} = f
where :math:`f=\frac{\partial^2 u_\mathrm{ref}}{\partial x^2}` and
:math:`u_\mathrm{ref}` is a reference solution.
"""

import odil
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/_downloads/a059939c07979526d721d26d4ede54b1/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
field
Field
=====
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env python3
'''
Harmonic oscillator
===================
'''


import numpy as np
import torch
import torch.nn as nn
import matplotlib.pyplot as plt
import math

def oscillator(d, w0, x):
w = math.sqrt(w0**2 - d**2)
phi = math.atan2(-d, w)
y = torch.exp(-d * x) * torch.cos(phi + w * x) / math.cos(phi)
return y


torch.manual_seed(123)
torch.set_default_dtype(torch.float32)
d, w0 = 2.0, 20.0
x = torch.linspace(0, 1, 500)[:, None]
y = oscillator(d, w0, x)
x_data = x[0:20:10]
y_data = y[0:20:10]
x_physics = torch.linspace(0, 1, 25)[:, None].requires_grad_(True)
model = nn.Sequential(nn.Linear(1, 16), nn.Tanh(), nn.Linear(16, 16), nn.Tanh(), nn.Linear(16, 1))
optimizer = torch.optim.Adam(model.parameters(), lr=1e-2)
ones = torch.ones_like(x_physics)
for i in range(5000):
optimizer.zero_grad()
yhp = model(x_physics)
dx, = torch.autograd.grad(yhp, x_physics, ones, create_graph=True)
dx2, = torch.autograd.grad(dx, x_physics, ones, create_graph=True)
physics = dx2 + 2 * d * dx + w0 * w0 * yhp
loss = torch.mean(
(model(x_data) - y_data)**2) + 1e-4 * torch.mean(physics**2)
loss.backward()
optimizer.step()
plt.plot(x, y)
plt.plot(x, model(x).detach(), '-')
plt.show()
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%pip install -q git+https://github.com/cselab/odil"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Harmonic oscillator\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\nimport torch\nimport torch.nn as nn\nimport matplotlib.pyplot as plt\nimport math\n\ndef oscillator(d, w0, x):\n w = math.sqrt(w0**2 - d**2)\n phi = math.atan2(-d, w)\n y = torch.exp(-d * x) * torch.cos(phi + w * x) / math.cos(phi)\n return y\n\n\ntorch.manual_seed(123)\ntorch.set_default_dtype(torch.float32)\nd, w0 = 2.0, 20.0\nx = torch.linspace(0, 1, 500)[:, None]\ny = oscillator(d, w0, x)\nx_data = x[0:20:10]\ny_data = y[0:20:10]\nx_physics = torch.linspace(0, 1, 25)[:, None].requires_grad_(True)\nmodel = nn.Sequential(nn.Linear(1, 16), nn.Tanh(), nn.Linear(16, 16), nn.Tanh(), nn.Linear(16, 1))\noptimizer = torch.optim.Adam(model.parameters(), lr=1e-2)\nones = torch.ones_like(x_physics)\nfor i in range(5000):\n optimizer.zero_grad()\n yhp = model(x_physics)\n dx, = torch.autograd.grad(yhp, x_physics, ones, create_graph=True)\n dx2, = torch.autograd.grad(dx, x_physics, ones, create_graph=True)\n physics = dx2 + 2 * d * dx + w0 * w0 * yhp\n loss = torch.mean(\n (model(x_data) - y_data)**2) + 1e-4 * torch.mean(physics**2)\n loss.backward()\n optimizer.step()\nplt.plot(x, y)\nplt.plot(x, model(x).detach(), '-')\nplt.show()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
17 changes: 17 additions & 0 deletions doc/_images/math/0f716ccfb45e4bb9bd5a80d0c9cc97871344b62a.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions doc/_images/math/0fa66331941f83e8be152ad2fcb91c9f1057715d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 588cc2c

Please sign in to comment.