Skip to content

Commit 37c0a92

Browse files
authored
Merge pull request #3309 from pymc-devs/rename_sd_to_sigma
Rename sd to sigma for consistency.
2 parents 98fd63e + fcbdf96 commit 37c0a92

File tree

94 files changed

+850
-795
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+850
-795
lines changed

RELEASE-NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
### Maintenance
88

9+
- All occurances of `sd` as a parameter name have been renamed to `sigma`. `sd` will continue to function for backwards compatibility.
910
- Made `BrokenPipeError` for parallel sampling more verbose on Windows.
1011
- Added the `broadcast_distribution_samples` function that helps broadcasting arrays of drawn samples, taking into account the requested `size` and the inferred distribution shape. This sometimes is needed by distributions that call several `rvs` separately within their `random` method, such as the `ZeroInflatedPoisson` (Fix issue #3310).
1112
- The `Wald`, `Kumaraswamy`, `LogNormal`, `Pareto`, `Cauchy`, `HalfCauchy`, `Weibull` and `ExGaussian` distributions `random` method used a hidden `_random` function that was written with scalars in mind. This could potentially lead to artificial correlations between random draws. Added shape guards and broadcasting of the distribution samples to prevent this (Similar to issue #3310).

docs/source/Advanced_usage_of_Theano_in_PyMC3.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ be time consuming if the number of datasets is large)::
3232
data = theano.shared(observed_data[0])
3333
pm.Model() as model:
3434
mu = pm.Normal('mu', 0, 10)
35-
pm.Normal('y', mu=mu, sd=1, observed=data)
35+
pm.Normal('y', mu=mu, sigma=1, observed=data)
3636

3737
# Generate one trace for each dataset
3838
traces = []
@@ -53,7 +53,7 @@ variable for our observations::
5353
x_shared = theano.shared(x)
5454

5555
with pm.Model() as model:
56-
coeff = pm.Normal('x', mu=0, sd=1)
56+
coeff = pm.Normal('x', mu=0, sigma=1)
5757
logistic = pm.math.sigmoid(coeff * x_shared)
5858
pm.Bernoulli('obs', p=logistic, observed=y)
5959

@@ -210,8 +210,8 @@ We can now define our model using this new op::
210210
tt_mu_from_theta = MuFromTheta()
211211

212212
with pm.Model() as model:
213-
theta = pm.HalfNormal('theta', sd=1)
213+
theta = pm.HalfNormal('theta', sigma=1)
214214
mu = pm.Deterministic('mu', tt_mu_from_theta(theta))
215-
pm.Normal('y', mu=mu, sd=0.1, observed=[0.2, 0.21, 0.3])
215+
pm.Normal('y', mu=mu, sigma=0.1, observed=[0.2, 0.21, 0.3])
216216

217217
trace = pm.sample()

docs/source/Probability_Distributions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ For example, if we wish to define a particular variable as having a normal prior
1212

1313
with pm.Model():
1414
15-
x = pm.Normal('x', mu=0, sd=1)
15+
x = pm.Normal('x', mu=0, sigma=1)
1616
1717
A variable requires at least a ``name`` argument, and zero or more model parameters, depending on the distribution. Parameter names vary by distribution, using conventional names wherever possible. The example above defines a scalar variable. To make a vector-valued variable, a ``shape`` argument should be provided; for example, a 3x3 matrix of beta random variables could be defined with:
1818

docs/source/PyMC3_and_Theano.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ happens if we define a PyMC3 model. Let's look at a simple example::
134134
data = true_mu + np.random.randn(50)
135135

136136
with pm.Model() as model:
137-
mu = pm.Normal('mu', mu=0, sd=1)
138-
y = pm.Normal('y', mu=mu, sd=1, observed=data)
137+
mu = pm.Normal('mu', mu=0, sigma=1)
138+
y = pm.Normal('y', mu=mu, sigma=1, observed=data)
139139

140140
In this model we define two variables: `mu` and `y`. The first is
141141
a free variable that we want to infer, the second is an observed
@@ -184,7 +184,7 @@ example::
184184
with pm.Model() as model:
185185
mu = pm.Normal('mu', 0, 1)
186186
sd = pm.HalfNormal('sd', 1)
187-
y = pm.Normal('y', mu=mu, sd=sd, observed=data)
187+
y = pm.Normal('y', mu=mu, sigma=sd, observed=data)
188188

189189
is roughly equivalent to this::
190190

@@ -213,4 +213,4 @@ theano operation on them::
213213
beta = pm.Normal('beta', 0, 1, shape=len(design_matrix))
214214
predict = tt.dot(design_matrix, beta)
215215
sd = pm.HalfCauchy('sd', beta=2.5)
216-
pm.Normal('y', mu=predict, sd=sd, observed=data)
216+
pm.Normal('y', mu=predict, sigma=sd, observed=data)

docs/source/api/bounds.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,27 @@ specification of a bounded distribution should go within the model block::
3939

4040
with pm.Model() as model:
4141
BoundedNormal = pm.Bound(pm.Normal, lower=0.0)
42-
x = BoundedNormal('x', mu=1.0, sd=3.0)
42+
x = BoundedNormal('x', mu=1.0, sigma=3.0)
4343

4444
If the bound will be applied to a single variable in the model, it may be
4545
cleaner notationally to define both the bound and variable together. ::
4646

4747
with model:
48-
x = pm.Bound(pm.Normal, lower=0.0)('x', mu=1.0, sd=3.0)
48+
x = pm.Bound(pm.Normal, lower=0.0)('x', mu=1.0, sigma=3.0)
4949

5050
However, it is possible to create multiple different random variables
5151
that have the same bound applied to them::
5252

5353
with model:
5454
BoundNormal = pm.Bound(pm.Normal, lower=0.0)
55-
hyper_mu = BoundNormal("hyper_mu", mu=1, sd=0.5)
56-
mu = BoundNormal("mu", mu=hyper_mu, sd=1)
55+
hyper_mu = BoundNormal("hyper_mu", mu=1, sigma=0.5)
56+
mu = BoundNormal("mu", mu=hyper_mu, sigma=1)
5757

5858
Bounds can also be applied to a vector of random variables. With the same
5959
``BoundedNormal`` object we created previously we can write::
6060

6161
with model:
62-
x_vector = BoundedNormal('x_vector', mu=1.0, sd=3.0, shape=3)
62+
x_vector = BoundedNormal('x_vector', mu=1.0, sigma=3.0, shape=3)
6363

6464
Caveats
6565
#######

docs/source/developer_guide.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ explicit about the conversion. For example:
147147
.. code:: python
148148
149149
with pm.Model() as model:
150-
z = pm.Normal('z', mu=0., sd=5.) # ==> pymc3.model.FreeRV, or theano.tensor with logp
151-
x = pm.Normal('x', mu=z, sd=1., observed=5.) # ==> pymc3.model.ObservedRV, also has logp properties
150+
z = pm.Normal('z', mu=0., sigma=5.) # ==> pymc3.model.FreeRV, or theano.tensor with logp
151+
x = pm.Normal('x', mu=z, sigma=1., observed=5.) # ==> pymc3.model.ObservedRV, also has logp properties
152152
x.logp({'z': 2.5}) # ==> -4.0439386
153153
model.logp({'z': 2.5}) # ==> -6.6973152
154154
@@ -308,7 +308,7 @@ a model:
308308
.. code:: python
309309
310310
with pm.Model() as m:
311-
x = pm.Normal('x', mu=0., sd=1.)
311+
x = pm.Normal('x', mu=0., sigma=1.)
312312
313313
314314
Which is the same as doing:
@@ -317,7 +317,7 @@ Which is the same as doing:
317317
.. code:: python
318318
319319
m = pm.Model()
320-
x = m.Var('x', pm.Normal.dist(mu=0., sd=1.))
320+
x = m.Var('x', pm.Normal.dist(mu=0., sigma=1.))
321321
322322
323323
Both with the same output:
@@ -457,7 +457,7 @@ transformation <https://docs.pymc.io/notebooks/api_quickstart.html?highlight=cha
457457
458458
.. code:: python
459459
460-
z = pm.Lognormal.dist(mu=0., sd=1., transform=tr.Log)
460+
z = pm.Lognormal.dist(mu=0., sigma=1., transform=tr.Log)
461461
z.transform # ==> pymc3.distributions.transforms.Log
462462
463463
@@ -1051,14 +1051,14 @@ we get error (even worse, wrong answer with silent error):
10511051
with pm.Model() as m:
10521052
mu = pm.Normal('mu', 0., 1., shape=(5, 1))
10531053
sd = pm.HalfNormal('sd', 5., shape=(1, 10))
1054-
pm.Normal('x', mu=mu, sd=sd, observed=np.random.randn(2, 5, 10))
1054+
pm.Normal('x', mu=mu, sigma=sd, observed=np.random.randn(2, 5, 10))
10551055
trace = pm.sample_prior_predictive(100)
10561056
10571057
trace['x'].shape # ==> should be (100, 2, 5, 10), but get (100, 5, 10)
10581058
10591059
.. code:: python
10601060
1061-
pm.Normal.dist(mu=np.zeros(2), sd=1).random(size=(10, 4)) # ==> ERROR
1061+
pm.Normal.dist(mu=np.zeros(2), sigma=1).random(size=(10, 4)) # ==> ERROR
10621062
10631063
There are also other error related random sample generation (e.g.,
10641064
`Mixture is currently

docs/source/history.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ Models are defined using a context manager (``with`` statement). The model is sp
109109
with Model() as bioassay_model:
110110

111111
# Prior distributions for latent variables
112-
alpha = Normal('alpha', 0, sd=100)
113-
beta = Normal('beta', 0, sd=100)
112+
alpha = Normal('alpha', 0, sigma=100)
113+
beta = Normal('beta', 0, sigma=100)
114114

115115
# Linear combinations of parameters
116116
theta = invlogit(alpha + beta*dose)

docs/source/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
2424
X, y = linear_training_data()
2525
with pm.Model() as linear_model:
26-
weights = pm.Normal('weights', mu=0, sd=1)
26+
weights = pm.Normal('weights', mu=0, sigma=1)
2727
noise = pm.Gamma('noise', alpha=2, beta=1)
2828
y_observed = pm.Normal('y_observed',
2929
mu=X.dot(weights),
30-
sd=noise,
30+
sigma=noise,
3131
observed=y)
3232
3333
prior = pm.sample_prior_predictive()

docs/source/notebooks/AR.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@
177177
"source": [
178178
"tau = 1.0\n",
179179
"with pm.Model() as ar1:\n",
180-
" beta = pm.Normal('beta', mu=0, sd=tau)\n",
181-
" data = pm.AR('y', beta, sd=1.0, observed=y)\n",
180+
" beta = pm.Normal('beta', mu=0, sigma=tau)\n",
181+
" data = pm.AR('y', beta, sigma=1.0, observed=y)\n",
182182
" trace = pm.sample(1000, cores=4)\n",
183183
" \n",
184184
"pm.traceplot(trace);"
@@ -303,8 +303,8 @@
303303
],
304304
"source": [
305305
"with pm.Model() as ar2:\n",
306-
" beta = pm.Normal('beta', mu=0, sd=tau, shape=2)\n",
307-
" data = pm.AR('y', beta, sd=1.0, observed=y)\n",
306+
" beta = pm.Normal('beta', mu=0, sigma=tau, shape=2)\n",
307+
" data = pm.AR('y', beta, sigma=1.0, observed=y)\n",
308308
" trace = pm.sample(1000, cores=4)\n",
309309
" \n",
310310
"pm.traceplot(trace);"
@@ -362,9 +362,9 @@
362362
],
363363
"source": [
364364
"with pm.Model() as ar2:\n",
365-
" beta = pm.Normal('beta', mu=0, sd=tau)\n",
365+
" beta = pm.Normal('beta', mu=0, sigma=tau)\n",
366366
" beta2 = pm.Uniform('beta2')\n",
367-
" data = pm.AR('y', [beta, beta2], sd=1.0, observed=y)\n",
367+
" data = pm.AR('y', [beta, beta2], sigma=1.0, observed=y)\n",
368368
" trace = pm.sample(1000, tune=1000, cores=4)\n",
369369
"\n",
370370
"pm.traceplot(trace);"

docs/source/notebooks/BEST.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@
128128
"μ_s = y.value.std() * 2\n",
129129
"\n",
130130
"with pm.Model() as model:\n",
131-
" group1_mean = pm.Normal('group1_mean', μ_m, sd=μ_s)\n",
132-
" group2_mean = pm.Normal('group2_mean', μ_m, sd=μ_s)"
131+
" group1_mean = pm.Normal('group1_mean', μ_m, sigma=μ_s)\n",
132+
" group2_mean = pm.Normal('group2_mean', μ_m, sigma=μ_s)"
133133
]
134134
},
135135
{

docs/source/notebooks/Diagnosing_biased_Inference_with_Divergences.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,10 @@
147147
"outputs": [],
148148
"source": [
149149
"with pm.Model() as Centered_eight:\n",
150-
" mu = pm.Normal('mu', mu=0, sd=5)\n",
150+
" mu = pm.Normal('mu', mu=0, sigma=5)\n",
151151
" tau = pm.HalfCauchy('tau', beta=5)\n",
152-
" theta = pm.Normal('theta', mu=mu, sd=tau, shape=J)\n",
153-
" obs = pm.Normal('obs', mu=theta, sd=sigma, observed=y)"
152+
" theta = pm.Normal('theta', mu=mu, sigma=tau, shape=J)\n",
153+
" obs = pm.Normal('obs', mu=theta, sigma=sigma, observed=y)"
154154
]
155155
},
156156
{
@@ -1321,11 +1321,11 @@
13211321
"outputs": [],
13221322
"source": [
13231323
"with pm.Model() as NonCentered_eight:\n",
1324-
" mu = pm.Normal('mu', mu=0, sd=5)\n",
1324+
" mu = pm.Normal('mu', mu=0, sigma=5)\n",
13251325
" tau = pm.HalfCauchy('tau', beta=5)\n",
1326-
" theta_tilde = pm.Normal('theta_t', mu=0, sd=1, shape=J)\n",
1326+
" theta_tilde = pm.Normal('theta_t', mu=0, sigma=1, shape=J)\n",
13271327
" theta = pm.Deterministic('theta', mu + tau * theta_tilde)\n",
1328-
" obs = pm.Normal('obs', mu=theta, sd=sigma, observed=y)"
1328+
" obs = pm.Normal('obs', mu=theta, sigma=sigma, observed=y)"
13291329
]
13301330
},
13311331
{

docs/source/notebooks/Euler-Maruyama_and_SDEs.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@
249249
" xh = EulerMaruyama('xh', dt, lin_sde, (lam, ), shape=N, testval=x_t)\n",
250250
" \n",
251251
" # predicted observation\n",
252-
" zh = pm.Normal('zh', mu=xh, sd=5e-3, observed=z_t)"
252+
" zh = pm.Normal('zh', mu=xh, sigma=5e-3, observed=z_t)"
253253
]
254254
},
255255
{
@@ -629,7 +629,7 @@
629629
" ah = pm.Uniform('ah', lower=0.5, upper=1.5)\n",
630630
" mh = pm.Uniform('mh', lower=0.0, upper=1.0)\n",
631631
" xyh = EulerMaruyama('xyh', dt, osc_sde, (τh, ah), shape=xys.shape, testval=xys)\n",
632-
" zh = pm.Normal('zh', mu=mh * xyh[:, 0] + (1 - mh) * xyh[:, 1], sd=0.1, observed=zs)"
632+
" zh = pm.Normal('zh', mu=mh * xyh[:, 0] + (1 - mh) * xyh[:, 1], sigma=0.1, observed=zs)"
633633
]
634634
},
635635
{

docs/source/notebooks/GLM-hierarchical-advi-minibatch.ipynb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@
7070
"source": [
7171
"with pm.Model() as hierarchical_model:\n",
7272
" # Hyperpriors for group nodes\n",
73-
" mu_a = pm.Normal('mu_alpha', mu=0., sd=100**2)\n",
73+
" mu_a = pm.Normal('mu_alpha', mu=0., sigma=100**2)\n",
7474
" sigma_a = pm.Uniform('sigma_alpha', lower=0, upper=100)\n",
75-
" mu_b = pm.Normal('mu_beta', mu=0., sd=100**2)\n",
75+
" mu_b = pm.Normal('mu_beta', mu=0., sigma=100**2)\n",
7676
" sigma_b = pm.Uniform('sigma_beta', lower=0, upper=100)"
7777
]
7878
},
@@ -93,9 +93,9 @@
9393
"source": [
9494
"with hierarchical_model:\n",
9595
" \n",
96-
" a = pm.Normal('alpha', mu=mu_a, sd=sigma_a, shape=n_counties)\n",
96+
" a = pm.Normal('alpha', mu=mu_a, sigma=sigma_a, shape=n_counties)\n",
9797
" # Intercept for each county, distributed around group mean mu_a\n",
98-
" b = pm.Normal('beta', mu=mu_b, sd=sigma_b, shape=n_counties)"
98+
" b = pm.Normal('beta', mu=mu_b, sigma=sigma_b, shape=n_counties)"
9999
]
100100
},
101101
{
@@ -139,7 +139,7 @@
139139
" eps = pm.Uniform('eps', lower=0, upper=100) \n",
140140
" \n",
141141
" # Data likelihood\n",
142-
" radon_like = pm.Normal('radon_like', mu=radon_est, sd=eps, observed=log_radon_t, total_size=len(data))"
142+
" radon_like = pm.Normal('radon_like', mu=radon_est, sigma=eps, observed=log_radon_t, total_size=len(data))"
143143
]
144144
},
145145
{
@@ -238,21 +238,21 @@
238238
"# Inference button (TM)!\n",
239239
"with pm.Model():\n",
240240
"\n",
241-
" mu_a = pm.Normal('mu_alpha', mu=0., sd=100**2)\n",
241+
" mu_a = pm.Normal('mu_alpha', mu=0., sigma=100**2)\n",
242242
" sigma_a = pm.Uniform('sigma_alpha', lower=0, upper=100)\n",
243-
" mu_b = pm.Normal('mu_beta', mu=0., sd=100**2)\n",
243+
" mu_b = pm.Normal('mu_beta', mu=0., sigma=100**2)\n",
244244
" sigma_b = pm.Uniform('sigma_beta', lower=0, upper=100)\n",
245245
" \n",
246-
" a = pm.Normal('alpha', mu=mu_a, sd=sigma_a, shape=n_counties)\n",
247-
" b = pm.Normal('beta', mu=mu_b, sd=sigma_b, shape=n_counties)\n",
246+
" a = pm.Normal('alpha', mu=mu_a, sigma=sigma_a, shape=n_counties)\n",
247+
" b = pm.Normal('beta', mu=mu_b, sigma=sigma_b, shape=n_counties)\n",
248248
" \n",
249249
" # Model error\n",
250250
" eps = pm.Uniform('eps', lower=0, upper=100)\n",
251251
" \n",
252252
" radon_est = a[county_idx] + b[county_idx] * data.floor.values\n",
253253
" \n",
254254
" radon_like = pm.Normal(\n",
255-
" 'radon_like', mu=radon_est, sd=eps, observed=data.log_radon.values)\n",
255+
" 'radon_like', mu=radon_est, sigma=eps, observed=data.log_radon.values)\n",
256256
" \n",
257257
" step = pm.NUTS(scaling=approx.cov.eval(), is_cov=True)\n",
258258
" hierarchical_trace = pm.sample(2000, step, start=approx.sample()[0], progressbar=True)"

docs/source/notebooks/GLM-hierarchical.ipynb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@
220220
"with pm.Model() as unpooled_model:\n",
221221
" \n",
222222
" # Independent parameters for each county\n",
223-
" a = pm.Normal('a', 0, sd=100, shape=n_counties)\n",
224-
" b = pm.Normal('b', 0, sd=100, shape=n_counties)\n",
223+
" a = pm.Normal('a', 0, sigma=100, shape=n_counties)\n",
224+
" b = pm.Normal('b', 0, sigma=100, shape=n_counties)\n",
225225
" \n",
226226
" # Model error\n",
227227
" eps = pm.HalfCauchy('eps', 5)\n",
@@ -233,7 +233,7 @@
233233
" radon_est = a[county_idx] + b[county_idx]*data.floor.values\n",
234234
" \n",
235235
" # Data likelihood\n",
236-
" y = pm.Normal('y', radon_est, sd=eps, observed=data.log_radon)\n",
236+
" y = pm.Normal('y', radon_est, sigma=eps, observed=data.log_radon)\n",
237237
" "
238238
]
239239
},
@@ -283,26 +283,26 @@
283283
"source": [
284284
"with pm.Model() as hierarchical_model:\n",
285285
" # Hyperpriors for group nodes\n",
286-
" mu_a = pm.Normal('mu_a', mu=0., sd=100**2)\n",
286+
" mu_a = pm.Normal('mu_a', mu=0., sigma=100**2)\n",
287287
" sigma_a = pm.HalfCauchy('sigma_a', 5)\n",
288-
" mu_b = pm.Normal('mu_b', mu=0., sd=100**2)\n",
288+
" mu_b = pm.Normal('mu_b', mu=0., sigma=100**2)\n",
289289
" sigma_b = pm.HalfCauchy('sigma_b', 5)\n",
290290
" \n",
291291
" # Intercept for each county, distributed around group mean mu_a\n",
292292
" # Above we just set mu and sd to a fixed value while here we\n",
293293
" # plug in a common group distribution for all a and b (which are\n",
294294
" # vectors of length n_counties).\n",
295-
" a = pm.Normal('a', mu=mu_a, sd=sigma_a, shape=n_counties)\n",
295+
" a = pm.Normal('a', mu=mu_a, sigma=sigma_a, shape=n_counties)\n",
296296
" # Intercept for each county, distributed around group mean mu_a\n",
297-
" b = pm.Normal('b', mu=mu_b, sd=sigma_b, shape=n_counties)\n",
297+
" b = pm.Normal('b', mu=mu_b, sigma=sigma_b, shape=n_counties)\n",
298298
" \n",
299299
" # Model error\n",
300300
" eps = pm.HalfCauchy('eps', 5)\n",
301301
" \n",
302302
" radon_est = a[county_idx] + b[county_idx] * data.floor.values\n",
303303
" \n",
304304
" # Data likelihood\n",
305-
" radon_like = pm.Normal('radon_like', mu=radon_est, sd=eps, observed=data.log_radon)"
305+
" radon_like = pm.Normal('radon_like', mu=radon_est, sigma=eps, observed=data.log_radon)"
306306
]
307307
},
308308
{

0 commit comments

Comments
 (0)