如何在TensorFlow中计算概率密度函数(PDF)

4
在Matlab中,我可以通过使用函数来计算高斯分布的概率密度函数(PDF):
x = [0.8147,0.9058,0.1270,0.9134,0.6324,0.0975,0.2785,0.5469,0.9575,0.9649]
y = normpdf(x,1.0,2.5)

输出:

y = 0.1591    0.1595    0.1501    0.1595    0.1579    0.1495    0.1531    0.1570    0.1596    0.1596

使用 TensorFlow,我尝试了以下代码:
x = tf.variable([0.8147,0.9058,0.1270,0.9134,0.6324,0.0975,0.2785,0.5469,0.9575,0.9649],tf.float32)
y = tf.contrib.distributions.NormalWithSoftplusSigma.pdf(x)

我遇到了一个错误:TypeError: pdf missing 1 required positional argument

如何输入mu和sigma值来获得类似的输出结果?

2个回答

5

这个函数 pdf 已经更新为 prob:

dist = tf.contrib.distributions.Normal(1.0, 2.5) 
y = dist.prob(x)

3
首先创建一个“正态分布”对象,然后使用“pdf”方法。
dist = tf.contrib.distributions.Normal(1.0, 2.5)
y = dist.pdf(x)

更多细节请参见此处


2
详细信息的链接已失效。 - slcott

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接