From c12db93656fc275d2c4dcb4a0c329b10c9583909 Mon Sep 17 00:00:00 2001 From: Mateo VG Date: Thu, 22 Feb 2024 18:46:51 -0500 Subject: [PATCH 1/5] add distribution, boolean, and callable to Parameters --- HARK/core.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/HARK/core.py b/HARK/core.py index 71a79e2a9..80389315d 100644 --- a/HARK/core.py +++ b/HARK/core.py @@ -14,7 +14,7 @@ from copy import copy, deepcopy from dataclasses import dataclass, field from time import time -from typing import Any, Dict, List, NewType, Optional, Union +from typing import Any, Dict, List, NewType, Optional, Union, Callable from warnings import warn import numpy as np @@ -103,11 +103,11 @@ def __infer_dims__( """ Infers the age-varying dimensions of a parameter. - If the parameter is a scalar, numpy array, or None, it is assumed to be - invariant over time. If the parameter is a list or tuple, it is assumed - to be varying over time. If the parameter is a list or tuple of length - greater than 1, the length of the list or tuple must match the - `_term_age` attribute of the Parameters object. + If the parameter is a scalar, numpy array, booleanm callable or None, + it is assumed to be invariant over time. If the parameter is a list or + tuple, it is assumed to be varying over time. If the parameter is a list + or tuple of length greater than 1, the length of the list or tuple must match + the `_term_age` attribute of the Parameters object. Parameters ---------- @@ -117,7 +117,9 @@ def __infer_dims__( value of parameter """ - if isinstance(value, (int, float, np.ndarray, type(None))): + if isinstance( + value, (int, float, np.ndarray, type(None), Distribution, bool, Callable) + ): self.__add_to_invariant__(key) return value if isinstance(value, (list, tuple)): From 8ffc45106d691b75743fb942a0dbfc68102fe84e Mon Sep 17 00:00:00 2001 From: Mateo VG Date: Thu, 22 Feb 2024 18:47:57 -0500 Subject: [PATCH 2/5] add distribution to docstring --- HARK/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HARK/core.py b/HARK/core.py index 80389315d..fbd9d1e66 100644 --- a/HARK/core.py +++ b/HARK/core.py @@ -103,7 +103,7 @@ def __infer_dims__( """ Infers the age-varying dimensions of a parameter. - If the parameter is a scalar, numpy array, booleanm callable or None, + If the parameter is a scalar, numpy array, boolean, distribution, callable or None, it is assumed to be invariant over time. If the parameter is a list or tuple, it is assumed to be varying over time. If the parameter is a list or tuple of length greater than 1, the length of the list or tuple must match From d1c50727fd7c334a823ca5cbb4f26bb29c7c315c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Vel=C3=A1squez-Giraldo?= Date: Thu, 22 Feb 2024 18:57:59 -0500 Subject: [PATCH 3/5] Update CHANGELOG.md --- Documentation/CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/CHANGELOG.md b/Documentation/CHANGELOG.md index 3ac0ab23c..a70fa7701 100644 --- a/Documentation/CHANGELOG.md +++ b/Documentation/CHANGELOG.md @@ -8,6 +8,16 @@ For more information on HARK, see [our Github organization](https://github.com/e ## Changes +### 0.15.0 + +Release Date: TBA + +### Major Changes + +### Minor Changes + +- Adds support for distributions, booleans, and callables as parameters in the `Parameters` class. [1387](https://github.com/econ-ark/HARK/pull/1387) + ### 0.14.0 Release Date: February 12, 2024 From 7417c545824b8c5d51bd90646747c3ef5981e7e4 Mon Sep 17 00:00:00 2001 From: alanlujan91 Date: Wed, 28 Feb 2024 10:58:49 -0500 Subject: [PATCH 4/5] fix check --- HARK/core.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/HARK/core.py b/HARK/core.py index fbd9d1e66..313ed48f5 100644 --- a/HARK/core.py +++ b/HARK/core.py @@ -14,13 +14,11 @@ from copy import copy, deepcopy from dataclasses import dataclass, field from time import time -from typing import Any, Dict, List, NewType, Optional, Union, Callable +from typing import Any, Callable, Dict, List, NewType, Optional, Union from warnings import warn import numpy as np import pandas as pd -from xarray import DataArray - from HARK.distribution import ( Distribution, IndexDistribution, @@ -29,6 +27,7 @@ ) from HARK.parallel import multi_thread_commands, multi_thread_commands_fake from HARK.utilities import NullFunc, get_arg_names +from xarray import DataArray logging.basicConfig(format="%(message)s") _log = logging.getLogger("HARK") From 2c410fdcc4344656fde6eb62ef242a9f8c9b9fa4 Mon Sep 17 00:00:00 2001 From: Mateo VG Date: Fri, 26 Apr 2024 10:19:25 -0400 Subject: [PATCH 5/5] Add tests --- HARK/core.py | 2 +- HARK/tests/test_core.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/HARK/core.py b/HARK/core.py index 05d9b92e7..29e11236d 100644 --- a/HARK/core.py +++ b/HARK/core.py @@ -15,7 +15,7 @@ from copy import copy, deepcopy from dataclasses import dataclass, field from time import time -from typing import Any, Dict, List, Optional, Union +from typing import Any, Callable, Dict, List, Optional, Union from warnings import warn import numpy as np diff --git a/HARK/tests/test_core.py b/HARK/tests/test_core.py index c105648ab..137772040 100644 --- a/HARK/tests/test_core.py +++ b/HARK/tests/test_core.py @@ -174,12 +174,20 @@ def test_create_agents(self): class test_parameters(unittest.TestCase): def setUp(self): - self.params = Parameters(T_cycle=3, a=1, b=[2, 3, 4], c=np.array([5, 6, 7])) + self.params = Parameters( + T_cycle=3, + a=1, + b=[2, 3, 4], + c=np.array([5, 6, 7]), + d=[lambda x: x, lambda x: x**2, lambda x: x**3], + e=Uniform(), + f=[True, False, True], + ) def test_init(self): self.assertEqual(self.params._length, 3) - self.assertEqual(self.params._invariant_params, {"a", "c"}) - self.assertEqual(self.params._varying_params, {"b"}) + self.assertEqual(self.params._invariant_params, {"a", "c", "e"}) + self.assertEqual(self.params._varying_params, {"b", "d", "f"}) def test_getitem(self): self.assertEqual(self.params["a"], 1)