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

Update hypotheses and common_hypothesis by pre_process_poi #135

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ debug.py
.DS_Store
docs/source/reference/release_notes.rst
.vscode
.hypothesis
2 changes: 1 addition & 1 deletion alea/examples/configs/unbinned_wimp_running.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ computation_options:
}
in_common:
{
hypotheses: ["free", "zero", "true"],
hypotheses: ["free", "zero", "true", {"poi_expectation": 15}],
output_filename: "toymc_power_wimp_mass_{wimp_mass:d}_poi_expectation_{poi_expectation:.2f}.ii.h5",
n_mc: 5000,
n_batch: 40,
Expand Down
37 changes: 27 additions & 10 deletions alea/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,33 +164,50 @@ def __init__(
statistical_model_args.get("asymptotic_dof", 1),
)

def pre_process_poi(self, value, attribute_name):
"""Pre-process of poi_expectation for some attributes of runner."""
if not all([isinstance(v, (float, int)) for v in value.values()]):
raise ValueError(
f"{attribute_name} should be a dict of float! But {value} is provided."
)
# update poi according to poi_expectation
if "poi_expectation" in value:
value = self.update_poi(self.model, self.poi, value, self.nominal_values)
dachengx marked this conversation as resolved.
Show resolved Hide resolved
return value

@property
def generate_values(self) -> Dict[str, float]:
return self._generate_values

@generate_values.setter
def generate_values(self, value: Dict[str, float]) -> None:
if not all([isinstance(v, (float, int)) for v in value.values()]):
raise ValueError(f"generate_values should be a dict of float! But {value} is provided.")
# update poi according to poi_expectation
if "poi_expectation" in value:
self.input_poi_expectation = True
value = self.update_poi(self.model, self.poi, value, self.nominal_values)
else:
self.input_poi_expectation = False
self._generate_values = value
# update poi according to poi_expectation
self._generate_values = self.pre_process_poi(value, "generate_values")

@property
def common_hypothesis(self) -> Dict[str, float]:
return self._common_hypothesis

@common_hypothesis.setter
def common_hypothesis(self, value: Dict[str, float]) -> None:
if not all([isinstance(v, (float, int)) for v in value.values()]):
raise ValueError(
f"common_hypothesis should be a dict of float! But {value} is provided."
)
self._common_hypothesis = value
# update poi according to poi_expectation
self._common_hypothesis = self.pre_process_poi(value, "common_hypothesis")

@property
def hypotheses(self) -> list:
return self._hypotheses

@hypotheses.setter
def hypotheses(self, values: list) -> None:
# update poi according to poi_expectation
for i in range(len(values)):
if isinstance(values[i], dict):
values[i] = self.pre_process_poi(values[i], "hypothesis")
self._hypotheses = values

@staticmethod
def runner_arguments():
Expand Down
Loading