# Empirical Bernstein copula on a weighted sample?

**URL:** <https://openturns.discourse.group/t/empirical-bernstein-copula-on-a-weighted-sample/334>\
**Category:** Python usage\
**Created:** [November 27, 2023, 10:33am UTC](https://openturns.discourse.group/t/empirical-bernstein-copula-on-a-weighted-sample/334 "2023-11-27T10:33:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![efekhari27](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/efekhari27/32/92_2.png) [@efekhari27](https://openturns.discourse.group/u/efekhari27)\
**Post date:** [November 27, 2023, 10:33am UTC](https://openturns.discourse.group/t/empirical-bernstein-copula-on-a-weighted-sample/334/1 "2023-11-27T10:33:32Z")

</div>

Hi everyone,

I was wondering if there is a way in OpenTURNS to fit an empirical Bernstein copula (EBC) using a weighted sample.

Let us consider two samples \mathbf{X}\_{0, n}, \mathbf{X}\_{1, n} (each in \mathbb{R}^d, with size n) independently generated after two well known distributions: \mathbf{X}\_{0, n} \sim h\_0 and \mathbf{X}\_{1, n} \sim h\_1. I would like to use the two samples to fit the copula associated with the distribution h\_0.

Would it be legitimate to apply importance sampling weights to the sample \mathbf{X}\_{1, n} and fit an EBC using the union of \mathbf{X}\_{1, n} weighted and \mathbf{X}\_{0, n}? And is there a way to use the ot.EmpiricalBernsteinCopula class to do so?

Thanks in advance for your answers!  
Elias

---

<div class="post-metadata">

**Author:** ![josephmure](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/josephmure/32/114_2.png) [@josephmure](https://openturns.discourse.group/u/josephmure)\
**Post date:** [November 30, 2023, 8:15am UTC](https://openturns.discourse.group/t/empirical-bernstein-copula-on-a-weighted-sample/334/2 "2023-11-30T08:15:50Z")

</div>

Hi Elias, for now the only way to do that I see is to repeat the points with larger weight in the sample. That is because the `EmpiricalBernsteinCopula` constructor requires a `Sample`, whereas a weighted sample would be represented in the library by a `WeightedExperiment`.

---

<div class="post-metadata">

**Author:** ![efekhari27](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/efekhari27/32/92_2.png) [@efekhari27](https://openturns.discourse.group/u/efekhari27)\
**Post date:** [December 1, 2023, 11:06am UTC](https://openturns.discourse.group/t/empirical-bernstein-copula-on-a-weighted-sample/334/3 "2023-12-01T11:06:45Z")

</div>

Hi Joseph,

Thanks for your answer. Working with repetitions works perfectly to emulate weights even if it’s probably not optimal numerically.

Best,  
Elias

---

<div class="post-metadata">

**Author:** ![regislebrun](https://yyz2.discourse-cdn.com/free1/user_avatar/openturns.discourse.group/regislebrun/32/154_2.png) [@regislebrun](https://openturns.discourse.group/u/regislebrun)\
**Post date:** [December 5, 2023, 11:34am UTC](https://openturns.discourse.group/t/empirical-bernstein-copula-on-a-weighted-sample/334/4 "2023-12-05T11:34:48Z")

</div>

In addition to Joseph’s excellent answer (the repetition of points according to their weights), I would like to confirm that the approach you describe is perfectly sounded. With w\_i=h\_0(\mathbf{X}\_{1,n}^i)/h\_1(\mathbf{X}\_{1,n}^i), the weighted sample (w,\mathbf{X}\_{1,n}) is distributed according to h\_0.

Unfortunately we don’t have the concept of weighted sample in OT yet. We manipulate separately the sample and the weights, as produced e.g by a WeightedExperiment (which is indeed a _weighted sample generator_).

The current implementation of EmpiricalBernsteinCopula relies heavily on the uniform weights. It could be adapted to nonuiform weights (and BernsteinCopulaFactory too) but the cost in terms of performance (sampling, PDF/CDF computation) will probably be significant. It can be added to the whish list on github with a short description of the context, in particular the dimension and the size of the samples you want to use.
