How to use BNT for DBNs.docx
《How to use BNT for DBNs.docx》由会员分享,可在线阅读,更多相关《How to use BNT for DBNs.docx(12页珍藏版)》请在冰豆网上搜索。
HowtouseBNTforDBNs
HowtouseBNTforDBNs
∙Modelspecification
oHMMs
oKalmanfilters
oCoupledHMMs
oWaternetwork
oBATnetwork
∙Inference
oDiscretehiddennodes
oContinuoushiddennodes
∙Learning
oParameterlearning
oStructurelearning
Modelspecification
DynamicBayesianNetworks(DBNs)aredirectedgraphicalmodelsofstochasticprocesses.TheygeneralisehiddenMarkovmodels(HMMs)andlineardynamicalsystems(LDSs)byrepresentingthehidden(andobserved)stateintermsofstatevariables,whichcanhavecomplexinterdependencies.Thegraphicalstructureprovidesaneasywaytospecifytheseconditionalindependencies,andhencetoprovideacompactparameterizationofthemodel.
Notethat"temporalBayesiannetwork"wouldbeabetternamethan"dynamicBayesiannetwork",sinceitisassumedthatthemodelstructuredoesnotchange,butthetermDBNhasbecomeentrenched.Wealsonormallyassumethattheparametersdonotchange,i.e.,themodelistime-invariant.However,wecanalwaysaddextrahiddennodestorepresentthecurrent"regime",therebycreatingmixturesofmodelstocaptureperiodicnon-stationarities.
Therearesomecaseswherethesizeofthestatespacecanchangeovertime,e.g.,trackingavariable,butunknown,numberofobjects.Inthiscase,weneedtochangethemodelstructureovertime.BNTdoesnotsupportthis.
HiddenMarkovModels(HMMs)
ThesimplestkindofDBNisaHiddenMarkovModel(HMM),whichhasonediscretehiddennodeandonediscreteorcontinuousobservednodeperslice.Weillustratethisbelow.Asbefore,circlesdenotecontinuousnodes,squaresdenotediscretenodes,clearmeanshidden,shadedmeansobserved.
Wehave"unrolled"themodelforthree"timeslices"--thestructureandparametersareassumedtorepeatasthemodelisunrolledfurther.HencetospecifyaDBN,weneedtodefinetheintra-slicetopology(withinaslice),theinter-slicetopology(betweentwoslices),aswellastheparametersforthefirsttwoslices.(Suchatwo-slicetemporalBayesnetisoftencalleda2TBN.)
Wecanspecifythetopologyasfollows.
intra=zeros
(2);
intra(1,2)=1;%node1inslicetconnectstonode2inslicet
inter=zeros
(2);
inter(1,1)=1;%node1inslicet-1connectstonode1inslicet
Wecanspecifytheparametersasfollows,whereforsimplicityweassumetheobservednodeisdiscrete.
Q=2;%numhiddenstates
O=2;%numobservablesymbols
ns=[QO];
dnodes=1:
2;
bnet=mk_dbn(intra,inter,ns,'discrete',dnodes);
fori=1:
4
bnet.CPD{i}=tabular_CPD(bnet,i);
end
WeassumethedistributionsP(X(t)|X(t-1))andP(Y(t)|X(t))areindependentoftfort>1.HencetheCPDfornodes5,7,...isthesameasfornode3,sowesaytheyareinthesameequivalenceclass,withnode3beingthe"representative"forthisclass.Inotherwords,wehavetiedtheparametersfornodes3,5,7,...Similarly,nodes4,6,8,...aretied.Note,however,that(theparametersfor)nodes1and2arenottiedtosubsequentslices.
AboveweassumedtheobservationmodelP(Y(t)|X(t))isindependentoftfort>1,butitisconventionaltoassumethisistrueforallt.Sowewouldliketoputnodes2,4,6,...allinthesameclass.Wecandothisbyexplicitelydefiningtheequivalenceclasses,asfollows(seehereformoredetailsonparametertying).
Wedefineeclass1(i)tobetheequivalenceclassthatnodeiinslice1belongsto.Similarly,wedefineeclass2(i)tobetheequivalenceclassthatnodeiinslice2,3,...,belongsto.ForanHMM,wehave
eclass1=[12];
eclass2=[32];
eclass=[eclass1eclass2];
Thistiestheobservationmodelacrossslices,sincee.g.,eclass(4)=eclass
(2)=2.
Bydefault,eclass1=1:
ss,andeclass2=(1:
ss)+ss,wheress=slicesize=thenumberofnodesperslice.Butbyusingtheabovetieingpattern,wenowonlyhave3CPDstospecify,insteadof4:
bnet=mk_dbn(intra,inter,ns,'discrete',dnodes,'eclass1',eclass1,'eclass2',eclass2);
prior0=normalise(rand(Q,1));
transmat0=mk_stochastic(rand(Q,Q));
obsmat0=mk_stochastic(rand(Q,O));
bnet.CPD{1}=tabular_CPD(bnet,1,prior0);
bnet.CPD{2}=tabular_CPD(bnet,2,obsmat0);
bnet.CPD{3}=tabular_CPD(bnet,3,transmat0);
Wediscusshowtodoinferenceandlearningonthismodelbelow.(SeealsomyHMMtoolbox,whichisincludedwithBNT.)
SomecommonvariantsonHMMsareshownbelow.BNTcanhandleallofthese.
LinearDynamicalSystems(LDSs)andKalmanfilters
ALinearDynamicalSystem(LDS)hasthesametopologyasanHMM,butallthenodesareassumedtohavelinear-Gaussiandistributions,i.e.,
x(t+1)=A*x(t)+w(t),w~N(0,Q),x(0)~N(init_x,init_V)
y(t)=C*x(t)+v(t),v~N(0,R)
Somesimplevariantsareshownbelow.
WecancreatearegularLDSinBNTasfollows.
intra=zeros
(2);
intra(1,2)=1;
inter=zeros
(2);
inter(1,1)=1;
n=2;
X=2;%sizeofhiddenstate
Y=2;%sizeofobservablestate
ns=[XY];
dnodes=[];
onodes=[2];
eclass1=[12];
eclass2=[32];
bnet=mk_dbn(intra,inter,ns,'discrete',dnodes,'eclass1',eclass1,'eclass2',eclass2);
x0=rand(X,1);
V0=eye(X);%mustbepositivesemidefinite!
C0=rand(Y,X);
R0=eye(Y);
A0=rand(X,X);
Q0=eye(X);
bnet.CPD{1}=gaussian_CPD(bnet,1,'mean',x0,'cov',V0,'cov_prior_weight',0);
bnet.CPD{2}=gaussian_CPD(bnet,2,'mean',zeros(Y,1),'cov',R0,'weights',C0,...
'clamp_mean',1,'cov_prior_weight',0);
bnet.CPD{3}=gaussian_CPD(bnet,3,'mean',zeros(X,1),'cov',Q0,'weights',A0,...
'clamp_mean',1,'cov_prior_weight',0);
Wediscusshowtodoinferenceandlearningonthismodelbelow.(SeealsomyKalmanfiltertoolbox,whichisincludedwithBNT.)
CoupledHMMs
HereisanexampleofacoupledHMMwithN=5chains,unrolledforT=3slices.EachhiddendiscretenodehasaprivateobservedGaussianchild.
Wecanmakethisusingthefunction
Q=2;%binaryhiddennodes
discrete_obs=0;%ctsobservednodes
Y=1;%scalarobservednodes
bnet=mk_chmm(N,Q,Y,discrete_obs);
Waternetwork
Considerthefollowingmodelofawaterpurificationplant,developedbyFinnV.Jensen,UffeKj鎟ulff,KristianG.Olesen,andJanPedersen.(Clickhereformoredetailsonthismodel.FollowingBoyenandKoller,wehaveaddeddiscreteevidencenodes.)
WenowshowhowtospecifythismodelinBNT.
ss=12;%slicesize
intra=zeros(ss);
intra(1,9)=1;
intra(3,10)=1;
intra(4,11)=1;
intra(8,12)=1;
inter=zeros(ss);
inter(1,[13])=1;%node1inslice1connectstonodes1and3inslice2
inter(2,[237])=1;
inter(3,[345])=1;
inter(4,[346])=1;
inter(5,[356])=1;
inter(6,[456])=1;
inter(7,[78])=1;
inter(8,[678])=1;
onodes=9:
12;%observed
dnodes=1:
ss;%discrete
ns=2*ones(1,ss);%binarynodes
eclass1=1:
12;
eclass2=[13:
209:
12];
eclass=[eclass1eclass2];
bnet=mk_dbn(intra,inter,ns,'discrete',dnodes,'eclass1',eclass1,'eclass2',eclass2);
fore=1:
max(eclass)
bnet.CPD{e}=tabular_CPD(bnet,e);
end
Wehavetiedtheobservationparametersacrossallslices.Clickhereforamorecomplexexampleofparametertieing.
BATnet
AsanexampleofamorecomplicatedDBN,considerthefollowingexample,whichisamodelofacar'shighlevelstate,asmightbeusedbyanautomatedcar.(ThemodelisfromForbes,Huang,KanazawaandRussell,"TheBATmobile:
TowardsaBayesianAutomatedTaxi",IJCAI95.ThefigureisfromBoyenandKoller,"TractableInferenceforComplexStochasticProcesses",UAI98.Forsimplicity,weonlyshowtheobservednodesforslice2.)
Sincethistopologyissocomplicated,itisusefultobeabletorefertothenodesbyname,insteadofnumber.
names={'LeftClr','RightClr','LatAct',...'Bclr','BYdotDiff'};
ss=length(names);
Wecanspecifytheintra-slicetopologyusingacellarrayasfollows,whereeachrowspecifiesaconnectionbetweentwonamednodes:
intrac={...
'LeftClr','LeftClrSens';
'RightClr','RightClrSens';
...
'BYdotDiff','BcloseFast'};
Finally,wecanconvertthiscellarraytoanadjacencymatrixusingthefollowingfunction:
[intra,names]=mk_adj_mat(intrac,names,1);
Thisfunctionalsopermutesthenamessothattheyareintopologicalorder.Giventhisorderingofthenames,wecanmaketheinter-sliceconnectivitymatrixasfollows:
interc={...
'LeftClr','LeftClr';
'LeftClr','LatAct';
...
'FBStatus','LatAct'};
inter=mk_adj_mat(interc,names,0);
Torefertoanode,wemustknowitsnumber,whichcanbecomputedasinthefollowingexample:
obs={'LeftClrSens','RightClrSens','TurnSignalSens','XdotSens','YdotSens','FYdotDiffSens',...
'FclrSens','BXdotSens','BclrSens','BYdotDiffSens'};
fori=1:
length(obs)
onodes(i)=stringmatch(obs{i},names);
end
onodes=sort(onodes);
(WesorttheonodessincemostBNTroutinesassumethatset-valuedargumentsareinsortedorder.)WecannowmaketheDBN:
dnodes=1:
ss;
ns=2*ones(1,ss);%binarynodes
bnet=mk_dbn(intra,inter,ns,'iscrete',dnodes);
Tospecifytheparameters,wemustknowtheorderoftheparents.SeethefunctionBNT/general/mk_named_CPTforawaytodothisinthecaseoftabularnodes.Forsimplicity,wejustgeneraterandomparameters:
fori=1:
2*ss
bnet.CPD{i}=tabular_CPD(bnet,i);
end
AcompleteversionofthisexampleisavailableinBNT/examples/dynamic/bat1.m.
Inference
ThegeneralinferenceproblemforDBNsistocomputeP(X(i,t0)|Y(:
t1:
t2)),whereX(i,t)representsthei'thhiddenvariableattimetandY(:
t1:
t2)representsalltheevidencebetweentimest1andt2.Thereareseveralspecialcasesofinterest,illustratedbelow.Thearrowindicatest0:
itisX(t0)thatwearetryingtoestimate.