Neural network 如何计算KL散度relaxedonehot分类

Neural network 如何计算KL散度relaxedonehot分类,neural-network,autoencoder,bayesian-networks,Neural Network,Autoencoder,Bayesian Networks,我想计算PyTorch中2个relaxedonehot分类分布之间的KL散度。我觉得我做错了什么,因为吉隆坡的偏离度非常高 导入火炬 从torch.com导入relaxedonehot分类 p_m=relaxedonehot分类(torch.张量([2.2]),probs=torch.张量([0.1,0.2,0.3,0.4])) 批次参数是从火炬获得的(2,4) q_m=RelaxedOneHotCategorical(torch.tensor([5.4]),logits=从_a_nn获得的批次

我想计算PyTorch中2个relaxedonehot分类分布之间的KL散度。我觉得我做错了什么,因为吉隆坡的偏离度非常高

导入火炬
从torch.com导入relaxedonehot分类
p_m=relaxedonehot分类(torch.张量([2.2]),probs=torch.张量([0.1,0.2,0.3,0.4]))
批次参数是从火炬获得的(2,4)
q_m=RelaxedOneHotCategorical(torch.tensor([5.4]),logits=从_a_nn获得的批次参数)
z=q_m.rsample()
kl=-torch.mean(q_m.log_prob(z).exp()*(q_m.log_prob(z)-p_m.log_prob(z)))
Z
张量([[0.2671,0.2973,0.2144,0.2212],
[0.2431, 0.2550, 0.3064, 0.1954]])
吉隆坡
张量(-766.7020)
我错过了一些琐碎的事情吗?我应该做些特别的事情吗?我看到RelaxedonehotCategorial基于ExpConcrete,应该处理下溢