[英]CDF of a multivariate Normal in Tensorflow
我想使用張量流評估多元正態分布的cdf。 到目前為止我嘗試過的是:
import tensorflow as tf
ds = tf.contrib.distributions
# Initialize a single 3-variate Gaussian.
mu = [0., 0., 0.]
cov = [[ 0.36, 0.12, 0.06],
[ 0.12, 0.29, -0.13],
[ 0.06, -0.13, 0.26]]
mvn = ds.MultivariateNormalFullCovariance(
loc=mu,
covariance_matrix=cov)
value = tf.constant([0., 0., 0.])
with tf.Session() as sess:
print mvn.cdf(value).eval()
產生錯誤:
NotImplementedError: cdf is not implemented when overriding event_shape
我不明白為什么我要覆蓋event_shape,因為event_shape和值的形狀相同。 我究竟做錯了什么?
您沒有做錯任何事。 CDF未針對多元正態實現。 (我同意錯誤消息令人困惑。錯誤消息由負責實現cdf
TransformedDistribution
拋出。)
如果您可以忍受蒙特卡洛近似,我建議您執行以下操作:
def approx_multivariate_cdf(dist, bound, num_samples=int(100e3), seed=None):
s = dist.sample(num_samples, seed=seed)
in_box = tf.cast(tf.reduce_all(s <= bound, axis=-1), dist.dtype)
return tf.reduce_mean(in_box, axis=0)
(經過一番思考,我確信有人可以做得更好。)
這里可能還會描述一個更聰明的解決方案: https : //arxiv.org/abs/1603.04166
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.