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

Change data format to only use structured arrays #42

Merged
merged 6 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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 .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
extend-ignore = S101
9 changes: 5 additions & 4 deletions alea/blueice_extended_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import scipy.stats as stats
from blueice.likelihood import LogAncillaryLikelihood
from blueice.likelihood import LogLikelihoodSum
from inference_interface import dict_to_structured_array, structured_array_to_dict
dachengx marked this conversation as resolved.
Show resolved Hide resolved

from alea.statistical_model import StatisticalModel
from alea.simulators import BlueiceDataGenerator
Expand Down Expand Up @@ -187,7 +188,7 @@ def _generate_data(self, **generate_values) -> list:
generate_values_anc = {k: v for k, v in generate_values.items() if k in ancillary_keys}
ancillary_measurements = self._generate_ancillary_measurements(
**generate_values_anc)
return science_data + [ancillary_measurements] + [generate_values]
return science_data + [ancillary_measurements] + [dict_to_structured_array(generate_values)]

def _generate_science_data(self, **generate_values) -> list:
science_data = [
Expand All @@ -209,7 +210,7 @@ def _generate_ancillary_measurements(self, **generate_values) -> dict:
parameter_meas = param.fit_limits[1]
ancillary_measurements[name] = parameter_meas

return ancillary_measurements
return dict_to_structured_array(ancillary_measurements)

def _set_efficiency(self, source, ll):
if "efficiency_name" not in source:
Expand Down Expand Up @@ -275,12 +276,12 @@ def constraint_terms(self) -> dict:
"""
return {name: func.logpdf for name, func in self.constraint_functions.items()}

def set_data(self, d: dict):
def set_data(self, d: np.array):
"""
Set the data of the ancillary likelihood (ancillary measurements).

Args:
d (dict): Data in this case is a dict of ancillary measurements.
d (np.array): Data of ancillary measurements, stored as numpy array
"""
# This results in shifted constraint terms.
if set(d.keys()) != set(self.parameters.names):
Expand Down