Class documentation

class numdf.Ptp(Omega_X={'x1': (-1, 1), 'x2': (-1, 1)}, Omega_Y={'Y': (0, 1)}, n_elements=10)

Ptp class - physical to probability.

Given a user provided “function” over a physical “domain”

Y(X) where X in Ω_X

this class uses the fit method to return the “CDF”, “QDF” & “PDF”

F(y), Q(p), f(y)

over their corresponding probability space Ω_Y. The method uses a finite element discretisation consisting of n elements “bins”.

Parameters:
  • Omega_X (dictionary) – Physical domain of the function Y(X).

  • Omega_Y (dictionary) – Domain of the function F_Y(y).

  • n_elements (int) – Number of finite elements.

Returns:

density – A density object containing the CDF, QDF and PDF of Y(X).

Return type:

Density object

Examples

Specify the domain size(s) & number of finite elements/bins:

>>> ptp = Ptp(Omega_X={'x1': (0, 1)}, Omega_Y={'Y': (0, 1)}, n_elements=5)
>>> x1 = ptp.x_coords()

Compute the density of a function on this domain:

>>> density = ptp.fit(Y=x1, Range_Y={'Y_min':0, 'Y_max':1}, quadrature_degree=100)
>>> density.plot('CDF')
fit(Y, Range_Y={'Y_max': 1, 'Y_min': 0}, quadrature_degree=100)

Return the Density object correspoding to Y(X).

Parameters:
  • Y (UFL expression/callable) – A UFL expression Y(X) terms of x_coords() or a callable that returns Y(X_i) at the points {X_i}.

  • Range_Y (dictionary) – Range of the function Y(X).

  • quadrature_degree (int) – Quadrature degree used to evaluate the projection of I(y,X).

Returns:

density – A Density object containing the CDF, QDF & PDF of Y(X).

Return type:

class ‘Density’

indicator(Y)

Apply the indicator function I(y,X) to the random function Y(X).

Parameters:

Y (UFL expression) – A UFL expression Y(X) terms of x_coords() with range [0,1].

Returns:

I(y,X) – A conditional operator implementing the indicator function.

Return type:

UFL expression

map(Y)

Map Y(x) so that its range becomes the unit interval [0,1].

Parameters:

Y (UFL expression) – A UFL expression Y(X) terms of x_coords().

Returns:

Y_mapped – A UFL expression in terms of x_coords() with range [0,1].

Return type:

UFL expression

slope_limiter(F, Range_Y)

Apply a slope limiter to ensure a non-decreasing cdf F(y).

Parameters:

F (firedrake Function) – The cdf F(y) of the random function Y(X).

Returns:

F – The slope limited cdf F(y) of the random function Y(X).

Return type:

firedrake Function

x_coords()

Return the co-ordinates of X=(x1,x2).

xy_coords()

Return the X & Y co-ordinates of the extended mesh.

y_coord()

Return the y coordinate on the interval mesh.

class numdf.Density(ptp, y, cdf, qdf, pdf)

Density class containing the cdf, qdf and pdf of a function Y(X).

Instances of this class are returned by the Ptp class when the fit method is called on a function Y(X) to return

F(y), Q(p), f(φ)

the “CDF”, “QDF” & “PDF” over their corresponding probability space Ω_Y. This class allows these functions to be easily composed and plotted.

Examples

Compose the QDF and CDF:

>>> density.compose(density.qdf, density.cdf, quadrature_degree=100)

Plot the CDF and PDF:

>>> density.plot('CDF')
>>> density.plot('PDF')
__call__(g)

Given a test function g(y) evaluate

int g(y) dF(y)

in terms of its

int g(y) dF(y) := <g,f_0> + <g,f_1>

where f_0 & f_1 are the Riesz representors of f[v].

Parameters:

g (Firedrake function or UFL expression) – A valid test function

Returns:

integral – The integral int g(y) dF(y)

Return type:

float

compose(f, g, quadrature_degree)

Return the projection of the function composition f o g(y) = f(g(y)) into the space of test functions.

Parameters:
  • f (firedrake Function) – Input functions to compose.

  • g (firedrake Function) – Input functions to compose.

Returns:

f(g(y)) – Composition projected into the space DG1

Return type:

firedrake Function

evaluate(y)

Return the CDF, QDF and PDF at the point(s) y.

Parameters:

y (array-like) – A grid to evaluate on.

Returns:

cdf_at_y,qdf_at_y,pdf_at_y – cdf,qdf,pdf evaluated on y.

Return type:

array-like

plot(function='CDF')

Visualise the CDF, QDF and PDF using inbuilt plotting routines.

Parameters:

function (string) – The function to plot e.g. ‘CDF, ‘PDF’, ‘QDF’