5
5
- LinearRegression model
6
6
7
7
Models are intended to be used from inside an experiment
8
- class (see `pymc_experiments.py
8
+ class (see :py:mod:`pymc_experiments.py<.pymc_experiments.py>` old
9
+ link `pymc_experiments.py
9
10
<https://causalpy.readthedocs.io/en/latest/api_pymc_experiments.html>`_).
10
11
This is why the examples require some extra
11
12
manipulation input data, often to ensure `y` has the correct shape.
@@ -31,7 +32,7 @@ class ModelBuilder(pm.Model):
31
32
- build_model: must be implemented by subclasses
32
33
- fit: populates idata attribute
33
34
- predict: returns predictions on new data
34
- - score: returns Bayesian R^2
35
+ - score: returns Bayesian :math: ` R^2`
35
36
"""
36
37
37
38
def __init__ (self , sample_kwargs : Optional [Dict [str , Any ]] = None ):
@@ -208,10 +209,15 @@ class WeightedSumFitter(ModelBuilder):
208
209
209
210
Defines the PyMC model:
210
211
211
- - y ~ Normal(mu, sigma)
212
- - sigma ~ HalfNormal(1)
213
- - mu = X * beta
214
- - beta ~ Dirichlet(1,...,1)
212
+ .. math::
213
+
214
+ sigma \sim HalfNormal(1)
215
+
216
+ beta \sim Dirichlet(1,...,1)
217
+
218
+ mu = X * beta
219
+
220
+ y \sim Normal(mu, sigma)
215
221
216
222
Example
217
223
--------
@@ -224,18 +230,23 @@ class WeightedSumFitter(ModelBuilder):
224
230
>>> wsf = WeightedSumFitter(sample_kwargs={"progressbar": False})
225
231
>>> wsf.fit(X,y)
226
232
Inference ...
227
- """
233
+ """ # noqa: W605
228
234
229
235
def build_model (self , X , y , coords ):
230
236
"""
231
237
Defines the PyMC model:
232
238
233
- - y ~ Normal(mu, sigma)
234
- - sigma ~ HalfNormal(1)
235
- - mu = X * beta
236
- - beta ~ Dirichlet(1,...,1)
239
+ .. math::
237
240
238
- """
241
+ sigma \sim HalfNormal(1)
242
+
243
+ beta \sim Dirichlet(1,...,1)
244
+
245
+ mu = X * beta
246
+
247
+ y \sim Normal(mu, sigma)
248
+
249
+ """ # noqa: W605
239
250
with self :
240
251
self .add_coords (coords )
241
252
n_predictors = X .shape [1 ]
@@ -261,10 +272,14 @@ class LinearRegression(ModelBuilder):
261
272
262
273
Defines the PyMC model
263
274
264
- - y ~ Normal(mu, sigma)
265
- - mu = X * beta
266
- - beta ~ Normal(0, 50)
267
- - sigma ~ HalfNormal(1)
275
+ .. math::
276
+ beta \sim Normal(0, 50)
277
+
278
+ sigma \sim HalfNormal(1)
279
+
280
+ mu = X * beta
281
+
282
+ y \sim Normal(mu, sigma)
268
283
269
284
Example
270
285
--------
@@ -281,17 +296,22 @@ class LinearRegression(ModelBuilder):
281
296
... },
282
297
... )
283
298
Inference...
284
- """
299
+ """ # noqa: W605
285
300
286
301
def build_model (self , X , y , coords ):
287
302
"""
288
303
Defines the PyMC model
289
304
290
- - y ~ Normal(mu, sigma)
291
- - mu = X * beta
292
- - beta ~ Normal(0, 50)
293
- - sigma ~ HalfNormal(1)
294
- """
305
+ .. math::
306
+ beta \sim Normal(0, 50)
307
+
308
+ sigma \sim HalfNormal(1)
309
+
310
+ mu = X * beta
311
+
312
+ y \sim Normal(mu, sigma)
313
+
314
+ """ # noqa: W605
295
315
with self :
296
316
self .add_coords (coords )
297
317
X = pm .MutableData ("X" , X , dims = ["obs_ind" , "coeffs" ])
0 commit comments