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

[ENH] support for named parameters #20

Open
tmcclintock opened this issue Jun 23, 2021 · 1 comment
Open

[ENH] support for named parameters #20

tmcclintock opened this issue Jun 23, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@tmcclintock
Copy link

In emcee I added a PR for having named parameters (proposal, and the PR). This allows for dict-like access to the parameters rather than positional references. Example:

x = np.random.randn(100)  # 100 samples ~ N(0, 1)

def lnpdf(self, params: Dict[str, float]) -> np.float64:
    # A gaussian PDF with named parameters
    mean = params["mean"]
    var = params["var"]
    if var <= 0:
        return -np.inf
    return (
        -0.5 * ((mean - self.x) ** 2 / var + np.log(2 * np.pi * var)).sum()
    )

The main benefit is this allows one to build hierarchical models without having to remember "oh the first parameter for the N-th submodel is at position XYZ" (a common source of bugs).

Since zeus has the same API, I'd be happy to add it here too.

@minaskar minaskar added the enhancement New feature or request label Jun 23, 2021
@minaskar
Copy link
Owner

That looks great! Really useful feature. Please go ahead submitting a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants