@@ -230,34 +230,36 @@ class MvNormal(Continuous):
230230 Define a multivariate normal variable for a given covariance
231231 matrix::
232232
233- cov = np.array([[1., 0.5], [0.5, 2]])
233+ cov = np.array([[1.0 , 0.5], [0.5, 2]])
234234 mu = np.zeros(2)
235- vals = pm.MvNormal(' vals' , mu=mu, cov=cov, shape=(5, 2))
235+ vals = pm.MvNormal(" vals" , mu=mu, cov=cov, shape=(5, 2))
236236
237237 Most of the time it is preferable to specify the cholesky
238238 factor of the covariance instead. For example, we could
239239 fit a multivariate outcome like this (see the docstring
240240 of `LKJCholeskyCov` for more information about this)::
241241
242242 mu = np.zeros(3)
243- true_cov = np.array([[1.0, 0.5, 0.1],
244- [0.5, 2.0, 0.2],
245- [0.1, 0.2, 1.0]])
243+ true_cov = np.array(
244+ [
245+ [1.0, 0.5, 0.1],
246+ [0.5, 2.0, 0.2],
247+ [0.1, 0.2, 1.0],
248+ ],
249+ )
246250 data = np.random.multivariate_normal(mu, true_cov, 10)
247251
248252 sd_dist = pm.Exponential.dist(1.0, shape=3)
249- chol, corr, stds = pm.LKJCholeskyCov('chol_cov', n=3, eta=2,
250- sd_dist=sd_dist, compute_corr=True)
251- vals = pm.MvNormal('vals', mu=mu, chol=chol, observed=data)
253+ chol, corr, stds = pm.LKJCholeskyCov("chol_cov", n=3, eta=2, sd_dist=sd_dist, compute_corr=True)
254+ vals = pm.MvNormal("vals", mu=mu, chol=chol, observed=data)
252255
253256 For unobserved values it can be better to use a non-centered
254257 parametrization::
255258
256259 sd_dist = pm.Exponential.dist(1.0, shape=3)
257- chol, _, _ = pm.LKJCholeskyCov('chol_cov', n=3, eta=2,
258- sd_dist=sd_dist, compute_corr=True)
259- vals_raw = pm.Normal('vals_raw', mu=0, sigma=1, shape=(5, 3))
260- vals = pm.Deterministic('vals', pt.dot(chol, vals_raw.T).T)
260+ chol, _, _ = pm.LKJCholeskyCov("chol_cov", n=3, eta=2, sd_dist=sd_dist, compute_corr=True)
261+ vals_raw = pm.Normal("vals_raw", mu=0, sigma=1, shape=(5, 3))
262+ vals = pm.Deterministic("vals", pt.dot(chol, vals_raw.T).T)
261263 """
262264
263265 rv_op = multivariate_normal
@@ -1806,13 +1808,12 @@ class MatrixNormal(Continuous):
18061808 Define a matrixvariate normal variable for given row and column covariance
18071809 matrices::
18081810
1809- colcov = np.array([[1., 0.5], [0.5, 2]])
1811+ colcov = np.array([[1.0 , 0.5], [0.5, 2]])
18101812 rowcov = np.array([[1, 0, 0], [0, 4, 0], [0, 0, 16]])
18111813 m = rowcov.shape[0]
18121814 n = colcov.shape[0]
18131815 mu = np.zeros((m, n))
1814- vals = pm.MatrixNormal('vals', mu=mu, colcov=colcov,
1815- rowcov=rowcov)
1816+ vals = pm.MatrixNormal("vals", mu=mu, colcov=colcov, rowcov=rowcov)
18161817
18171818 Above, the ith row in vals has a variance that is scaled by 4^i.
18181819 Alternatively, row or column cholesky matrices could be substituted for
@@ -2418,23 +2419,25 @@ class ICAR(Continuous):
24182419 # 4x4 adjacency matrix
24192420 # arranged in a square lattice
24202421
2421- W = np.array([
2422- [0,1,0,1],
2423- [1,0,1,0],
2424- [0,1,0,1],
2425- [1,0,1,0]
2426- ])
2422+ W = np.array(
2423+ [
2424+ [0, 1, 0, 1],
2425+ [1, 0, 1, 0],
2426+ [0, 1, 0, 1],
2427+ [1, 0, 1, 0],
2428+ ],
2429+ )
24272430
24282431 # centered parameterization
24292432 with pm.Model():
2430- sigma = pm.Exponential(' sigma' , 1)
2431- phi = pm.ICAR(' phi' , W=W, sigma=sigma)
2433+ sigma = pm.Exponential(" sigma" , 1)
2434+ phi = pm.ICAR(" phi" , W=W, sigma=sigma)
24322435 mu = phi
24332436
24342437 # non-centered parameterization
24352438 with pm.Model():
2436- sigma = pm.Exponential(' sigma' , 1)
2437- phi = pm.ICAR(' phi' , W=W)
2439+ sigma = pm.Exponential(" sigma" , 1)
2440+ phi = pm.ICAR(" phi" , W=W)
24382441 mu = sigma * phi
24392442
24402443 References
0 commit comments