Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request - Parameter Loading - MarginalCopula #30

Open
kaleb-keny opened this issue Nov 30, 2020 · 2 comments
Open

Feature Request - Parameter Loading - MarginalCopula #30

kaleb-keny opened this issue Nov 30, 2020 · 2 comments
Assignees

Comments

@kaleb-keny
Copy link

I am not sure this is possible, but I am trying to do is save the parameters of the fit and load them in the future (as to avoid having to refit the data). So the parameters of a MarginalCopula fit are obtained using the following:

params = cop.params
Out[37]: 
{'copula': 6.935870895461638,
 'marginals': [{'type': 'gamma',
   'parameters': {'a': 1.2455705214968726,
    'loc': -0.00018850468681980907,
    'scale': 10.725816166928752}},
  {'type': 'genpareto',
   'parameters': {'c': 1.9383054484824958,
    'loc': -1.982576615044322e-09,
    'scale': 1.273334393803809}}]}

Then loading them back into a copula object is kind of tricky because the parameters for a Marginal Copula is a dict, as opposed to a numpy array. Maybe there is already a hard way to this.

@DanielBok DanielBok reopened this Dec 5, 2020
@DanielBok
Copy link
Owner

DanielBok commented Dec 5, 2020

Good point, I'll think of how we can make it look as such for the GMC

# assuming params is the dictionary, will do some checks to ensure it's properly defined here
cop.params = params

I believe one alternative to saving the copula parameters is to save the copula object as a pickle. This removes the issue with the user needing to know which copula the parameter is for.

import pickle

with open('my-cop.p', 'wb') as f:
    pickle.dump(my_cop, f)

Later on, we wouldn't need to know whether to import Gaussian, Student, or any other copula. We could just load the copula as-is. The parameters can still be accessed via copula.params property

@kaleb-keny
Copy link
Author

kaleb-keny commented Dec 5, 2020

@DanielBok although that is the easy way out 😄 and I was thinking of pickling the cop object lol... But I thought that this wouldn't be like the most elegant of solution, because you lose the info due to pkl compression, so the object isn't recognizable unless you unpickle it... I mean, that saving & loading the parameters of the copula, which is kind of a dict now, will allow transferring of parameters and allow you to see how the parameters are evolving across different fits... But maybe for this to work, you need maybe to add to the dict in cop.params the type of copula being used so on load it can push in those parameters accordingly...
I mean the solution your proposed for the gaussian/student works perfectly as you just need that array (representing correlation matrix)... Something that follows along that kind of work would be a dict with parameters inside...
But I'll probably leave the design part to you, as you might know more about the complications of making a generalized copula class that takes in any parameters that is pre-saved and generates the copula accordingly....
Also to note, that I maybe have a bias towards this, because I'm saving the parameters in a db as a json file to load them later...

@DanielBok DanielBok self-assigned this Dec 21, 2020
@kaleb-keny kaleb-keny reopened this Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants