【发布时间】:2020-03-08 15:01:43
【问题描述】:
我正在尝试了解如何在 Tensorflow 概率中实现以下模型。
- 角度
theta在[-pi / 2, +pi / 2]范围内具有一致的先验概率; - 方向翻转概率
beta在[0, 1]范围内具有统一的先验概率; -
theta'设置为:-
theta' = theta + pi概率为beta;或 -
theta' = theta概率为(1 - beta);
-
- 浓度
c具有HalfCauchy先验概率;和 - 观察,
alpha来自von Mises distribution,以theta'为中心,专注于c。
到目前为止,我尝试过的是
import tensorflow_probability as tfp
import numpy as np
tfd = tfp.distributions
model = tfd.JointDistributionSequential(
[
tfd.Uniform(-np.pi / 2, +np.pi / 2, name='theta'), # theta
tfd.Uniform(0.0, 1.0, name='beta'), # beta
tfd.HalfCauchy(loc=0, scale=1), # c
lambda c, beta, theta: tfd.VonMises(
loc=theta + np.pi * tfd.Binomial(probs=beta),
concentration=c,
name='observed'
), # Observation, alpha
]
)
调用它会在二项式部分出现错误:TypeError: __init__() missing 1 required positional argument: 'total_count'。我做错了什么?
2020 年 3 月 17 日更新
最新代码如下。我仍在尝试找出如何实现模型的第 (3) 部分,即通过添加pi 和概率beta 来翻转我的角度方向theta。对此的任何帮助将不胜感激!到目前为止我所拥有的不起作用,因为我无法将伯努利对象乘以浮点数。
model = tfd.JointDistributionSequential(
[
tfd.Uniform(-np.pi / 2, +np.pi / 2, name='theta'), # theta
tfd.Uniform(0.0, 1.0, name='beta'), # beta
tfd.HalfCauchy(loc=0, scale=1), # c
lambda c, beta, theta: tfd.VonMises(
loc=theta + np.pi * tfd.Bernoulli(probs=beta, dtype=tf.float32),
concentration=c,
name='observed'
), # Observation, alpha
]
)
【问题讨论】:
-
我想你可能想使用
MixtureSameFamily?
标签: tensorflow tensorflow-probability hierarchical-bayesian