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

ScipyModel subclasses fail to restore constant values when using from_dict #212

Closed
csala opened this issue Feb 23, 2021 · 0 comments · Fixed by #213
Closed

ScipyModel subclasses fail to restore constant values when using from_dict #212

csala opened this issue Feb 23, 2021 · 0 comments · Fixed by #213
Assignees
Labels
bug There is an error in the code that needs to be fixed
Milestone

Comments

@csala
Copy link
Contributor

csala commented Feb 23, 2021

Environment Details

Please indicate the following details about the environment in which you found the bug:

  • Copulas version: 0.4.0

Error Description

If ScipyModel subclasses are built using a dict specification that implies a constant value (such as scale=0), the constant value being passed is not properly restored, resulting on a model that samples None every time.

Steps to reproduce

To reproduce, a Univariate instance can be created passing a constant value specification, such as scale=0 on a GaussianUnivariate.

In [1]: from copulas.univariate import Univariate

In [2]: univariate = Univariate.from_dict({
   ...:     'type': 'copulas.univariate.gaussian.GaussianUnivariate',
   ...:     'loc': 10,
   ...:     'scale': 0
   ...: })

In [3]: univariate.sample(5)
Out[3]: array([None, None, None, None, None], dtype=object)

Fix

To fix this, a new method _extract_constant can be added to the ScipyModel subclasses which extracts the constant value encoded in the params and returns it, and then _set_constant_value must be used instead of _replace_constant_methods

@csala csala added the bug There is an error in the code that needs to be fixed label Feb 23, 2021
@csala csala added this to the 0.4.1 milestone Feb 23, 2021
@csala csala self-assigned this Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug There is an error in the code that needs to be fixed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant