From 71ed76bfd9e73d4769f16fc3aa53accfdeff2e89 Mon Sep 17 00:00:00 2001 From: Knut Dundas Moraa Date: Fri, 14 Jul 2023 15:49:15 -0400 Subject: [PATCH 1/4] Change data format to only use structured arrays to avoid data loader mess. --- alea/blueice_extended_model.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/alea/blueice_extended_model.py b/alea/blueice_extended_model.py index d1af0cdd..bfbeca3e 100644 --- a/alea/blueice_extended_model.py +++ b/alea/blueice_extended_model.py @@ -8,6 +8,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 class BlueiceExtendedModel(StatisticalModel): @@ -155,7 +156,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 = [gen.simulate(**generate_values) @@ -177,7 +178,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) class CustomAncillaryLikelihood(LogAncillaryLikelihood): @@ -215,16 +216,16 @@ 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. - assert set(d.keys()) == set(self.parameters.names) - self.constraint_functions = self._get_constraint_functions(**d) + assert set(d.dtype.names) == set(self.parameters.names) + self.constraint_functions = self._get_constraint_functions(**structured_array_to_dict(d)) def ancillary_likelihood_sum(self, evaluate_at: dict) -> float: """Return the sum of all constraint terms. From 130047ee85e21ef0995f752f78b4f38d87926cf6 Mon Sep 17 00:00:00 2001 From: Knut Dundas Moraa Date: Fri, 14 Jul 2023 16:34:34 -0400 Subject: [PATCH 2/4] add .flake8 file to ignore assert errors --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000..ac7deb56 --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +extend-ignore = S101 From d56a1e0f741d97530dac956f3d6b610c3acee20c Mon Sep 17 00:00:00 2001 From: dachengx Date: Tue, 25 Jul 2023 18:05:08 +0800 Subject: [PATCH 3/4] flake ignore in setup.cfg --- .flake8 | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index ac7deb56..00000000 --- a/.flake8 +++ /dev/null @@ -1,2 +0,0 @@ -[flake8] -extend-ignore = S101 From 93fc829e3c21f26c33c27ab3d8e6a7813b73702c Mon Sep 17 00:00:00 2001 From: dachengx Date: Tue, 25 Jul 2023 18:06:21 +0800 Subject: [PATCH 4/4] Remove unused import --- alea/models/blueice_extended_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alea/models/blueice_extended_model.py b/alea/models/blueice_extended_model.py index 764a46a7..52694b19 100644 --- a/alea/models/blueice_extended_model.py +++ b/alea/models/blueice_extended_model.py @@ -5,7 +5,7 @@ import numpy as np import scipy.stats as stats from blueice.likelihood import LogAncillaryLikelihood, LogLikelihoodSum -from inference_interface import dict_to_structured_array, structured_array_to_dict +from inference_interface import dict_to_structured_array from alea.model import StatisticalModel from alea.simulators import BlueiceDataGenerator