1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14+ import warnings
15+
1416import aesara
1517import numpy as np
1618import pytest
@@ -125,7 +127,7 @@ def check_rv_inferred_size(self):
125127
126128 def test_steps_scalar_check (self ):
127129 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 ) )
129131
130132 def test_gaussianrandomwalk_inference (self ):
131133 mu , sigma , steps = 2 , 1 , 1000
@@ -136,7 +138,9 @@ def test_gaussianrandomwalk_inference(self):
136138 _sigma = pm .Uniform ("sigma" , 0 , 10 )
137139
138140 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+ )
140144
141145 trace = pm .sample (chains = 1 )
142146
@@ -147,26 +151,30 @@ def test_gaussianrandomwalk_inference(self):
147151 @pytest .mark .parametrize ("init" , [None , pm .Normal .dist ()])
148152 def test_gaussian_random_walk_init_dist_shape (self , init ):
149153 """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 ()) == ()
152158
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 ,)
155161
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 ()) == ()
158164
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 ,)
161167
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 ,)
164170
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 ,)
167173
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 )
170178
171179 def test_shape_ellipsis (self ):
172180 grw = pm .GaussianRandomWalk .dist (
@@ -184,28 +192,28 @@ def test_gaussianrandomwalk_broadcasted_by_init_dist(self):
184192
185193 @pytest .mark .parametrize ("shape" , ((6 ,), (3 , 6 )))
186194 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 ) )
188196 steps = x .owner .inputs [- 1 ]
189197 assert steps .eval () == 5
190198
191199 @pytest .mark .parametrize ("shape" , (None , (5 , ...)))
192200 def test_missing_steps (self , shape ):
193201 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 ) )
195203
196204 def test_inconsistent_steps_and_shape (self ):
197205 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 ) )
199207
200208 def test_inferred_steps_from_dims (self ):
201209 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 ) )
203211 steps = x .owner .inputs [- 1 ]
204212 assert steps .eval () == 19
205213
206214 def test_inferred_steps_from_observed (self ):
207215 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 ) )
209217 steps = x .owner .inputs [- 1 ]
210218 assert steps .eval () == 9
211219
0 commit comments