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

Filtering API for python #132

Open
eerolinna opened this issue Jan 16, 2020 · 0 comments
Open

Filtering API for python #132

eerolinna opened this issue Jan 16, 2020 · 0 comments

Comments

@eerolinna
Copy link
Contributor

The R filtering API is like

pos <- filter_posteriors(my_pdb, data_name == "eight_schools")

The same exact API cannot be done in python*. I propose this instead

pos = my_pdb.filter_posteriors(lambda posterior: posterior.data.name == "eight_schools")

In other words, filter_posteriors takes a function that takes a posterior object and returns a bool.

The function doesn't have to be given inline, the following is valid too

def filter_function(posterior):
    return posterior.data.name == "eight_schools"
pos = my_pdb.filter_posteriors(filter_function)

Return value of filter_posteriors is a list of posterior objects.

I also propose adding filter_models and filter_data that are equivalent to filter_posteriors but act instead on models or data.

The following query finds the posteriors where model has keyword bda3_example

filtered_models = my_pdb.filter_models(lambda model: "bda3_example" in model.information["keywords"])
filtered_posteriors = my_pdb.filter_posteriors(lambda posterior: posterior.model in filtered_models)

[*] This is because python doesn't support unevaluated expressions like data_name == "eight_schools"

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

1 participant