Last updated: 2023-03-16.
tf_quant_finance.math.piecewise.PiecewiseConstantFunc#
Creates a piecewise constant function.
tf_quant_finance.math.piecewise.PiecewiseConstantFunc(
jump_locations, values, dtype=None, name=None
)
Args:#
jump_locations: A realTensorof shapebatch_shape + [num_jump_points]. The locations where the function changes its values. Note that the values are expected to be ordered along the last dimension. Repeated values are allowed but it is up to the user to ensure that the correspondingvaluesare also repeated.values: ATensorof the samedtypeasjump_locationsand shapebatch_shape + [num_jump_points + 1] + event_shape. Definesvalues[batch_rank * slice(None), i]on intervals(jump_locations[..., i - 1], jump_locations[..., i]). Hereevent_shapeallows for array-valued piecewise constant functions andbatch_rank = len(batch_shape).dtype: Optional dtype forjump_locationsandvalues. Default value:Nonewhich maps to the default dtype inferred fromjump_locations.name: Pythonstrname prefixed to ops created by this class. Default value:Nonewhich is mapped to the default namePiecewiseConstantFunc.
Raises:#
ValueError: Ifjump_locationsandvalueshave different batch shapes or, in case of static shapes, if the event shape ofvaluesis different fromnum_jump_points + 1.
Methods#
__call__
__call__(
x, left_continuous=True, name=None
)
Computes value of the piecewise constant function.
Returns a value of the piecewise function with jump locations and values given by the initializer.
Args:#
x: A realTensorof shapebatch_shape + [num_points]. Points at which the function has to be evaluated.left_continuous: Pythonbool. Whether the function is left- or right- continuous, i.e., at thejump_locations[..., i]left-continuity means that the function has the same valuevalues[batch_rank * slice(None), i], whereas for right-continuity, the value isvalues[batch_rank * slice(None), i + 1]. Default value:Truewhich means that the function is left-continuous.name: Pythonstrname prefixed to ops created by this method. Default value:Nonewhich is mapped to the default nameself.name() + _call.
Returns:#
A Tensor of the same dtype as x and shape
batch_shape + [num_points] + event_shape containing values of the
piecewise constant function.
dtype
dtype()
The underlying data type.
integrate
integrate(
x1, x2, name=None
)
Integrates the piecewise constant function between end points.
Returns a value of the integral on the interval [x1, x2] of a piecewise
constant function with jump locations and values given by the initializer.
Args:#
x1: A realTensorof shapebatch_shape + [num_points]. Left end points at which the function has to be integrated.x2: ATensorof the same shape anddtypeasx1. Right end points at which the function has to be integrated.name: Pythonstrname prefixed to ops created by this method. Default value:Nonewhich is mapped to the default nameself.name() +_integrate``.
Returns:#
A Tensor of the same dtype as x and shape
batch_shape + [num_points] + event_shape containing values of the
integral of the piecewise constant function between [x1, x2].
jump_locations
jump_locations()
The jump locations of the piecewise constant function.
name
name()
The name to give to the ops created by this class.
values
values()
The value of the piecewise constant function between jump locations.