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
Create the copula class
Inherit from CopulaModel (and ModelSelectionMixin, SupportsTailDependence if applicable)
Implement the methods: get_cdf, get_pdf, sample, kendall_tau, etc.
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):
...
Add to the factory
from CopulaFurtif.core.copulas.domain.factories.copula_factory import CopulaFactory
from CopulaFurtif.core.copulas.domain.models.archimedean.mycopula import MyCopula
CopulaFactory.register("mycopula", MyCopula)
Write a unit test
Test all behaviors: parameters, PDF, CDF, derivatives, etc.
Place the file in tests/units/test_my_model.py
(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