@@ -93,7 +93,9 @@ class Metropolis(ArrayStepShared):
93
93
generates_stats = True
94
94
stats_dtypes = [{
95
95
'accept' : np .float64 ,
96
+ 'accepted' : np .bool ,
96
97
'tune' : np .bool ,
98
+ 'scaling' : np .float64 ,
97
99
}]
98
100
99
101
def __init__ (self , vars = None , S = None , proposal_dist = None , scaling = 1. ,
@@ -166,7 +168,9 @@ def astep(self, q0):
166
168
167
169
stats = {
168
170
'tune' : self .tune ,
171
+ 'scaling' : self .scaling ,
169
172
'accept' : np .exp (accept ),
173
+ 'accepted' : accepted ,
170
174
}
171
175
172
176
return q_new , [stats ]
@@ -191,26 +195,24 @@ def tune(scale, acc_rate):
191
195
>0.95 x 10
192
196
193
197
"""
194
-
195
- # Switch statement
196
198
if acc_rate < 0.001 :
197
199
# reduce by 90 percent
198
- scale *= 0.1
200
+ return scale * 0.1
199
201
elif acc_rate < 0.05 :
200
202
# reduce by 50 percent
201
- scale *= 0.5
203
+ return scale * 0.5
202
204
elif acc_rate < 0.2 :
203
205
# reduce by ten percent
204
- scale *= 0.9
206
+ return scale * 0.9
205
207
elif acc_rate > 0.95 :
206
208
# increase by factor of ten
207
- scale *= 10.0
209
+ return scale * 10.0
208
210
elif acc_rate > 0.75 :
209
211
# increase by double
210
- scale *= 2.0
212
+ return scale * 2.0
211
213
elif acc_rate > 0.5 :
212
214
# increase by ten percent
213
- scale *= 1.1
215
+ return scale * 1.1
214
216
215
217
return scale
216
218
@@ -531,7 +533,9 @@ class DEMetropolis(PopulationArrayStepShared):
531
533
generates_stats = True
532
534
stats_dtypes = [{
533
535
'accept' : np .float64 ,
536
+ 'accepted' : np .bool ,
534
537
'tune' : np .bool ,
538
+ 'scaling' : np .float64 ,
535
539
}]
536
540
537
541
def __init__ (self , vars = None , S = None , proposal_dist = None , lamb = None , scaling = 0.001 ,
@@ -544,7 +548,7 @@ def __init__(self, vars=None, S=None, proposal_dist=None, lamb=None, scaling=0.0
544
548
vars = pm .inputvars (vars )
545
549
546
550
if S is None :
547
- S = np .ones (sum ( v . dsize for v in vars ) )
551
+ S = np .ones (model . ndim )
548
552
549
553
if proposal_dist is not None :
550
554
self .proposal_dist = proposal_dist (S )
@@ -553,7 +557,7 @@ def __init__(self, vars=None, S=None, proposal_dist=None, lamb=None, scaling=0.0
553
557
554
558
self .scaling = np .atleast_1d (scaling ).astype ('d' )
555
559
if lamb is None :
556
- lamb = 2.38 / np .sqrt (2 * S . size )
560
+ lamb = 2.38 / np .sqrt (2 * model . ndim )
557
561
self .lamb = float (lamb )
558
562
self .tune = tune
559
563
self .tune_interval = tune_interval
@@ -593,7 +597,9 @@ def astep(self, q0):
593
597
594
598
stats = {
595
599
'tune' : self .tune ,
600
+ 'scaling' : self .scaling ,
596
601
'accept' : np .exp (accept ),
602
+ 'accepted' : accepted
597
603
}
598
604
599
605
return q_new , [stats ]
0 commit comments