copul.wrapper package
Submodules
copul.wrapper.cd1_wrapper module
- class copul.wrapper.cd1_wrapper.CD1Wrapper(sympy_func: SymPyFuncWrapper | Expr | float | int)[source]
Bases:
SymPyFuncWrapper- Wrapper for ∂C/∂u (first coordinate). Bivariate boundaries:
CD1(u, 0) = 0
CD1(u, 1) = 1
These boundary rules must hold even after partial substitution of u, i.e., when only v (or u2) remains free.
copul.wrapper.cd2_wrapper module
- class copul.wrapper.cd2_wrapper.CD2Wrapper(sympy_func: SymPyFuncWrapper | Expr | float | int)[source]
Bases:
SymPyFuncWrapper- Wrapper for ∂C/∂v (second coordinate). Bivariate boundaries:
CD2(0, v) = 0
CD2(1, v) = 1
These boundary rules must hold even after partial substitution of v (i.e., when only u / u1 remains free).
copul.wrapper.cdf_wrapper module
- class copul.wrapper.cdf_wrapper.CDFWrapper(sympy_func: SymPyFuncWrapper | Expr | float | int)[source]
Bases:
SymPyFuncWrapperWrapper for copula cumulative distribution functions.
- Boundary handling (dimension-agnostic):
C(…, 0, …) = 0 if any coordinate is 0
C(1, …, 1) = 1 if all coordinates are 1 (for those present)
- Bivariate margins (u,v) or (u1,u2):
C(1, v) = v
C(u, 1) = u
copul.wrapper.cdi_wrapper module
- class copul.wrapper.cdi_wrapper.CDiWrapper(func, i)[source]
Bases:
ConditionalWrapperGeneral wrapper for the conditional distribution when conditioning on the i-th variable. Handles multivariate case (u1, u2, …, un).
Boundary conditions: - If ui = 0, returns 0 - If ui = 1, returns 1 (representing the unconditional distribution of the remaining variables) - If any other variable is 0 or 1, handles according to conditional distribution rules
copul.wrapper.conditional_wrapper module
- class copul.wrapper.conditional_wrapper.ConditionalWrapper(func, condition_index=None)[source]
Bases:
SymPyFuncWrapperBase class for conditional distribution wrappers. Handles multivariate cases with symbols u1, u2, …, un.
copul.wrapper.inv_gen_wrapper module
- class copul.wrapper.inv_gen_wrapper.InvGenWrapper(expr, y_symbol, copula_instance)[source]
Bases:
SymPyFuncWrapper- numpy_func()[source]
Create a vectorized numpy function that can be called with array inputs.
When called without arguments, returns a callable function that can evaluate the expression with numpy arrays. When called with arguments, evaluates the expression directly with those arguments.
- Parameters:
*args (array_like, optional) – If provided, input arrays corresponding to the symbols in the expression.
- Returns:
If args are provided, returns the result of evaluating the expression. If no args are provided, returns a function that can be called later.
- Return type:
callable or numpy.ndarray
Examples
>>> import sympy >>> from copul.wrapper.sympy_wrapper import SymPyFuncWrapper >>> x, y = sympy.symbols('x y') >>> expr = SymPyFuncWrapper(x**2 + y) >>> import numpy as np >>> >>> # Get a function and call it later >>> f = expr.numpy_func() >>> f(np.array([1, 2]), np.array([3, 4])) array([4, 8]) >>> >>> # Or evaluate directly >>> expr.numpy_func(np.array([1, 2]), np.array([3, 4])) array([4, 8])
copul.wrapper.pickands_wrapper module
copul.wrapper.sympy_wrapper module
- class copul.wrapper.sympy_wrapper.SymPyFuncWrapper(sympy_func: SymPyFuncWrapper | Expr | float | int)[source]
Bases:
objectA wrapper class for SymPy expressions that provides additional functionality and a more intuitive interface for working with symbolic mathematics.
This class allows for easier function substitution, differentiation, and arithmetic operations with proper type handling.
- diff(*args, **kwargs) SymPyFuncWrapper[source]
Differentiate the expression.
This method directly uses SymPy’s diff method.
- Returns:
A new SymPyFuncWrapper with the differentiated expression.
- evalf(n: int | None = None) float | Expr | SymPyFuncWrapper[source]
Evaluate the expression numerically.
- Parameters:
n – Optional number of significant digits.
- Returns:
For numeric expressions, returns a float
For expressions with symbols, returns the evalf’d SymPy expression
- Return type:
For backward compatibility
- expand() SymPyFuncWrapper[source]
Expand the expression.
- Returns:
A new SymPyFuncWrapper with the expanded expression.
- factor() SymPyFuncWrapper[source]
Factor the expression.
- Returns:
A new SymPyFuncWrapper with the factored expression.
- property free_symbols: Set[Symbol]
Return the set of free symbols in the expression.
- property func: Expr
Return the underlying SymPy expression.
- has(*args, **kwargs) bool[source]
Check if the expression has a certain property.
This method directly uses SymPy’s has method.
- Returns:
True if the expression has the specified property, False otherwise.
- integrate(*args, **kwargs) SymPyFuncWrapper[source]
Integrate the expression.
This method directly uses SymPy’s integrate method.
- Returns:
A new SymPyFuncWrapper with the integrated expression.
- isclose(other, tolerance: float = 1e-10) bool[source]
Check if this expression is numerically close to another expression or value.
- Parameters:
other – Another SymPyFuncWrapper, SymPy expression, or numeric value.
tolerance – Maximum absolute difference allowed for equality (default: 1e-10).
- Returns:
True if expressions are numerically close, False otherwise.
- numpy() ndarray[source]
Convert the expression to a numpy function.
- Returns:
A numpy function that evaluates the expression with numpy inputs.
- Raises:
ValueError – If the expression cannot be converted to a numpy function.
- numpy_func(*args)[source]
Create a vectorized numpy function that can be called with array inputs.
When called without arguments, returns a callable function that can evaluate the expression with numpy arrays. When called with arguments, evaluates the expression directly with those arguments.
- Parameters:
*args (array_like, optional) – If provided, input arrays corresponding to the symbols in the expression.
- Returns:
If args are provided, returns the result of evaluating the expression. If no args are provided, returns a function that can be called later.
- Return type:
callable or numpy.ndarray
Examples
>>> import sympy >>> from copul.wrapper.sympy_wrapper import SymPyFuncWrapper >>> x, y = sympy.symbols('x y') >>> expr = SymPyFuncWrapper(x**2 + y) >>> import numpy as np >>> >>> # Get a function and call it later >>> f = expr.numpy_func() >>> f(np.array([1, 2]), np.array([3, 4])) array([4, 8]) >>> >>> # Or evaluate directly >>> expr.numpy_func(np.array([1, 2]), np.array([3, 4])) array([4, 8])
- simplify() SymPyFuncWrapper[source]
Simplify the expression.
- Returns:
A new SymPyFuncWrapper with the simplified expression.
- subs(*args, **kwargs) SymPyFuncWrapper[source]
Substitute values in the expression.
This method directly uses SymPy’s subs method.
- Returns:
A new SymPyFuncWrapper with the substitutions applied.