@@ -460,7 +460,6 @@ def logp(self, x):
460
460
def _distr_parameters_for_repr (self ):
461
461
return ["mu" , "cov" ]
462
462
463
-
464
463
def random (self , point = None , size = None ):
465
464
"""
466
465
Draw random values from MvGaussianRandomWalk.
@@ -477,48 +476,61 @@ def random(self, point=None, size=None):
477
476
Returns
478
477
-------
479
478
array
479
+
480
+
481
+ Examples
482
+ -------
483
+ Create one sample from a 2-dimensional Gaussian random walk with 10 timesteps::
484
+
485
+ mu = np.array([1.0, 0.0])
486
+ cov = np.array([[1.0, 0.0], [0.0, 2.0]])
487
+ sample = MvGaussianRandomWalk(mu, cov, shape=(10, 2)).random(size=1)
480
488
"""
481
489
482
- param_attribute = getattr (self .innov , "chol_cov" if self .innov ._cov_type == "chol" else self .innov ._cov_type )
483
- mu , param = distribution .draw_values ([self .innov .mu , param_attribute ], point = point , size = size )
490
+ param_attribute = getattr (
491
+ self .innov , "chol_cov" if self .innov ._cov_type == "chol" else self .innov ._cov_type
492
+ )
493
+ mu , param = distribution .draw_values (
494
+ [self .innov .mu , param_attribute ], point = point , size = size
495
+ )
484
496
return distribution .generate_samples (
485
- self ._random ,
497
+ self ._random ,
486
498
size = size ,
487
499
dist_shape = self .shape ,
488
500
not_broadcast_kwargs = {
489
501
"sample_shape" : to_tuple (size ),
490
502
"param" : param ,
491
503
"mu" : mu ,
492
- "cov_type" : self .innov ._cov_type
493
- }
504
+ "cov_type" : self .innov ._cov_type ,
505
+ },
494
506
)
495
507
496
- def _random (self , mu , param , size , sample_shape , cov_type ):
508
+ def _random (self , mu , param , size , sample_shape , cov_type ):
497
509
"""
498
510
Implements the multivariate Gaussian random walk as a cumulative
499
511
sum of i.i.d. multivariate Gaussians.
500
512
Assumes that
501
513
size is of the form (samples, time, dims).
502
- """
514
+ """
503
515
504
516
if cov_type == "chol" :
505
- cov = np .matmul (param , param .transpose ())
517
+ cov = np .matmul (param , param .transpose ())
506
518
elif cov_type == "tau" :
507
- cov = np .linalg .inv (param )
519
+ cov = np .linalg .inv (param )
508
520
else :
509
521
cov = param
510
522
511
523
# time axis comes after the sample axis
512
- time_axis = len (sample_shape )
524
+ time_axis = len (sample_shape )
513
525
514
526
# spatial axis is last
515
- spatial_axis = - 1
527
+ spatial_axis = - 1
516
528
517
- rv = stats .multivariate_normal (mean = mu , cov = cov )
529
+ rv = stats .multivariate_normal (mean = mu , cov = cov )
518
530
519
531
# only feed in sample and time dimensions since stats.multivariate_normal
520
532
# automatically adds back in the spatial dimensions to the end when it samples.
521
- data = rv .rvs (size [:spatial_axis ]).cumsum (axis = time_axis )
533
+ data = rv .rvs (size [:spatial_axis ]).cumsum (axis = time_axis )
522
534
523
535
# shift the walk to start at zero
524
536
if len (data .shape ) > 2 :
0 commit comments