Skip to content

Commit 8443954

Browse files
committed
update documentation and classes initializers
1 parent c3af785 commit 8443954

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

cuqi/pde/_pde.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PDE(ABC):
1717
Callable function which returns a tuple of the needed PDE components (expected components are explained in the subclasses)
1818
1919
observation_map: a function handle
20-
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+
A function that takes the PDE solution as input and the returns the observed solution. e.g. `observation_map=lambda u: u**2`.
2121
2222
grid_sol: np.ndarray
2323
The grid on which solution is defined
@@ -195,7 +195,10 @@ class SteadyStateLinearPDE(LinearPDE):
195195
Parameters
196196
-----------
197197
PDE_form : callable function
198-
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.
198+
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.
199+
200+
observation_map: a function handle
201+
A function that takes the PDE solution and spatial grid as input and the returns the observed solution. e.g. `observation_map=lambda u, grid: u**2`.
199202
200203
kwargs:
201204
See :class:`~cuqi.pde.LinearPDE` for the remaining keyword arguments.
@@ -205,8 +208,8 @@ class SteadyStateLinearPDE(LinearPDE):
205208
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.
206209
"""
207210

208-
def __init__(self, PDE_form, **kwargs):
209-
super().__init__(PDE_form, **kwargs)
211+
def __init__(self, PDE_form, observation_map=None, **kwargs):
212+
super().__init__(PDE_form, observation_map=observation_map, **kwargs)
210213

211214
def assemble(self, *args, **kwargs):
212215
"""Assembles differential operator and rhs according to PDE_form"""
@@ -231,8 +234,8 @@ def observe(self, solution):
231234
solution_obs = interp1d(self.grid_sol, solution, kind='quadratic')(self.grid_obs)
232235

233236
if self.observation_map is not None:
234-
solution_obs = self.observation_map(solution_obs)
235-
237+
solution_obs = self.observation_map(solution_obs, self.grid_obs)
238+
236239
return solution_obs
237240

238241
class TimeDependentLinearPDE(LinearPDE):
@@ -252,6 +255,8 @@ class TimeDependentLinearPDE(LinearPDE):
252255
method: str
253256
Time stepping method. Currently two options are available `forward_euler` and `backward_euler`.
254257
258+
observation_map: a function handle
259+
A function that takes the PDE solution, the spatial grid, and the time steps as input and the returns the observed solution. e.g. `observation_map=lambda u, grid, times: u**2`.
255260
kwargs:
256261
See :class:`~cuqi.pde.LinearPDE` for the remaining keyword arguments
257262
@@ -261,8 +266,8 @@ class TimeDependentLinearPDE(LinearPDE):
261266
"""
262267

263268
def __init__(self, PDE_form, time_steps, time_obs='final',
264-
method='forward_euler', **kwargs):
265-
super().__init__(PDE_form, **kwargs)
269+
method='forward_euler', observation_map=None, **kwargs):
270+
super().__init__(PDE_form, observation_map=observation_map, **kwargs)
266271

267272
self.time_steps = time_steps
268273
self.method = method

0 commit comments

Comments
 (0)