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 default_*_config from @property to @staticmethod #235

Merged
merged 2 commits into from
Sep 1, 2023
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
8 changes: 4 additions & 4 deletions pymc_experimental/linearmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ def __init__(self, model_config: Dict = None, sampler_config: Dict = None, nsamp
_model_type = "LinearModel"
version = "0.1"

@property
def default_model_config(self):
@staticmethod
def get_default_model_config():
return {
"intercept": {"loc": 0, "scale": 10},
"slope": {"loc": 0, "scale": 10},
"obs_error": 2,
}

@property
def default_sampler_config(self):
@staticmethod
def get_default_sampler_config():
return {
"draws": 1_000,
"tune": 1_000,
Expand Down
26 changes: 14 additions & 12 deletions pymc_experimental/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ def __init__(
>>> ...
>>> model = MyModel(model_config, sampler_config)
"""
sampler_config = self.default_sampler_config if sampler_config is None else sampler_config
sampler_config = (
self.get_default_sampler_config() if sampler_config is None else sampler_config
)
self.sampler_config = sampler_config
model_config = self.default_model_config if model_config is None else model_config
model_config = self.get_default_model_config() if model_config is None else model_config

self.model_config = model_config # parameters for priors etc.
self.model = None # Set by build_model
Expand Down Expand Up @@ -133,17 +135,17 @@ def output_var(self):
"""
raise NotImplementedError

@property
@staticmethod
@abstractmethod
def default_model_config(self) -> Dict:
def get_default_model_config() -> Dict:
"""
Returns a class default config dict for model builder if no model_config is provided on class initialization
Useful for understanding structure of required model_config to allow its customization by users
Examples
--------
>>> @classmethod
>>> def default_model_config(self):
>>> Return {
>>> @staticmethod
>>> def default_model_config():
>>> return {
>>> 'a' : {
>>> 'loc': 7,
>>> 'scale' : 3
Expand All @@ -162,17 +164,17 @@ def default_model_config(self) -> Dict:
"""
raise NotImplementedError

@property
@staticmethod
@abstractmethod
def default_sampler_config(self) -> Dict:
def get_default_sampler_config(self) -> Dict:
"""
Returns a class default sampler dict for model builder if no sampler_config is provided on class initialization
Useful for understanding structure of required sampler_config to allow its customization by users
Examples
--------
>>> @classmethod
>>> def default_sampler_config(self):
>>> Return {
>>> @staticmethod
>>> def default_sampler_config():
>>> return {
>>> 'draws': 1_000,
>>> 'tune': 1_000,
>>> 'chains': 1,
Expand Down
10 changes: 5 additions & 5 deletions pymc_experimental/tests/test_model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def build_model(self, X: pd.DataFrame, y: pd.Series, model_config=None):
self.generate_and_preprocess_model_data(X, y)
with pm.Model(coords=coords) as self.model:
if model_config is None:
model_config = self.default_model_config
model_config = self.model_config
x = pm.MutableData("x", self.X["input"].values)
y_data = pm.MutableData("y_data", self.y)

Expand Down Expand Up @@ -114,8 +114,8 @@ def generate_and_preprocess_model_data(self, X: pd.DataFrame, y: pd.Series):
self.X = X
self.y = y

@property
def default_model_config(self) -> Dict:
@staticmethod
def get_default_model_config() -> Dict:
return {
"a": {"loc": 0, "scale": 10, "dims": ("numbers",)},
"b": {"loc": 0, "scale": 10},
Expand All @@ -128,8 +128,8 @@ def _generate_and_preprocess_model_data(
self.X = X
self.y = y

@property
def default_sampler_config(self) -> Dict:
@staticmethod
def get_default_sampler_config() -> Dict:
return {
"draws": 1_000,
"tune": 1_000,
Expand Down