Last updated: 2023-03-16.
tf_quant_finance.math.pde.steppers.parabolic_equation_stepper.parabolic_equation_step#
Performs one step of the one dimensional parabolic PDE solver.
tf_quant_finance.math.pde.steppers.parabolic_equation_stepper.parabolic_equation_step(
time, next_time, coord_grid, value_grid, boundary_conditions,
second_order_coeff_fn, first_order_coeff_fn, zeroth_order_coeff_fn,
inner_second_order_coeff_fn, inner_first_order_coeff_fn, time_marching_scheme,
dtype=None, name=None
)
Typically one doesn’t need to call this function directly, unless they have
a custom time marching scheme. A simple stepper function for one-dimensional
PDEs can be found in crank_nicolson.py.
For a given solution (given by the value_grid) of a parabolic PDE at a given
time on a given coord_grid computes an approximate solution at the
next_time on the same coordinate grid. The parabolic differential equation
is of the form:
dV/dt + a * d2(A * V)/dx2 + b * d(B * V)/dx + c * V = 0
Here a, A, b, B, and c are known coefficients which may depend on
x and t; V = V(t, x) is the solution to be found.
Args:#
time: Real scalarTensor. The time before the step.next_time: Real scalarTensor. The time after the step.coord_grid: List of size 1 that contains a rank 1 realTensorof has shape[d]orB + [d]wheredis the size of the grid andBis a batch shape. Represents the coordinates of the grid points.value_grid: RealTensorcontaining the function values at timetimewhich have to be evolved to timenext_time. The shape of theTensormust broadcast withB + [d].Bis the batch dimensions (one or more), which allow multiple functions (with potentially different boundary/final conditions and PDE coefficients) to be evolved simultaneously.boundary_conditions: The boundary conditions. Only rectangular boundary conditions are supported. A list of tuples of size 1. The list element is a tuple that consists of two callables orNones representing the boundary conditions at the minimum and maximum values of the spatial variable indexed by the position in the list.boundary_conditions[0][0]describes the boundary atx_min, andboundary_conditions[0][1]the boundary atx_max.Nonevalues mean that the second order term on the boundary is assumed to be zero, i.e., ‘dV/dt + b * d(B * V)/dx + c * V = 0’. This condition is appropriate for PDEs where the second order term disappears on the boundary. For notNonevalues, the boundary conditions are accepted in the formalpha(t) V + beta(t) V_n = gamma(t), whereV_nis the derivative with respect to the exterior normal to the boundary. Each callable receives the current timetand thecoord_gridat the current time, and should return a tuple ofalpha,beta, andgamma. Each can be a number, a zero-rankTensoror aTensorof the batch shape. For example, for a grid of shape(b, n), wherebis the batch size,boundary_conditions[0][0]should return a tuple of either numbers, zero-rank tensors or tensors of shape(b, n).alphaandbetacan also beNonein case of Neumann and Dirichlet conditions, respectively.second_order_coeff_fn: Callable returning the second order coefficienta(t, r)evaluated at given timet. The callable accepts the following arguments:t: The time at which the coefficient should be evaluated.locations_grid: aTensorrepresenting a grid of locationsrat which the coefficient should be evaluated. Returns an objectAsuch thatA[0][0]is defined and equalsa(r, t).A[0][0]should be a Number, aTensorbroadcastable to the shape of the grid represented bylocations_grid, orNoneif corresponding term is absent in the equation. Also, the callable itself may be None, meaning there are no second-order derivatives in the equation.first_order_coeff_fn: Callable returning the first order coefficientb(t, r)evaluated at given timet. The callable accepts the following arguments:t: The time at which the coefficient should be evaluated.locations_grid: aTensorrepresenting a grid of locationsrat which the coefficient should be evaluated. Returns a list or an 1DTensor,0-th element of which representsb(t, r). This element should be a Number, aTensorbroadcastable to the shape of the grid represented bylocations_grid, or None if corresponding term is absent in the equation. The callable itself may be None, meaning there are no first-order derivatives in the equation.zeroth_order_coeff_fn: Callable returning the zeroth order coefficientc(t, r)evaluated at given timet. The callable accepts the following arguments:t: The time at which the coefficient should be evaluated.locations_grid: aTensorrepresenting a grid of locationsrat which the coefficient should be evaluated. Should return a Number or aTensorbroadcastable to the shape of the grid represented bylocations_grid. May also return None or be None if the shift term is absent in the equation.inner_second_order_coeff_fn: Callable returning the coefficients under the second derivatives (i.e.A(t, x)above) at given timet. The requirements are the same as forsecond_order_coeff_fn.inner_first_order_coeff_fn: Callable returning the coefficients under the first derivatives (i.e.B(t, x)above) at given timet. The requirements are the same as forfirst_order_coeff_fn.time_marching_scheme: A callable which represents the time marching scheme for solving the PDE equation. Ifu(t)is space-discretized vector of the solution of the PDE, this callable approximately solves the equationdu/dt = A(t) u(t)foru(t1)givenu(t2). HereAis a tridiagonal matrix. The callable consumes the following arguments by keyword:inner_value_grid: Grid of solution values at the current time of the same
dtypeasvalue_gridand shape ofvalue_grid[..., 1:-1].t1: Time before the step.
t2: Time after the step.
equation_params_fn: A callable that takes a scalar
Tensorargument representing time, and constructs the tridiagonal matrixA(a tuple of threeTensors, main, upper, and lower diagonals) and the inhomogeneous termb. All of theTensors are of the samedtypeasvalues_inner_value_gridand of the shape broadcastable with the shape ofinner_value_grid. The callable should return aTensorof the same shape anddtypeavalue_gridand represents an approximate solution of the PDE after one iteraton.
dtype: The dtype to use.name: The name to give to the ops. Default value: None which meansparabolic_equation_stepis used.
Returns:#
A sequence of two Tensors. The first one is a Tensor of the same
dtype and shape as coord_grid and represents a new coordinate grid
after one iteration. The second Tensor is of the same shape and dtype
asvalue_grid and represents an approximate solution of the equation after
one iteration.