bayespy - 如果观察输出模糊规则,如何计算后验概率

时间:2017-10-16 12:34:51

标签: python-3.x bayesian-networks inference fuzzy

以下示例: http://bayespy.org/examples/hmm.html

a0 = [0.6, 0.4] # p(rainy)=0.6, p(sunny)=0.4
A = [[0.7, 0.3], # p(rainy->rainy)=0.7, p(rainy->sunny)=0.3
     [0.4, 0.6]] # p(sunny->rainy)=0.4, p(sunny->sunny)=0.6

N = 100 # will be observing 100 samples

# discrete first-order Markov chain is constructed as
from bayespy.nodes import CategoricalMarkovChain
Z = CategoricalMarkovChain(a0, A, states=N)

# observations
# probability of each activity depends on the current weather
P = [[0.1, 0.4, 0.5], # walk, shop, clean for rainy weather
     [0.6, 0.3, 0.1]]

# observed process using P and chain Z
from bayespy.nodes import Categorical, Mixture
Y = Mixture(Z, Categorical, P)

# DATA

# generate artificial data from the model itself.
# Realisation of weather process
weather = Z.random()

# using weather process, draw realisations of activities
activity = Mixture(weather, Categorical, P).random()

# INFERENCE
#using weather and activities data, 
#we set our variable Y to be observed:
Y.observe(activity)

# variational Bayesian inference engine with all random variables
from bayespy.inference import VB
Q = VB(Y, Z)

# is only one unobserved random variable, we recover the exact posterior 
distribution
Q.update()

如果活动状态(观察变量)不是分类集但是属于每个活动的模糊成员资格激活的分布,我应该如何使用Bayespy?例如。而不是像步行或清洁或商店那样相互独立的活动状态,人们可以在模糊框架中同时走路和购物到一定程度,例如步行80%,清洁20%,因此:

  • 我应该为模糊观察活动定义什么模型(高斯,分类,混合,......)?即改变分类?

activity = Mixture(weather, Categorical, P).random()

0 个答案:

没有答案