You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This module contains observation map examples for PDE problems. The map can
5
+
be passed to the `PDE` object initializer via the `observation_map` argument.
6
+
7
+
For example on how to use set observation maps in time dependent PDEs, see
8
+
`demos/howtos/TimeDependentLinearPDE.py`.
9
+
"""
10
+
11
+
# 1. Steady State Observation Maps
12
+
# --------------------------------
13
+
14
+
# 2. Time-Dependent Observation Maps
15
+
# -----------------------------------
16
+
defFD_spatial_gradient(sol, grid, times):
17
+
"""Time dependent observation map that computes the finite difference (FD) spatial gradient of a solution given at grid points (grid) and times (times). This map is supported for 1D spatial domains only.
18
+
19
+
Parameters
20
+
----------
21
+
sol : np.ndarray
22
+
The solution array of shape (number of grid points, number of time steps).
23
+
24
+
grid : np.ndarray
25
+
The spatial grid points of shape (number of grid points,).
26
+
27
+
times : np.ndarray
28
+
The discretized time steps of shape (number of time steps,)."""
29
+
30
+
iflen(grid.shape) !=1:
31
+
raiseValueError("FD_spatial_gradient only supports 1D spatial domains.")
Copy file name to clipboardExpand all lines: cuqi/pde/_pde.py
+52-21Lines changed: 52 additions & 21 deletions
Original file line number
Diff line number
Diff line change
@@ -15,14 +15,15 @@ class PDE(ABC):
15
15
PDE_form : callable function
16
16
Callable function which returns a tuple of the needed PDE components (expected components are explained in the subclasses)
17
17
18
-
observation_map: a function handle
19
-
A function that takes the PDE solution as input and the returns the observed solution. e.g. `observation_map=lambda u: u**2` or `observation_map=lambda u: u[0]`
20
-
21
18
grid_sol: np.ndarray
22
19
The grid on which solution is defined
23
20
24
21
grid_obs: np.ndarray
25
-
The grid on which the observed solution should be interpolated (currently only supported for 1D problems).
22
+
The grid on which the observed solution should be interpolated (currently only supported for 1D problems).
23
+
24
+
observation_map: a function handle
25
+
A function that takes the PDE solution, interpolated on `grid_obs`, as input and returns the observed solution. e.g., `observation_map=lambda u, grid_obs: u**2`.
"""Interpolate solution on observed space domain."""
194
+
raiseNotImplementedError("interpolate_on_observed_domain method is not implemented for LinearPDE base class.")
190
195
191
196
classSteadyStateLinearPDE(LinearPDE):
192
197
"""Linear steady state PDE.
193
198
194
199
Parameters
195
200
-----------
196
201
PDE_form : callable function
197
-
Callable function with signature `PDE_form(parameter1, parameter2, ...)` where `parameter1`, `parameter2`, etc. are the Bayesian unknown parameters (the user can choose any names for these parameters, e.g. `a`, `b`, etc.). The function returns a tuple with the discretized differential operator A and right-hand-side b. The types of A and b are determined by what the method :meth:`linalg_solve` accepts as first and second parameters, respectively.
202
+
Callable function with signature `PDE_form(parameter1, parameter2, ...)` where `parameter1`, `parameter2`, etc. are the Bayesian unknown parameters (the user can choose any names for these parameters, e.g. `a`, `b`, etc.). The function returns a tuple with the discretized differential operator A and right-hand-side b. The types of A and b are determined by what the method :meth:`linalg_solve` accepts as first and second parameters, respectively.
203
+
204
+
observation_map: a function handle
205
+
A function that takes the PDE solution, interpolated on `grid_obs`, as input and returns the observed solution. e.g. `observation_map=lambda u, grid_obs: u**2`.
198
206
199
207
kwargs:
200
208
See :class:`~cuqi.pde.LinearPDE` for the remaining keyword arguments.
@@ -204,8 +212,8 @@ class SteadyStateLinearPDE(LinearPDE):
204
212
See demo demos/demo24_fwd_poisson.py for an illustration on how to use SteadyStateLinearPDE with varying solver choices. And demos demos/demo25_fwd_poisson_2D.py and demos/demo26_fwd_poisson_mixedBC.py for examples with mixed (Dirichlet and Neumann) boundary conditions problems. demos/demo25_fwd_poisson_2D.py also illustrates how to observe on a specific boundary, for example.
@@ -251,16 +267,20 @@ class TimeDependentLinearPDE(LinearPDE):
251
267
method: str
252
268
Time stepping method. Currently two options are available `forward_euler` and `backward_euler`.
253
269
270
+
observation_map: a function handle
271
+
A function that takes the PDE solution, interpolated on `grid_obs` and `time_obs`, as input and returns the observed solution. e.g. `observation_map=lambda u, grid_obs, time_obs: u**2`.
272
+
254
273
kwargs:
255
274
See :class:`~cuqi.pde.LinearPDE` for the remaining keyword arguments
256
275
257
276
Example
258
277
-----------
259
-
See demos/demo34_TimeDependentLinearPDE.py for 1D heat and 1D wave equations.
278
+
See demos/howtos/TimeDependentLinearPDE.py for 1D heat and 1D wave equations examples. It demonstrates setting up `TimeDependentLinearPDE` objects, including the choice of time stepping methods, observation domain, and observation map.
0 commit comments