如何在最新版本的Tensorflow中使用MultiVariateNormal分发

时间:2018-05-15 02:50:24

标签: tensorflow

我需要使用function dateDiffToString(a, b){ // make checks to make sure a and b are not null // and that they are date | integers types diff = Math.abs(a - b); ms = diff % 1000; diff = (diff - ms) / 1000 ss = diff % 60; diff = (diff - ss) / 60 mm = diff % 60; diff = (diff - mm) / 60 hh = diff % 24; days = (diff - hh) / 24 return days + ":" + hh+":"+mm+":"+ss+"."+ms; } var today = new Date() var yest = new Date() yest = yest.setDate(today.getDate()-1) console.log(dateDiffToString(yest, today))中的MultiVariateNormal分布但是在最新版本的Tensorflow中,上述分发不可用,导致错误 enter image description here

有人可以指出哪个可用的分布将采用均值和西格玛,并给出多变量正态分布。

1 个答案:

答案 0 :(得分:0)

tf.contrib.distributions.MultivariateNormalFullCovariance defines the Multivariate Normal distribution that is parameterized by the表示向量(mu)and the协方差矩阵。

一个例子,

# Let mean vector and co-variance be:
mu = [1., 2] 
cov = [[ 1,  3/5],[ 3/5,  2]]

#Multivariate Normal distribution
gaussian = tf.contrib.distributions.MultivariateNormalFullCovariance(
           loc=mu,
           covariance_matrix=cov)

# Generate a mesh grid to plot the distributions
X, Y = tf.meshgrid(tf.range(-3, 3, 0.1), tf.range(-3, 3, 0.1))
idx = tf.concat([tf.reshape(X, [-1, 1]), tf.reshape(Y,[-1,1])], axis =1)
prob = tf.reshape(gaussian.prob(idx), tf.shape(X))

with tf.Session() as sess:
   p = sess.run(prob)
   m, c = sess.run([gaussian.mean(), gaussian.covariance()])
   # m is [1., 2.]
   # c is [[1, 0.6], [0.6, 2]]

enter image description here