@@ -56,7 +56,10 @@ def rng_fn(
56
56
init : float ,
57
57
size : int ,
58
58
) -> np .ndarray :
59
- """Gaussian Random Walk randon function
59
+ """Gaussian Random Walk generator.
60
+
61
+ The init value is drawn from the Normal distribution with the same sigma as the
62
+ innovations.
60
63
61
64
Parameters
62
65
----------
@@ -79,7 +82,7 @@ def rng_fn(
79
82
-------
80
83
np.ndarray
81
84
"""
82
- return init + np .cumsum (rng .normal (loc = mu , scale = sigma , size = size ))
85
+ return np .cumsum ([ rng .normal (init , sigma ), rng . normal ( loc = mu , scale = sigma , size = size )] )
83
86
84
87
85
88
gaussianrandomwalk = GaussianRandomWalkRV ()
@@ -231,55 +234,34 @@ def logp(self, value):
231
234
class GaussianRandomWalk (distribution .Continuous ):
232
235
r"""Random Walk with Normal innovations
233
236
234
- Note that this is mainly a user-friendly wrapper to enable an easier specification
235
- of GRW. You are not restricted to use only Normal innovations but can use any
236
- distribution: just use `aesara.tensor.cumsum()` to create the random walk behavior.
237
+
238
+ Note init is currently drawn from a normal distribution with the same sigma as the innovations
237
239
238
240
Parameters
239
241
----------
240
242
mu: tensor
241
243
innovation drift, defaults to 0.0
242
- For vector valued mu, first dimension must match shape of the random walk, and
243
- the first element will be discarded (since there is no innovation in the first timestep)
244
244
sigma: tensor
245
- sigma > 0, innovation standard deviation (only required if tau is not specified)
246
- For vector valued sigma, first dimension must match shape of the random walk, and
247
- the first element will be discarded (since there is no innovation in the first timestep)
248
- tau: tensor
249
- tau > 0, innovation precision (only required if sigma is not specified)
250
- For vector valued tau, first dimension must match shape of the random walk, and
251
- the first element will be discarded (since there is no innovation in the first timestep)
252
- init: distribution
253
- distribution for initial value (Defaults to Flat())
245
+ sigma > 0, innovation standard deviation, defaults to 0.0
246
+ init: float
247
+ Mean value of initialization, defaults to 0.0
254
248
"""
255
249
256
250
rv_op = gaussianrandomwalk
257
251
258
252
@classmethod
259
253
def dist (
260
254
cls ,
261
- mu : Optional [Union [np .ndarray , float ]] = None ,
262
- sigma : Optional [Union [np .ndarray , float ]] = None ,
263
- init : float = None ,
255
+ mu : Optional [Union [np .ndarray , float ]] = 0.0 ,
256
+ sigma : Optional [Union [np .ndarray , float ]] = 1.0 ,
257
+ init : float = 0.0 ,
264
258
size : int = None ,
265
259
* args ,
266
260
** kwargs
267
261
) -> RandomVariable :
268
262
269
- # Still working on this. The RV op is my current blocker
270
263
return super ().dist ([mu , sigma , init ], ** kwargs )
271
264
272
- # TODO: Add typehints
273
- # def get_moment(
274
- # self,
275
- # size: Optional[Union[np.ndarray, float]],
276
- # mu: Optional[Union[np.ndarray, float]],
277
- # sigma: Optional[Union[np.ndarray, float]],
278
- # init: Optional[Union[np.ndarray, float]],
279
- # ):
280
- # moment = mu * size + init
281
- # return moment
282
-
283
265
def logp (
284
266
value : at .Variable ,
285
267
mu : at .Variable ,
@@ -289,18 +271,19 @@ def logp(
289
271
"""
290
272
Calculate log-probability of Gaussian Random Walk distribution at specified value.
291
273
292
-
293
-
294
274
Parameters
295
275
----------
296
- x: numeric
297
- Value for which log-probability is calculated.
276
+ value: at.Variable,
277
+ mu: at.Variable,
278
+ sigma: at.Variable,
279
+ init: at.Variable,
298
280
299
281
Returns
300
282
-------
301
283
TensorVariable
302
284
"""
303
285
286
+ # TODO: Remove this and use pm.Normal.logp
304
287
def normal_logp (value , mu , sigma ):
305
288
logp = (
306
289
- 0.5 * at .pow ((value - mu ) / sigma , 2 )
0 commit comments