Skip to content

Commit

Permalink
Merge pull request #18 from aai-institute/feature/improve-notebooks
Browse files Browse the repository at this point in the history
Feature/improve notebooks
  • Loading branch information
samuelburbulla authored Dec 14, 2023
2 parents 08117d3 + 63d784f commit 93d0899
Show file tree
Hide file tree
Showing 9 changed files with 637 additions and 539 deletions.
4 changes: 2 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ nav:
- Learning Operators:
- Introduction: operators/index.md
- Examples:
- Intro: examples/intro.ipynb
- Sine: examples/sine.ipynb
- Basics: examples/basics.ipynb
- Physics-informed: examples/physicsinformed.ipynb
- Self-supervised: examples/selfsupervised.ipynb
- Code:
- API: api/continuity/
- Changelog: CHANGELOG.md
318 changes: 318 additions & 0 deletions notebooks/basics.ipynb

Large diffs are not rendered by default.

297 changes: 0 additions & 297 deletions notebooks/intro.ipynb

This file was deleted.

24 changes: 17 additions & 7 deletions notebooks/physicsinformed.ipynb

Large diffs are not rendered by default.

279 changes: 279 additions & 0 deletions notebooks/selfsupervised.ipynb

Large diffs are not rendered by default.

224 changes: 0 additions & 224 deletions notebooks/sine.ipynb

This file was deleted.

14 changes: 13 additions & 1 deletion src/continuity/data/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ class Sine(SelfSupervisedDataSet):
sine waves is evenly distributed between $\pi$ for the first observation
and $2\pi$ for the last observation, respectively.
The `Sine` dataset generates $N$ sine waves
$$
f(x) = \sin(w_k x), \quad w_k = 1 + \frac{k}{N-1}, \quad k = 0, \dots, N-1.
$$
As a `SelfSupervisedDataset` it exports batches of samples for self-supervised
training, namely
$$
\left(\mathbf{x}, f(\mathbf{x}), x_j, f(x_j)\right), \quad \text{for } j = 1, \dots, M,
$$
where $\mathbf{x} = (x_i)_{i=1 \dots M}$ are the $M$ equidistantly
distributed sensor positions.
- coordinate_dim: 1
- num_channels: 1
Expand Down Expand Up @@ -172,7 +184,7 @@ def generate_observation(self, i: float):
if self.size == 1:
w = 1
else:
w = i / self.size + 1
w = 1 + i / (self.size - 1)

u = np.sin(w * np.pi * x)

Expand Down
14 changes: 7 additions & 7 deletions src/continuity/operators/neuraloperator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ class ContinuousConvolution(Operator):
where $(x_i, u_i)$ are the $N$ sensors of the mapped observation.
Args:
kernel: Kernel function $\kappa$ or network (if $d$ is the coordinate dimension, $\kappa: \R^d \times \R^d \to \R$)
coordinate_dim: Dimension of coordinate space
num_channels: Number of channels
kernel: Kernel function $\kappa$ or network (if $d$ is the coordinate dimension, $\kappa: \R^d \times \R^d \to \R$)
"""

def __init__(
self,
coordinate_dim: int,
num_channels: int,
kernel: Union[Callable[[Tensor], Tensor], torch.nn.Module],
coordinate_dim: int = 1,
num_channels: int = 1,
):
super().__init__()

self.kernel = kernel
self.coordinate_dim = coordinate_dim
self.num_channels = num_channels
self.kernel = kernel

def forward(self, x: Tensor, u: Tensor, y: Tensor) -> Tensor:
"""Forward pass through the operator.
Expand Down Expand Up @@ -123,26 +123,26 @@ def __init__(
self.num_channels = num_channels

self.lifting = ContinuousConvolution(
NeuralNetworkKernel(kernel_width, kernel_depth),
coordinate_dim,
num_channels,
NeuralNetworkKernel(kernel_width, kernel_depth),
)

self.hidden_layers = torch.nn.ModuleList(
[
ContinuousConvolution(
NeuralNetworkKernel(kernel_width, kernel_depth),
coordinate_dim,
num_channels,
NeuralNetworkKernel(kernel_width, kernel_depth),
)
for _ in range(depth)
]
)

self.projection = ContinuousConvolution(
NeuralNetworkKernel(kernel_width, kernel_depth),
coordinate_dim,
num_channels,
NeuralNetworkKernel(kernel_width, kernel_depth),
)

def forward(self, x: Tensor, u: Tensor, y: Tensor) -> Tensor:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_convolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ def dirac(x, y):

# Operator
operator = ContinuousConvolution(
kernel=dirac,
coordinate_dim=dataset.coordinate_dim,
num_channels=dataset.num_channels,
kernel=dirac,
)

# Create tensors
Expand Down

0 comments on commit 93d0899

Please sign in to comment.