From 3d5b52123287eae285b223084dbc9c4ddcec0c29 Mon Sep 17 00:00:00 2001 From: alekracicot Date: Wed, 10 Aug 2022 14:17:50 -0400 Subject: [PATCH 1/5] fix Model docstring --- pymc/model.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/pymc/model.py b/pymc/model.py index 20a3f8ba45..769287017b 100644 --- a/pymc/model.py +++ b/pymc/model.py @@ -466,24 +466,24 @@ def __init__(self, mean=0, sigma=1, name=''): # will get model's name prefix # 3) you can create variables with Var method - self.Var('v1', Normal.dist(mu=mean, sigma=sd)) - # this will create variable named like '{prefix::}v1' + self.register_rv(pm.Normal.dist(mu=mean, sigma=sigma), 'v1', initval=1) + # this will create variable named like '{name::}v1' # and assign attribute 'v1' to instance created # variable can be accessed with self.v1 or self['v1'] # 4) this syntax will also work as we are in the # context of instance itself, names are given as usual - Normal('v2', mu=mean, sigma=sd) + pm.Normal('v2', mu=mean, sigma=sigma # something more complex is allowed, too - half_cauchy = HalfCauchy('sigma', beta=10, initval=1.) - Normal('v3', mu=mean, sigma=half_cauchy) + half_cauchy = pm.HalfCauchy('sd', beta=10, initval=1.) + pm.Normal('v3', mu=mean, sigma=half_cauchy) # Deterministic variables can be used in usual way - Deterministic('v3_sq', self.v3 ** 2) + pm.Deterministic('v3_sq', self.v3 ** 2) # Potentials too - Potential('p1', at.constant(1)) + pm.Potential('p1', at.constant(1)) # After defining a class CustomModel you can use it in several # ways @@ -497,7 +497,7 @@ def __init__(self, mean=0, sigma=1, name=''): # II: # use new class as entering point in context with CustomModel() as model: - Normal('new_normal_var', mu=1, sigma=0) + pm.Normal('new_normal_var', mu=1, sigma=0) # III: # just get model instance with all that was defined in it @@ -510,7 +510,6 @@ def __init__(self, mean=0, sigma=1, name=''): CustomModel(mean=2, name='second') # variables inside both scopes will be named like `first::*`, `second::*` - """ if TYPE_CHECKING: From 87e2469a2e647538b21eaf15e05cc59174b190a3 Mon Sep 17 00:00:00 2001 From: alekracicot Date: Fri, 19 Aug 2022 12:56:31 -0400 Subject: [PATCH 2/5] Added pm. before Model call --- pymc/model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pymc/model.py b/pymc/model.py index 769287017b..ac1c07b8ff 100644 --- a/pymc/model.py +++ b/pymc/model.py @@ -473,7 +473,7 @@ def __init__(self, mean=0, sigma=1, name=''): # 4) this syntax will also work as we are in the # context of instance itself, names are given as usual - pm.Normal('v2', mu=mean, sigma=sigma + pm.Normal('v2', mu=mean, sigma=sigma) # something more complex is allowed, too half_cauchy = pm.HalfCauchy('sd', beta=10, initval=1.) @@ -490,7 +490,7 @@ def __init__(self, mean=0, sigma=1, name=''): # I: # state the model within a context - with Model() as model: + with pm.Model() as model: CustomModel() # arbitrary actions @@ -505,7 +505,7 @@ def __init__(self, mean=0, sigma=1, name=''): # IV: # use many custom models within one context - with Model() as model: + with pm.Model() as model: CustomModel(mean=1, name='first') CustomModel(mean=2, name='second') From 4e13a6bc852387e1ab22478377c3bd517f950ec6 Mon Sep 17 00:00:00 2001 From: alekracicot Date: Mon, 22 Aug 2022 09:22:25 -0400 Subject: [PATCH 3/5] added suggested changes --- pymc/model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymc/model.py b/pymc/model.py index ac1c07b8ff..371d242fca 100644 --- a/pymc/model.py +++ b/pymc/model.py @@ -465,8 +465,8 @@ def __init__(self, mean=0, sigma=1, name=''): # variables in several ways note, that all variables # will get model's name prefix - # 3) you can create variables with Var method - self.register_rv(pm.Normal.dist(mu=mean, sigma=sigma), 'v1', initval=1) + # 3) you can create variables with the register_rv method + self.register_rv(Normal.dist(mu=mean, sigma=sigma), 'v1', initval=1) # this will create variable named like '{name::}v1' # and assign attribute 'v1' to instance created # variable can be accessed with self.v1 or self['v1'] From b87b18b15c37660f917473ea80dd07ed543cc7e6 Mon Sep 17 00:00:00 2001 From: alekracicot Date: Tue, 23 Aug 2022 09:01:48 -0400 Subject: [PATCH 4/5] Remove pm. --- pymc/model.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pymc/model.py b/pymc/model.py index 371d242fca..69d6872dc1 100644 --- a/pymc/model.py +++ b/pymc/model.py @@ -473,31 +473,31 @@ def __init__(self, mean=0, sigma=1, name=''): # 4) this syntax will also work as we are in the # context of instance itself, names are given as usual - pm.Normal('v2', mu=mean, sigma=sigma) + Normal('v2', mu=mean, sigma=sigma) # something more complex is allowed, too - half_cauchy = pm.HalfCauchy('sd', beta=10, initval=1.) - pm.Normal('v3', mu=mean, sigma=half_cauchy) + half_cauchy = HalfCauchy('sd', beta=10, initval=1.) + Normal('v3', mu=mean, sigma=half_cauchy) # Deterministic variables can be used in usual way - pm.Deterministic('v3_sq', self.v3 ** 2) + Deterministic('v3_sq', self.v3 ** 2) # Potentials too - pm.Potential('p1', at.constant(1)) + Potential('p1', at.constant(1)) # After defining a class CustomModel you can use it in several # ways # I: # state the model within a context - with pm.Model() as model: + with Model() as model: CustomModel() # arbitrary actions # II: # use new class as entering point in context with CustomModel() as model: - pm.Normal('new_normal_var', mu=1, sigma=0) + Normal('new_normal_var', mu=1, sigma=0) # III: # just get model instance with all that was defined in it @@ -505,7 +505,7 @@ def __init__(self, mean=0, sigma=1, name=''): # IV: # use many custom models within one context - with pm.Model() as model: + with Model() as model: CustomModel(mean=1, name='first') CustomModel(mean=2, name='second') From b88ade7c9e1962b14e7fc78ea217ee91546d3f74 Mon Sep 17 00:00:00 2001 From: Ricardo Vieira <28983449+ricardoV94@users.noreply.github.com> Date: Fri, 26 Aug 2022 09:23:48 +0200 Subject: [PATCH 5/5] Update pymc/model.py --- pymc/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymc/model.py b/pymc/model.py index 69d6872dc1..ed5a0f0555 100644 --- a/pymc/model.py +++ b/pymc/model.py @@ -476,7 +476,7 @@ def __init__(self, mean=0, sigma=1, name=''): Normal('v2', mu=mean, sigma=sigma) # something more complex is allowed, too - half_cauchy = HalfCauchy('sd', beta=10, initval=1.) + half_cauchy = HalfCauchy('sigma', beta=10, initval=1.) Normal('v3', mu=mean, sigma=half_cauchy) # Deterministic variables can be used in usual way