pal.couplings module

Stochastic variable coupling and dependency management.

Provides coupling mechanisms for stochastic variables, allowing them to maintain dependency relationships during reordering and copula applications. Key classes include CouplingGroup for managing variable groups and ProteusStochasticVariable as the base class for all stochastic types.

class pal.couplings.CouplingGroup(variable)[source]

Bases: object

A class to represent a group of variables that are coupled together.

__init__(variable)[source]

Initialize coupling group with a single variable.

Parameters:

variable (ProteusStochasticVariable) – The initial variable to add to the group.

add(obj)[source]

Add a variable to the coupling group.

Return type:

None

discard(obj)[source]

Remove a variable from the coupling group if it exists.

Return type:

None

merge(other)[source]

Merge another coupling group into this one.

Parameters:

other (CouplingGroup) – The other coupling group to merge.

Return type:

None

class pal.couplings.ProteusStochasticVariable[source]

Bases: NDArrayOperatorsMixin, ABC

A class to represent a stochastic variable in a simulation.

n_sims: int | None = None
values: ndarray[tuple[Any, ...], dtype[number[Any]]]
__init__()[source]

Initialize stochastic variable with new coupling group.

upsample(n_sims)[source]

Upsample the variable to match the specified number of simulations.

Parameters:

n_sims (int) – The number of simulations to upsample to.

Return type:

Self

Returns:

A new instance of self with the upsampled values.

astype(dtype)[source]

Convert the underlying values to a specified dtype.

Parameters:

dtype (dtype[Any] | type[Any]) – The data type to convert to.

Return type:

ndarray[tuple[Any, ...], dtype[Any]]

Returns:

A new numpy array with the specified dtype.

any()[source]

Check if any value in the variable is True (non-zero).

Return type:

bool

Returns:

True if any value is non-zero, False otherwise.

all()[source]

Check if all values in the variable are True (non-zero).

Return type:

bool

Returns:

True if all values are non-zero, False otherwise.