@@ -11,8 +11,7 @@ whenever possible. If the same model is going to be used repeatedly, we would
11
11
like to compile it just once. The following demonstrates how to reuse a model in
12
12
different scripts and between interactive Python sessions.
13
13
14
- **Within sessions ** you can avoid recompiling a model in two ways. The first
15
- method is to reuse a fit object in the call to ``stan ``. For example,
14
+ **Within sessions ** you can avoid recompiling a model by reusing the `StanModel ` instance:
16
15
17
16
.. code-block :: python
18
17
@@ -34,32 +33,17 @@ method is to reuse a fit object in the call to ``stan``. For example,
34
33
}
35
34
"""
36
35
37
- data = dict (N = 10 , y = [0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 ])
38
-
39
- .. code-block :: python
40
-
41
- fit = stan(model_code = model_code, data = data)
42
- print (fit)
43
-
44
- new_data = dict (N = 6 , y = [0 , 0 , 0 , 0 , 0 , 1 ])
45
- fit2 = stan(fit = fit, data = new_data)
46
- print (fit2)
47
-
48
- However, calling ``pystan.stan `` is deprecated and will soon be removed from
49
- PyStan. The recommended method is to compile the model once using the
50
- ``StanModel `` class and then sample from the model using the ``sampling ``
51
- method.
52
36
53
37
.. code-block :: python
54
38
55
39
from pystan import StanModel
56
40
57
- # using the same model as before
58
41
data = dict (N = 10 , y = [0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 1 ])
59
42
sm = StanModel(model_code = model_code)
60
43
fit = sm.sampling(data = data)
61
44
print (fit)
62
45
46
+ # reuse model with new data
63
47
new_data = dict (N = 6 , y = [0 , 0 , 0 , 0 , 0 , 1 ])
64
48
fit2 = sm.sampling(data = new_data)
65
49
print (fit2)
@@ -107,7 +91,7 @@ Automatically reusing models
107
91
108
92
For those who miss using variables across sessions in R, it is not difficult to
109
93
write a function that automatically saves a copy of every model that gets
110
- compiled using `` stan `` and opportunistically loads a copy of a model if one is
94
+ compiled and opportunistically loads a copy of a model if one is
111
95
available.
112
96
113
97
.. code-block :: python
0 commit comments