.. _extending: Extending the Pipeline: Adding a Copula ======================================= This section shows you how to integrate a new copula into the CopulaFurtif pipeline following the hexagonal architecture. ๐Ÿงฑ Steps to Add a Copula ------------------------ 1. **Create the copula class** - Inherit from `CopulaModel` (and `ModelSelectionMixin`, `SupportsTailDependence` if applicable) - Implement the methods: `get_cdf`, `get_pdf`, `sample`, `kendall_tau`, etc. .. code-block:: python from CopulaFurtif.core.copulas.domain.models.interfaces import CopulaModel class MyCopula(CopulaModel): def __init__(self): super().__init__() self.name = "My Copula" self.type = "mycopula" self.bounds_param = [(0.1, 5.0)] self._parameters = [1.0] def get_cdf(self, u, v, param=None): ... def get_pdf(self, u, v, param=None): ... def sample(self, n, param=None): ... def kendall_tau(self, param=None): ... 2. **Add to the factory** .. code-block:: python from CopulaFurtif.core.copulas.domain.factories.copula_factory import CopulaFactory from CopulaFurtif.core.copulas.domain.models.archimedean.mycopula import MyCopula CopulaFactory.register("mycopula", MyCopula) 3. **Write a unit test** - Test all behaviors: parameters, PDF, CDF, derivatives, etc. - Place the file in `tests/units/test_my_model.py` 4. **(Optional) Add a visualization** If needed, add a function in `copula_viz_adapter.py` ๐Ÿงช Full Example ---------------- A complete integration example (Joe or Gumbel copula) is available in `tests/` and `domain/models/`. ๐Ÿ“Œ Best Practices ----------------- - Use `np.clip` for bounds (to avoid log(0), division by 0) - Add `@property parameters` with a setter validating `bounds_param` - Implement `__str__` if useful for debugging or logs ๐Ÿ“š See also: `copula_factory.py`, `test_factory_and_archimedean.py`, `diagnostics_service.py`