DanielBok / copulae

Multivariate data modelling with Copulas in Python
https://copulae.readthedocs.io/en/latest/
MIT License
141 stars 26 forks source link

EmpiricalCopula usage #21

Closed M-Soundouss closed 4 years ago

M-Soundouss commented 4 years ago

Hello,

I am trying to use the EmpiricalCopula class and I am having some difficulties.

Example code :

from copulae import EmpiricalCopula
import numpy as np

np.random.seed(8)
data = np.random.uniform(size=(3000, 3))
cop = EmpiricalCopula(dim=3, data=data)

print(cop.random(10))  # simulate random number
print(cop.cdf(np.array([[0.1, 0.5, 1]])))

I find that the cop.cdf always gives the same number no matter what I use in the input. Am I using it wrong?

Thanks for writing this package. Best,

DanielBok commented 4 years ago

Hello,

Addressing 2 issues:

  1. You see the same random variables because of the seed
  2. The cdf is a 1-to-1 transformation so given any input, it should return deterministically the same output

That said, after reviewing the code, I noticed I made a mistake with the random generation in that I should have sampled the data with replacement. I'll fix it in the next update.

M-Soundouss commented 4 years ago

Hello,

Thanks for your response. Sorry I was not clear enough, what I meant is that :

print(cop.cdf(np.array([[0.1, 0.5, 1.]])))

# Gives [0.13366667]

print(cop.cdf(np.array([[0.1, 1., 1.]])))

# Gives [0.13366667]

print(cop.cdf(np.array([[1., 1., 1.]])))

# Gives [0.13366667]

I understand that cdf is deterministic but it does not mean that it should map all possible inputs into 0.13366667, right?

This behavior is different from other types of copulae (like the normal one) where the cdf function gives the output I expected.

DanielBok commented 4 years ago

Yes, you're right. Thank you for pointing out the bug.

The issue arises because I was trying to make it convenient by auto-adjusting the data into pseudo-observations when it is not already so. When I take it away, it'll be correct. I'll release the fix in the next copy.

M-Soundouss commented 4 years ago

Thank you very much! Looking forward to it.

DanielBok commented 4 years ago

@M-Soundouss I pushed up a fix in 0.7.0.

M-Soundouss commented 4 years ago

Thank you very much!