@@ -1109,6 +1109,7 @@ def _sample_conditional(
11091109 group : str ,
11101110 random_seed : RandomState | None = None ,
11111111 data : pt .TensorLike | None = None ,
1112+ method : str = "svd" ,
11121113 ** kwargs ,
11131114 ):
11141115 """
@@ -1130,6 +1131,11 @@ def _sample_conditional(
11301131 Observed data on which to condition the model. If not provided, the function will use the data that was
11311132 provided when the model was built.
11321133
1134+ method: str
1135+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
1136+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
1137+ is "svd".
1138+
11331139 kwargs:
11341140 Additional keyword arguments are passed to pymc.sample_posterior_predictive
11351141
@@ -1181,6 +1187,7 @@ def _sample_conditional(
11811187 covs = cov ,
11821188 logp = dummy_ll ,
11831189 dims = state_dims ,
1190+ method = method ,
11841191 )
11851192
11861193 obs_mu = (Z @ mu [..., None ]).squeeze (- 1 )
@@ -1192,6 +1199,7 @@ def _sample_conditional(
11921199 covs = obs_cov ,
11931200 logp = dummy_ll ,
11941201 dims = obs_dims ,
1202+ method = method ,
11951203 )
11961204
11971205 # TODO: Remove this after pm.Flat initial values are fixed
@@ -1222,6 +1230,7 @@ def _sample_unconditional(
12221230 steps : int | None = None ,
12231231 use_data_time_dim : bool = False ,
12241232 random_seed : RandomState | None = None ,
1233+ method : str = "svd" ,
12251234 ** kwargs ,
12261235 ):
12271236 """
@@ -1251,6 +1260,11 @@ def _sample_unconditional(
12511260 random_seed : int, RandomState or Generator, optional
12521261 Seed for the random number generator.
12531262
1263+ method: str
1264+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
1265+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
1266+ is "svd".
1267+
12541268 kwargs:
12551269 Additional keyword arguments are passed to pymc.sample_posterior_predictive
12561270
@@ -1309,6 +1323,7 @@ def _sample_unconditional(
13091323 steps = steps ,
13101324 dims = dims ,
13111325 mode = self ._fit_mode ,
1326+ method = method ,
13121327 sequence_names = self .kalman_filter .seq_names ,
13131328 k_endog = self .k_endog ,
13141329 )
@@ -1331,7 +1346,7 @@ def _sample_unconditional(
13311346 return idata_unconditional .posterior_predictive
13321347
13331348 def sample_conditional_prior (
1334- self , idata : InferenceData , random_seed : RandomState | None = None , ** kwargs
1349+ self , idata : InferenceData , random_seed : RandomState | None = None , method = "svd" , ** kwargs
13351350 ) -> InferenceData :
13361351 """
13371352 Sample from the conditional prior; that is, given parameter draws from the prior distribution,
@@ -1347,6 +1362,11 @@ def sample_conditional_prior(
13471362 random_seed : int, RandomState or Generator, optional
13481363 Seed for the random number generator.
13491364
1365+ method: str
1366+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
1367+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
1368+ is "svd".
1369+
13501370 kwargs:
13511371 Additional keyword arguments are passed to pymc.sample_posterior_predictive
13521372
@@ -1358,10 +1378,10 @@ def sample_conditional_prior(
13581378 "predicted_prior", and "smoothed_prior".
13591379 """
13601380
1361- return self ._sample_conditional (idata , "prior" , random_seed , ** kwargs )
1381+ return self ._sample_conditional (idata , "prior" , random_seed , method , ** kwargs )
13621382
13631383 def sample_conditional_posterior (
1364- self , idata : InferenceData , random_seed : RandomState | None = None , ** kwargs
1384+ self , idata : InferenceData , random_seed : RandomState | None = None , method = "svd" , ** kwargs
13651385 ):
13661386 """
13671387 Sample from the conditional posterior; that is, given parameter draws from the posterior distribution,
@@ -1376,6 +1396,11 @@ def sample_conditional_posterior(
13761396 random_seed : int, RandomState or Generator, optional
13771397 Seed for the random number generator.
13781398
1399+ method: str
1400+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
1401+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
1402+ is "svd".
1403+
13791404 kwargs:
13801405 Additional keyword arguments are passed to pymc.sample_posterior_predictive
13811406
@@ -1387,14 +1412,15 @@ def sample_conditional_posterior(
13871412 "predicted_posterior", and "smoothed_posterior".
13881413 """
13891414
1390- return self ._sample_conditional (idata , "posterior" , random_seed , ** kwargs )
1415+ return self ._sample_conditional (idata , "posterior" , random_seed , method , ** kwargs )
13911416
13921417 def sample_unconditional_prior (
13931418 self ,
13941419 idata : InferenceData ,
13951420 steps : int | None = None ,
13961421 use_data_time_dim : bool = False ,
13971422 random_seed : RandomState | None = None ,
1423+ method = "svd" ,
13981424 ** kwargs ,
13991425 ) -> InferenceData :
14001426 """
@@ -1423,6 +1449,11 @@ def sample_unconditional_prior(
14231449 random_seed : int, RandomState or Generator, optional
14241450 Seed for the random number generator.
14251451
1452+ method: str
1453+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
1454+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
1455+ is "svd".
1456+
14261457 kwargs:
14271458 Additional keyword arguments are passed to pymc.sample_posterior_predictive
14281459
@@ -1439,7 +1470,7 @@ def sample_unconditional_prior(
14391470 """
14401471
14411472 return self ._sample_unconditional (
1442- idata , "prior" , steps , use_data_time_dim , random_seed , ** kwargs
1473+ idata , "prior" , steps , use_data_time_dim , random_seed , method , ** kwargs
14431474 )
14441475
14451476 def sample_unconditional_posterior (
@@ -1448,6 +1479,7 @@ def sample_unconditional_posterior(
14481479 steps : int | None = None ,
14491480 use_data_time_dim : bool = False ,
14501481 random_seed : RandomState | None = None ,
1482+ method = "svd" ,
14511483 ** kwargs ,
14521484 ) -> InferenceData :
14531485 """
@@ -1477,6 +1509,11 @@ def sample_unconditional_posterior(
14771509 random_seed : int, RandomState or Generator, optional
14781510 Seed for the random number generator.
14791511
1512+ method: str
1513+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
1514+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
1515+ is "svd".
1516+
14801517 Returns
14811518 -------
14821519 InferenceData
@@ -1490,7 +1527,7 @@ def sample_unconditional_posterior(
14901527 """
14911528
14921529 return self ._sample_unconditional (
1493- idata , "posterior" , steps , use_data_time_dim , random_seed , ** kwargs
1530+ idata , "posterior" , steps , use_data_time_dim , random_seed , method , ** kwargs
14941531 )
14951532
14961533 def sample_statespace_matrices (
@@ -1933,6 +1970,7 @@ def forecast(
19331970 filter_output = "smoothed" ,
19341971 random_seed : RandomState | None = None ,
19351972 verbose : bool = True ,
1973+ method : str = "svd" ,
19361974 ** kwargs ,
19371975 ) -> InferenceData :
19381976 """
@@ -1989,6 +2027,11 @@ def forecast(
19892027 verbose: bool, default=True
19902028 Whether to print diagnostic information about forecasting.
19912029
2030+ method: str
2031+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
2032+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
2033+ is "svd".
2034+
19922035 kwargs:
19932036 Additional keyword arguments are passed to pymc.sample_posterior_predictive
19942037
@@ -2098,6 +2141,7 @@ def forecast(
20982141 sequence_names = self .kalman_filter .seq_names ,
20992142 k_endog = self .k_endog ,
21002143 append_x0 = False ,
2144+ method = method ,
21012145 )
21022146
21032147 forecast_model .rvs_to_initial_values = {
@@ -2126,6 +2170,7 @@ def impulse_response_function(
21262170 shock_trajectory : np .ndarray | None = None ,
21272171 orthogonalize_shocks : bool = False ,
21282172 random_seed : RandomState | None = None ,
2173+ method = "svd" ,
21292174 ** kwargs ,
21302175 ):
21312176 """
@@ -2177,6 +2222,11 @@ def impulse_response_function(
21772222 random_seed : int, RandomState or Generator, optional
21782223 Seed for the random number generator.
21792224
2225+ method: str
2226+ Method used to compute draws from multivariate normal. One of "cholesky", "eig", or "svd". "cholesky" is
2227+ fastest, but least robust to ill-conditioned matrices, while "svd" is slow but extermely robust. Default
2228+ is "svd".
2229+
21802230 kwargs:
21812231 Additional keyword arguments are passed to pymc.sample_posterior_predictive
21822232
@@ -2236,7 +2286,7 @@ def impulse_response_function(
22362286 shock_trajectory = pt .zeros ((n_steps , self .k_posdef ))
22372287 if Q is not None :
22382288 init_shock = pm .MvNormal (
2239- "initial_shock" , mu = 0 , cov = Q , dims = [SHOCK_DIM ], method = "svd"
2289+ "initial_shock" , mu = 0 , cov = Q , dims = [SHOCK_DIM ], method = method
22402290 )
22412291 else :
22422292 init_shock = pm .Deterministic (
0 commit comments