def testMarkovChainLogprobMatchesOriginal(self): # Use a very short dataset since the non-markov-chain model is slow. dataset = data.sp500_returns(num_points=10) model = stochastic_volatility.StochasticVolatility( use_markov_chain=False, **dataset) markov_chain_model = stochastic_volatility.StochasticVolatility( use_markov_chain=True, **dataset) xs = self.evaluate(model.prior_distribution().sample( 10, seed=tfp_test_util.test_seed())) xs_stacked = xs[:-1] + (tf.stack(xs[-1], axis=-1), ) self.assertAllClose( model.unnormalized_log_prob(xs), markov_chain_model.unnormalized_log_prob(xs_stacked), atol=1e-2)
def testBasic(self): """Checks that unconstrained parameters yield finite joint densities.""" model = stochastic_volatility.StochasticVolatility( centered_returns=tf.convert_to_tensor([5., -2.1, 8., 4., 1.1])) self.validate_log_prob_and_transforms( model, sample_transformation_shapes=dict( identity={ 'persistence_of_volatility': [], 'mean_log_volatility': [], 'white_noise_shock_scale': [], 'log_volatility': [5] }))