continuous_timeseries.discrete_to_continuous.piecewise_constant_common#
Common functions used across our piecewise constant implementations
Classes:
| Name | Description |
|---|---|
GetIdxsCallable |
Callable that can be used to get the index to return from |
PiecewiseConstantLike |
Piecewise-constant like implementation |
Functions:
| Name | Description |
|---|---|
antidifferentiate_piecewise_constant |
Antidifferentiate a piecewise-constant instance |
differentiate_piecewise_constant |
Differentiate a piecewise-constant instance |
discrete_to_continuous_piecewise_constant |
Convert a discrete timeseries to piecewise constant |
get_values |
Get the values to return for a given set of times of interest |
integrate_piecewise_constant |
Integrate a piecewise-constant instance |
piecewise_constant_y_validator |
Validate the |
GetIdxsCallable #
Bases: Protocol
Callable that can be used to get the index to return from self_y
Methods:
| Name | Description |
|---|---|
__call__ |
Get the index to return from |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
__call__ #
__call__(
times: NP_ARRAY_OF_FLOAT_OR_INT,
self_x: NP_ARRAY_OF_FLOAT_OR_INT,
) -> NDArray[integer]
Get the index to return from self.y
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
NP_ARRAY_OF_FLOAT_OR_INT
|
Times for which to get values |
required |
self_x
|
NP_ARRAY_OF_FLOAT_OR_INT
|
|
required |
Returns:
| Type | Description |
|---|---|
NDArray[integer]
|
Indexes to return from |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
PiecewiseConstantLike #
Bases: Protocol
Piecewise-constant like implementation
Methods:
| Name | Description |
|---|---|
__call__ |
Evaluate the function at specific points |
__init__ |
Initialise |
antidifferentiate |
Antidifferentiate |
differentiate |
Differentiate |
integrate |
Integrate |
Attributes:
| Name | Type | Description |
|---|---|---|
x |
NP_ARRAY_OF_FLOAT_OR_INT
|
Breakpoints between each piecewise constant interval |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | |
x
instance-attribute
#
Breakpoints between each piecewise constant interval
__call__ #
__call__(
x: NP_ARRAY_OF_FLOAT_OR_INT,
allow_extrapolation: bool = False,
) -> NP_ARRAY_OF_FLOAT_OR_INT
Evaluate the function at specific points
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NP_ARRAY_OF_FLOAT_OR_INT
|
Points at which to evaluate the function |
required |
allow_extrapolation
|
bool
|
Should extrapolation be allowed? |
False
|
Returns:
| Type | Description |
|---|---|
NP_ARRAY_OF_FLOAT_OR_INT
|
The function, evaluated at |
Raises:
| Type | Description |
|---|---|
ExtrapolationNotAllowedError
|
The user attempted to extrapolate when it isn't allowed. |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
__init__ #
__init__(
x: NP_ARRAY_OF_FLOAT_OR_INT, y: NP_ARRAY_OF_FLOAT_OR_INT
) -> None
Initialise
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
NP_ARRAY_OF_FLOAT_OR_INT
|
Breakpoints between each piecewise constant interval |
required |
y
|
NP_ARRAY_OF_FLOAT_OR_INT
|
The y-values which help define our spline |
required |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
antidifferentiate #
antidifferentiate(
domain_start: NP_FLOAT_OR_INT,
) -> ContinuousFunctionScipyPPoly
Antidifferentiate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_start
|
NP_FLOAT_OR_INT
|
The start of the domain. This is required to ensure that we start at the right point when evaluating the indefinite integral. |
required |
Returns:
| Type | Description |
|---|---|
ContinuousFunctionScipyPPoly
|
Indefinite integral of the function |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
differentiate #
differentiate() -> ContinuousFunctionScipyPPoly
integrate #
integrate(
integration_constant: NP_FLOAT_OR_INT,
domain_start: NP_FLOAT_OR_INT,
) -> ContinuousFunctionScipyPPoly
Integrate
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
integration_constant
|
NP_FLOAT_OR_INT
|
Integration constant This is required for the integral to be a definite integral. |
required |
domain_start
|
NP_FLOAT_OR_INT
|
The start of the domain. This is required to ensure that we start at the right point when evaluating the definite integral. |
required |
Returns:
| Type | Description |
|---|---|
ContinuousFunctionScipyPPoly
|
Integral of the function |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
antidifferentiate_piecewise_constant #
antidifferentiate_piecewise_constant(
self: PiecewiseConstantLike,
domain_start: NP_FLOAT_OR_INT,
) -> ContinuousFunctionScipyPPoly
Antidifferentiate a piecewise-constant instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
self
|
PiecewiseConstantLike
|
Piecewise-constant instance to antidifferentiate |
required |
domain_start
|
NP_FLOAT_OR_INT
|
Start of the domain of antidifferentiation |
required |
Returns:
| Type | Description |
|---|---|
ContinuousFunctionScipyPPoly
|
Indefinite integral of |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
differentiate_piecewise_constant #
differentiate_piecewise_constant(
self: PiecewiseConstantLike,
) -> ContinuousFunctionScipyPPoly
Differentiate a piecewise-constant instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
self
|
PiecewiseConstantLike
|
Piecewise-constant instance to differentiate |
required |
Returns:
| Type | Description |
|---|---|
ContinuousFunctionScipyPPoly
|
Derivative of |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
discrete_to_continuous_piecewise_constant #
discrete_to_continuous_piecewise_constant(
x: PINT_NUMPY_ARRAY,
y: PINT_NUMPY_ARRAY,
name: str,
piecewise_constant_like: type[PiecewiseConstantLike],
) -> TimeseriesContinuous
Convert a discrete timeseries to piecewise constant
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
PINT_NUMPY_ARRAY
|
The discrete x-values from which to convert |
required |
y
|
PINT_NUMPY_ARRAY
|
The discrete y-values from which to convert |
required |
name
|
str
|
The value to use to set the result's name attribute |
required |
piecewise_constant_like
|
type[PiecewiseConstantLike]
|
Piecewise-constant class to convert to |
required |
Returns:
| Type | Description |
|---|---|
TimeseriesContinuous
|
Continuous version of |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
get_values #
get_values(
times: NP_ARRAY_OF_FLOAT_OR_INT,
self_x: NP_ARRAY_OF_FLOAT_OR_INT,
self_y: NP_ARRAY_OF_FLOAT_OR_INT,
get_idxs: GetIdxsCallable,
allow_extrapolation: bool,
) -> NP_ARRAY_OF_FLOAT_OR_INT
Get the values to return for a given set of times of interest
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
times
|
NP_ARRAY_OF_FLOAT_OR_INT
|
Times for which to get the values |
required |
self_x
|
NP_ARRAY_OF_FLOAT_OR_INT
|
|
required |
self_y
|
NP_ARRAY_OF_FLOAT_OR_INT
|
|
required |
get_idxs
|
GetIdxsCallable
|
Function which defines the continuous piecewise constant's form. Given |
required |
allow_extrapolation
|
bool
|
Whether extrapolation should be allowed while retrieving the values |
required |
Returns:
| Type | Description |
|---|---|
NP_ARRAY_OF_FLOAT_OR_INT
|
Values of the function at |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
integrate_piecewise_constant #
integrate_piecewise_constant(
self: PiecewiseConstantLike,
integration_constant: NP_FLOAT_OR_INT,
domain_start: NP_FLOAT_OR_INT,
) -> ContinuousFunctionScipyPPoly
Integrate a piecewise-constant instance
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
self
|
PiecewiseConstantLike
|
Piecewise-constant instance to integrate |
required |
integration_constant
|
NP_FLOAT_OR_INT
|
Integration constant to use when calculating the integral |
required |
domain_start
|
NP_FLOAT_OR_INT
|
Start of the domain of integration |
required |
Returns:
| Type | Description |
|---|---|
ContinuousFunctionScipyPPoly
|
Integral of |
Source code in src/continuous_timeseries/discrete_to_continuous/piecewise_constant_common.py
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 | |
piecewise_constant_y_validator #
piecewise_constant_y_validator(
self: PiecewiseConstantLike,
attribute: Attribute[Any],
value: NP_ARRAY_OF_FLOAT_OR_INT,
) -> None
Validate the y attribute of piecewise constant implementations
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
self
|
PiecewiseConstantLike
|
Instance of a class that is piecewise-constant like |
required |
attribute
|
Attribute[Any]
|
Attribute being validated |
required |
value
|
NP_ARRAY_OF_FLOAT_OR_INT
|
Value to validate |
required |
Raises:
| Type | Description |
|---|---|
AssertionError
|
Value does not have the same shape as |