@@ -74,19 +74,19 @@ def autocorr(x, lag=1):
74
74
def autocov (x , lag = 1 ):
75
75
"""Sample autocovariance at specified lag.
76
76
77
- Parameters
78
- ----------
79
- x : Numpy array
80
- An array containing MCMC samples
81
- lag : int
82
- The desidered lag to take in consideration
83
-
84
- Returns
85
- -------
86
- 2x2 matrix with the variances of
87
- x[:-lag] and x[lag:] in the diagonal and the autocovariance
88
- on the off-diagonal.
89
- """
77
+ Parameters
78
+ ----------
79
+ x : Numpy array
80
+ An array containing MCMC samples
81
+ lag : int
82
+ The desidered lag to take in consideration
83
+
84
+ Returns
85
+ -------
86
+ 2x2 matrix with the variances of
87
+ x[:-lag] and x[lag:] in the diagonal and the autocovariance
88
+ on the off-diagonal.
89
+ """
90
90
x = np .asarray (x )
91
91
92
92
if not lag :
@@ -97,8 +97,7 @@ def autocov(x, lag=1):
97
97
98
98
99
99
def dic (trace , model = None ):
100
- """
101
- Calculate the deviance information criterion of the samples in trace from model
100
+ """Calculate the deviance information criterion of the samples in trace from model
102
101
Read more theory here - in a paper by some of the leading authorities on Model Selection -
103
102
dx.doi.org/10.1111/1467-9868.00353
104
103
@@ -124,8 +123,7 @@ def dic(trace, model=None):
124
123
125
124
126
125
def log_post_trace (trace , model ):
127
- """
128
- Calculate the elementwise log-posterior for the sampled trace.
126
+ """Calculate the elementwise log-posterior for the sampled trace.
129
127
130
128
Parameters
131
129
----------
@@ -137,13 +135,11 @@ def log_post_trace(trace, model):
137
135
138
136
139
137
def waic (trace , model = None , pointwise = False ):
140
- """
141
- Calculate the widely available information criterion, its standard error
138
+ """Calculate the widely available information criterion, its standard error
142
139
and the effective number of parameters of the samples in trace from model.
143
140
Read more theory here - in a paper by some of the leading authorities on
144
141
Model Selection - dx.doi.org/10.1111/1467-9868.00353
145
142
146
-
147
143
Parameters
148
144
----------
149
145
trace : result of MCMC run
@@ -153,7 +149,6 @@ def waic(trace, model=None, pointwise=False):
153
149
if True the pointwise predictive accuracy will be returned.
154
150
Default False
155
151
156
-
157
152
Returns
158
153
-------
159
154
namedtuple with the following elements:
@@ -191,12 +186,10 @@ def waic(trace, model=None, pointwise=False):
191
186
192
187
193
188
def loo (trace , model = None , pointwise = False ):
194
- """
195
- Calculates leave-one-out (LOO) cross-validation for out of sample predictive
189
+ """Calculates leave-one-out (LOO) cross-validation for out of sample predictive
196
190
model fit, following Vehtari et al. (2015). Cross-validation is computed using
197
191
Pareto-smoothed importance sampling (PSIS).
198
192
199
-
200
193
Parameters
201
194
----------
202
195
trace : result of MCMC run
@@ -206,7 +199,6 @@ def loo(trace, model=None, pointwise=False):
206
199
if True the pointwise predictive accuracy will be returned.
207
200
Default False
208
201
209
-
210
202
Returns
211
203
-------
212
204
namedtuple with the following elements:
@@ -215,7 +207,6 @@ def loo(trace, model=None, pointwise=False):
215
207
p_loo: effective number of parameters
216
208
loo_i: and array of the pointwise predictive accuracy, only if pointwise True
217
209
"""
218
-
219
210
model = modelcontext (model )
220
211
221
212
log_py = log_post_trace (trace , model )
@@ -301,8 +292,7 @@ def bpic(trace, model=None):
301
292
302
293
303
294
def compare (traces , models , ic = 'WAIC' ):
304
- """
305
- Compare models based on the widely available information criterion (WAIC)
295
+ """Compare models based on the widely available information criterion (WAIC)
306
296
or leave-one-out (LOO) cross-validation.
307
297
Read more theory here - in a paper by some of the leading authorities on
308
298
Model Selection - dx.doi.org/10.1111/1467-9868.00353
@@ -419,7 +409,6 @@ def calc_min_interval(x, alpha):
419
409
420
410
Assumes that x is sorted numpy array.
421
411
"""
422
-
423
412
n = len (x )
424
413
cred_mass = 1.0 - alpha
425
414
@@ -450,7 +439,6 @@ def hpd(x, alpha=0.05, transform=lambda x: x):
450
439
Function to transform data (defaults to identity)
451
440
452
441
"""
453
-
454
442
# Make a copy of trace
455
443
x = transform (x .copy ())
456
444
@@ -609,17 +597,14 @@ def df_summary(trace, varnames=None, stat_funcs=None, extend=False, include_tran
609
597
samples. Defaults to the smaller of 100 or the number of samples.
610
598
This is only meaningful when `stat_funcs` is None.
611
599
612
-
613
600
See also
614
601
--------
615
602
summary : Generate a pretty-printed summary of a trace.
616
603
617
-
618
604
Returns
619
605
-------
620
606
`pandas.DataFrame` with summary statistics for each variable
621
607
622
-
623
608
Examples
624
609
--------
625
610
.. code:: ipython
@@ -714,7 +699,6 @@ def summary(trace, varnames=None, transform=lambda x: x, alpha=0.05, start=0,
714
699
original variables (defaults to False).
715
700
to_file : None or string
716
701
File to write results to. If not given, print to stdout.
717
-
718
702
"""
719
703
if varnames is None :
720
704
if include_transformed :
0 commit comments