11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
+ import warnings
15
+
14
16
import aesara
15
17
import numpy as np
16
18
import pytest
@@ -125,7 +127,7 @@ def check_rv_inferred_size(self):
125
127
126
128
def test_steps_scalar_check (self ):
127
129
with pytest .raises (ValueError , match = "steps must be an integer scalar" ):
128
- self .pymc_dist .dist (steps = [1 ])
130
+ self .pymc_dist .dist (steps = [1 ], init_dist = pm . DiracDelta . dist ( 0 ) )
129
131
130
132
def test_gaussianrandomwalk_inference (self ):
131
133
mu , sigma , steps = 2 , 1 , 1000
@@ -136,7 +138,9 @@ def test_gaussianrandomwalk_inference(self):
136
138
_sigma = pm .Uniform ("sigma" , 0 , 10 )
137
139
138
140
obs_data = pm .MutableData ("obs_data" , obs )
139
- grw = GaussianRandomWalk ("grw" , _mu , _sigma , steps = steps , observed = obs_data )
141
+ grw = GaussianRandomWalk (
142
+ "grw" , _mu , _sigma , steps = steps , observed = obs_data , init_dist = Normal .dist (0 , 100 )
143
+ )
140
144
141
145
trace = pm .sample (chains = 1 )
142
146
@@ -147,26 +151,30 @@ def test_gaussianrandomwalk_inference(self):
147
151
@pytest .mark .parametrize ("init" , [None , pm .Normal .dist ()])
148
152
def test_gaussian_random_walk_init_dist_shape (self , init ):
149
153
"""Test that init_dist is properly resized"""
150
- grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init )
151
- assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == ()
154
+ with warnings .catch_warnings ():
155
+ warnings .filterwarnings ("ignore" , "Initial distribution not specified.*" , UserWarning )
156
+ grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init )
157
+ assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == ()
152
158
153
- grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init , size = (5 ,))
154
- assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (5 ,)
159
+ grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init , size = (5 ,))
160
+ assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (5 ,)
155
161
156
- grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init , shape = 2 )
157
- assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == ()
162
+ grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init , shape = 2 )
163
+ assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == ()
158
164
159
- grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init , shape = (5 , 2 ))
160
- assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (5 ,)
165
+ grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = 1 , steps = 1 , init_dist = init , shape = (5 , 2 ))
166
+ assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (5 ,)
161
167
162
- grw = pm .GaussianRandomWalk .dist (mu = [0 , 0 ], sigma = 1 , steps = 1 , init_dist = init )
163
- assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (2 ,)
168
+ grw = pm .GaussianRandomWalk .dist (mu = [0 , 0 ], sigma = 1 , steps = 1 , init_dist = init )
169
+ assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (2 ,)
164
170
165
- grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = [1 , 1 ], steps = 1 , init_dist = init )
166
- assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (2 ,)
171
+ grw = pm .GaussianRandomWalk .dist (mu = 0 , sigma = [1 , 1 ], steps = 1 , init_dist = init )
172
+ assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (2 ,)
167
173
168
- grw = pm .GaussianRandomWalk .dist (mu = np .zeros ((3 , 1 )), sigma = [1 , 1 ], steps = 1 , init_dist = init )
169
- assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (3 , 2 )
174
+ grw = pm .GaussianRandomWalk .dist (
175
+ mu = np .zeros ((3 , 1 )), sigma = [1 , 1 ], steps = 1 , init_dist = init
176
+ )
177
+ assert tuple (grw .owner .inputs [- 2 ].shape .eval ()) == (3 , 2 )
170
178
171
179
def test_shape_ellipsis (self ):
172
180
grw = pm .GaussianRandomWalk .dist (
@@ -184,28 +192,28 @@ def test_gaussianrandomwalk_broadcasted_by_init_dist(self):
184
192
185
193
@pytest .mark .parametrize ("shape" , ((6 ,), (3 , 6 )))
186
194
def test_inferred_steps_from_shape (self , shape ):
187
- x = GaussianRandomWalk .dist (shape = shape )
195
+ x = GaussianRandomWalk .dist (shape = shape , init_dist = Normal . dist ( 0 , 100 ) )
188
196
steps = x .owner .inputs [- 1 ]
189
197
assert steps .eval () == 5
190
198
191
199
@pytest .mark .parametrize ("shape" , (None , (5 , ...)))
192
200
def test_missing_steps (self , shape ):
193
201
with pytest .raises (ValueError , match = "Must specify steps or shape parameter" ):
194
- GaussianRandomWalk .dist (shape = shape )
202
+ GaussianRandomWalk .dist (shape = shape , init_dist = Normal . dist ( 0 , 100 ) )
195
203
196
204
def test_inconsistent_steps_and_shape (self ):
197
205
with pytest .raises (AssertionError , match = "Steps do not match last shape dimension" ):
198
- x = GaussianRandomWalk .dist (steps = 12 , shape = 45 )
206
+ x = GaussianRandomWalk .dist (steps = 12 , shape = 45 , init_dist = Normal . dist ( 0 , 100 ) )
199
207
200
208
def test_inferred_steps_from_dims (self ):
201
209
with pm .Model (coords = {"batch" : range (5 ), "steps" : range (20 )}):
202
- x = GaussianRandomWalk ("x" , dims = ("batch" , "steps" ))
210
+ x = GaussianRandomWalk ("x" , dims = ("batch" , "steps" ), init_dist = Normal . dist ( 0 , 100 ) )
203
211
steps = x .owner .inputs [- 1 ]
204
212
assert steps .eval () == 19
205
213
206
214
def test_inferred_steps_from_observed (self ):
207
215
with pm .Model ():
208
- x = GaussianRandomWalk ("x" , observed = np .zeros (10 ))
216
+ x = GaussianRandomWalk ("x" , observed = np .zeros (10 ), init_dist = Normal . dist ( 0 , 100 ) )
209
217
steps = x .owner .inputs [- 1 ]
210
218
assert steps .eval () == 9
211
219
0 commit comments