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

Create copies for include and values of other parameters to avoid directly modifying the original object #327

Closed
digicosmos86 opened this issue Nov 20, 2023 Discussed in #325 · 0 comments · Fixed by #331
Assignees
Labels
bug Something isn't working

Comments

@digicosmos86
Copy link
Collaborator

Discussed in #325

Originally posted by younesStrittmatter November 20, 2023
here is a code snippet to explain the issue (maybe it is the expected behavior, but could lead to errors down the line):

# define include (e.g., to be used for multiple models)
include = [
        {
            "name": "v",
            "prior": {
                "Intercept": {"name": "Uniform", "lower": -3.0, "upper": 3.0},
                "coherence": {"name": "Uniform", "lower": 0., "upper": 1.0},
            },
            "formula": "v ~ 1 + coherence",
            "link": "identity",
        }
    ]
    print('before')
    print(include)
    model_ddm = hssm.HSSM(
        data=data.copy(),
        model='ddm',
        include=i_,
    ).sample(sampler="nuts_numpyro", chains=chains, cores=cores, draws=draws, tune=tune)
    print('after')
    print(include)

leads to:

    before
    [{'name': 'v', 'prior': {'Intercept': {'name': 'Uniform', 'lower': -3.0, 'upper': 3.0}, 'coherence': {'name': 'Uniform', 'lower': 0.0, 'upper': 1.0}}, 'formula': 'v ~ 1 + coherence', 'link': 'identity'}]
    
    after
    [{'name': 'v', 'prior': {'Intercept': {'name': 'Uniform', 'lower': -3.0, 'upper': 3.0}, 'coherence': {'name': 'Uniform', 'lower': 0.0, 'upper': 1.0}}, 'formula': 'v ~ 1 + coherence', 'link': 'identity', 'bounds': (-inf, inf)}, {'name': 'p_outlier', 'prior': 0.05, 'bounds': None}]

If you want to use the same inclue in a different model, this then leads to an error:

ValueError: Please do not specify `p_outlier` in `include`. Please specify it with `p_outlier` instead.
</div>
@digicosmos86 digicosmos86 added the bug Something isn't working label Nov 20, 2023
@digicosmos86 digicosmos86 self-assigned this Nov 20, 2023
@digicosmos86 digicosmos86 changed the title Create copies for include and values of other parameters to avoid directly modifying the original object. Create copies for include and values of other parameters to avoid directly modifying the original object Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant