From 7090ee68a5b4a439a7b0ec89db115ed9b8a391fe Mon Sep 17 00:00:00 2001 From: Mateo VG Date: Thu, 27 Apr 2023 16:16:17 -0400 Subject: [PATCH 1/3] Fix metric bug --- HARK/metric.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HARK/metric.py b/HARK/metric.py index d1151058e..3c434d782 100644 --- a/HARK/metric.py +++ b/HARK/metric.py @@ -29,7 +29,7 @@ def distance_dicts(dict_a, dict_b): len_b = len(dict_b) if len_a == len_b: - if set(dict_a.keys()) == set(dict_b.keys()): + if set(dict_a.keys()) != set(dict_b.keys()): warn("Dictionaries with keys that do not match are being compared.") return 1000.0 return np.max( From bb139431c5e20d6224c16be25d878baf6ada5eef Mon Sep 17 00:00:00 2001 From: Mateo VG Date: Thu, 27 Apr 2023 16:20:34 -0400 Subject: [PATCH 2/3] Test dictionary metric --- HARK/tests/test_core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/HARK/tests/test_core.py b/HARK/tests/test_core.py index 76fed5d12..6b61a80f8 100644 --- a/HARK/tests/test_core.py +++ b/HARK/tests/test_core.py @@ -22,6 +22,9 @@ def setUp(self): self.obj_a = MetricObject() self.obj_b = MetricObject() self.obj_c = MetricObject() + self.dict_a = {"a": 1, "b": 2} + self.dict_b = {"a": 3, "b": 4} + self.dict_c = {"a": 5, "f": 6} def test_list(self): # same length @@ -46,6 +49,12 @@ def test_array(self): distance_metric(np.array(self.list_b), np.array(self.list_b)), 0.0 ) + def test_dict(self): + # Same keys (max of diffs across keys) + self.assertEqual(distance_metric(self.dict_a, self.dict_b), 2.0) + # Different keys + self.assertEqual(distance_metric(self.dict_a, self.dict_c), 1000.0) + def test_hark_object_distance(self): self.obj_a.distance_criteria = ["var_1", "var_2", "var_3"] self.obj_b.distance_criteria = ["var_1", "var_2", "var_3"] From 801c57ebf73952034062fe35279a1b5c7ed65450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Vel=C3=A1squez-Giraldo?= Date: Thu, 27 Apr 2023 16:26:11 -0400 Subject: [PATCH 3/3] Update CHANGELOG.md --- Documentation/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/CHANGELOG.md b/Documentation/CHANGELOG.md index 38cc9eab2..8d09cc628 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/CHANGELOG.md @@ -19,6 +19,7 @@ Release Date: TBD ### Minor Changes - Adds option `sim_common_Rrisky` to control whether risky-asset models draw common or idiosyncratic returns in simulation. [#1250](https://github.com/econ-ark/HARK/pull/1250),[#1253](https://github.com/econ-ark/HARK/pull/1253) +- Fixes bug in the metric that compares dictionaries with the same keys. [#1260](https://github.com/econ-ark/HARK/pull/1260) ### 0.13.0