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

Emcee batch fix #408

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions flepimop/gempyor_pkg/src/gempyor/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ def calibrate(

# Draw/get initial parameters:
backend = emcee.backends.HDFBackend(filename)
# save the dataframe of parameter names (this should be added to the h5 file)
gempyor_inference.inferpar.get_parameter_df().to_csv(filename.replace(".h5", ".csv"), index=True)
if resume or resume_location is not None:
# Normally one would put p0 = None to get the last State from the sampler, but that poses problems when the likelihood change
# and then acceptances are not guaranted, see issue #316. This solves this issue and greates a new chain with llik evaluation
Expand Down
5 changes: 3 additions & 2 deletions flepimop/gempyor_pkg/src/gempyor/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,14 +382,15 @@ def __init__(
self.already_built = False # whether we have already built the costly objects that need just one build
self.autowrite_seir = autowrite_seir

self.static_sim_arguments = get_static_arguments(self.modinf)

## Inference Stuff
self.do_inference = False
if config["inference"].exists():
from . import inference_parameter, logloss

if config["inference"]["method"].get("default") == "emcee":
# Generates the static_sim_arguments only if this is a config argument.
self.static_sim_arguments = get_static_arguments(self.modinf)

self.do_inference = True
self.inference_method = "emcee"
self.inferpar = inference_parameter.InferenceParameters(
Expand Down
11 changes: 11 additions & 0 deletions flepimop/gempyor_pkg/src/gempyor/inference_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ def __len__(self):
so one can use the built-in python len function
"""
return len(self.pnames)

def get_parameter_df(self):
data = {
"ptypes": self.ptypes,
"subpops": self.subpops,
"pnames": self.pnames
}
df = pd.DataFrame(data)
return df

def draw_initial(self, n_draw=1):
"""
Expand Down Expand Up @@ -235,6 +244,8 @@ def inject_proposal(
hnpi_df_mod = hnpi_df.copy(deep=True)

# Ideally this should lie in each submodules, e.g NPI.inject, parameter.inject
if self.get_dim() != len(proposal):
raise ValueError(f"Inference object stores {self.get_dim()} parameters, but received a proposal of lenght {len(proposal)} to be injected.")
jcblemai marked this conversation as resolved.
Show resolved Hide resolved

for p_idx in range(self.get_dim()):
if self.ptypes[p_idx] == "seir_modifiers":
Expand Down
2 changes: 2 additions & 0 deletions flepimop/gempyor_pkg/src/gempyor/outcomes.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def read_parameters_from_config(modinf: model_info.ModelInfo):
parameters[new_comp]["delay::npi_param_name"] = f"{new_comp}::delay".lower()
else:
logging.critical(f"No delay for outcome {new_comp}, using a 0 delay")
# FIXME: We should not here modify outcomes_config := modinf.outcomes_config["outcomes"]
# because this changes the order in which the outcomes the next time this function is called.
Comment on lines +201 to +202
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be tracking this with an issue - possible to explain via that way? Fine with the FIXME marker here (tho @TimothyWillard mgiht not be), but we'll lose track of it if not an issue.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree. It's in #373 as the PR should not close this issue (but fixes it in Sara's use case), though perhaps redefining the title would be helpful, so it's more precise.

outcomes_config[new_comp]["delay"] = {"value": 0}
parameters[new_comp]["delay"] = outcomes_config[new_comp]["delay"]["value"]
parameters[new_comp]["delay::npi_param_name"] = f"{new_comp}::delay".lower()
Expand Down