hmm viterbi.docx

上传人:b****4 文档编号:5403383 上传时间:2022-12-16 格式:DOCX 页数:17 大小:56.33KB
下载 相关 举报
hmm viterbi.docx_第1页
第1页 / 共17页
hmm viterbi.docx_第2页
第2页 / 共17页
hmm viterbi.docx_第3页
第3页 / 共17页
hmm viterbi.docx_第4页
第4页 / 共17页
hmm viterbi.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

hmm viterbi.docx

《hmm viterbi.docx》由会员分享,可在线阅读,更多相关《hmm viterbi.docx(17页珍藏版)》请在冰豆网上搜索。

hmm viterbi.docx

hmmviterbi

Viterbialgorithm

FromWikipedia,thefreeencyclopedia

Jumpto:

navigation,search

TheViterbialgorithmisadynamicprogrammingalgorithmforfindingthemostlikelysequenceofhiddenstates–calledtheViterbipath–thatresultsinasequenceofobservedevents,especiallyinthecontextofMarkovinformationsources,andmoregenerally,hiddenMarkovmodels.Theforwardalgorithmisacloselyrelatedalgorithmforcomputingtheprobabilityofasequenceofobservedevents.Thesealgorithmsbelongtotherealmofinformationtheory.

Thealgorithmmakesanumberofassumptions.

∙First,boththeobservedeventsandhiddeneventsmustbeinasequence.Thissequenceoftencorrespondstotime.

∙Second,thesetwosequencesneedtobealigned,andaninstanceofanobservedeventneedstocorrespondtoexactlyoneinstanceofahiddenevent.

∙Third,computingthemostlikelyhiddensequenceuptoacertainpointtmustdependonlyontheobservedeventatpointt,andthemostlikelysequenceatpointt−1.

Theseassumptionsareallsatisfiedinafirst-orderhiddenMarkovmodel.

Theterms"Viterbipath"and"Viterbialgorithm"arealsoappliedtorelateddynamicprogrammingalgorithmsthatdiscoverthesinglemostlikelyexplanationforanobservation.Forexample,instatisticalparsingadynamicprogrammingalgorithmcanbeusedtodiscoverthesinglemostlikelycontext-freederivation(parse)ofastring,whichissometimescalledthe"Viterbiparse".

TheViterbialgorithmwasconceivedbyAndrewViterbiin1967asadecodingalgorithmforconvolutionalcodesovernoisydigitalcommunicationlinks.FormoredetailsonthehistoryofthedevelopmentofthealgorithmseeDavidForney'sarticle[1].ThealgorithmhasfounduniversalapplicationindecodingtheconvolutionalcodesusedinbothCDMAandGSMdigitalcellular,dial-upmodems,satellite,deep-spacecommunications,and802.11wirelessLANs.Itisnowalsocommonlyusedinspeechrecognition,keywordspotting,computationallinguistics,andbioinformatics.Forexample,inspeech-to-text(speechrecognition),theacousticsignalistreatedastheobservedsequenceofevents,andastringoftextisconsideredtobethe"hiddencause"oftheacousticsignal.TheViterbialgorithmfindsthemostlikelystringoftextgiventheacousticsignal.

Contents

[hide]

∙1Overview

∙2Algorithm

∙3Example

∙4Javaimplementation

∙5C#Implementation

∙6Extensions

∙7Seealso

∙8Notes

∙9References

∙10Externallinks

[edit]Overview

Theassumptionslistedabovecanbeelaboratedasfollows.TheViterbialgorithmoperatesonastatemachineassumption.Thatis,atanytimethesystembeingmodeledisinsomestate.Thereareafinitenumberofstates.Whilemultiplesequencesofstates(paths)canleadtoagivenstate,atleastoneofthemisamostlikelypathtothatstate,calledthe"survivorpath".Thisisafundamentalassumptionofthealgorithmbecausethealgorithmwillexamineallpossiblepathsleadingtoastateandonlykeeptheonemostlikely.Thiswaythealgorithmdoesnothavetokeeptrackofallpossiblepaths,onlyoneperstate.

Asecondkeyassumptionisthatatransitionfromapreviousstatetoanewstateismarkedbyanincrementalmetric,usuallyanumber.Thistransitioniscomputedfromtheevent.Thethirdkeyassumptionisthattheeventsarecumulativeoverapathinsomesense,usuallyadditive.Sothecruxofthealgorithmistokeepanumberforeachstate.Whenaneventoccurs,thealgorithmexaminesmovingforwardtoanewsetofstatesbycombiningthemetricofapossiblepreviousstatewiththeincrementalmetricofthetransitionduetotheeventandchoosesthebest.Theincrementalmetricassociatedwithaneventdependsonthetransitionpossibilityfromtheoldstatetothenewstate.Forexampleindatacommunications,itmaybepossibletoonlytransmithalfthesymbolsfromanoddnumberedstateandtheotherhalffromanevennumberedstate.Additionally,inmanycasesthestatetransitiongraphisnotfullyconnected.Asimpleexampleisacarthathas3states—forward,stopandreverse—andatransitionfromforwardtoreverseisnotallowed.Itmustfirstenterthestopstate.Aftercomputingthecombinationsofincrementalmetricandstatemetric,onlythebestsurvivesandallotherpathsarediscarded.Therearemodificationstothebasicalgorithmwhichallowforaforwardsearchinadditiontothebackwardsonedescribedhere.

Pathhistorymustbestored.Insomecases,thesearchhistoryiscompletebecausethestatemachineattheencoderstartsinaknownstateandthereissufficientmemorytokeepallthepaths.Inothercases,aprogrammaticsolutionmustbefoundforlimitedresources:

oneexampleisconvolutionalencoding,wherethedecodermusttruncatethehistoryatadepthlargeenoughtokeepperformancetoanacceptablelevel.AlthoughtheViterbialgorithmisveryefficientandtherearemodificationsthatreducethecomputationalload,thememoryrequirementstendtoremainconstant.

[edit]Algorithm

SupposingwearegivenaHiddenMarkovModel(HMM)withstatesY,initialprobabilitiesπiofbeinginstateiandtransitionprobabilitiesai,joftransitioningfromstateitostatej.Sayweobserveoutputs

.Thestatesequence

mostlikelytohaveproducedtheobservationsisgivenbytherecurrencerelations:

[1]

HereVt,kistheprobabilityofthemostprobablestatesequenceresponsibleforthefirstt+1observations(weaddonebecauseindexingstartedat0)thathaskasitsfinalstate.TheViterbipathcanberetrievedbysavingbackpointerswhichrememberwhichstateywasusedinthesecondequation.LetPtr(k,t)bethefunctionthatreturnsthevalueofyusedtocomputeVt,kift>0,orkift=0.Then:

Thecomplexityofthisalgorithmis

.

[edit]Example

Considertwofriends,AliceandBob,wholivefarapartfromeachotherandwhotalktogetherdailyoverthetelephoneaboutwhattheydidthatday.Bobisonlyinterestedinthreeactivities:

walkinginthepark,shopping,andcleaninghisapartment.Thechoiceofwhattodoisdeterminedexclusivelybytheweatheronagivenday.AlicehasnodefiniteinformationabouttheweatherwhereBoblives,butsheknowsgeneraltrends.BasedonwhatBobtellsherhedideachday,Alicetriestoguesswhattheweathermusthavebeenlike.

AlicebelievesthattheweatheroperatesasadiscreteMarkovchain.Therearetwostates,"Rainy"and"Sunny",butshecannotobservethemdirectly,thatis,theyarehiddenfromher.Oneachday,thereisacertainchancethatBobwillperformoneofthefollowingactivities,dependingontheweather:

"walk","shop",or"clean".SinceBobtellsAliceabouthisactivities,thosearetheobservations.TheentiresystemisthatofahiddenMarkovmodel(HMM).

Aliceknowsthegeneralweathertrendsinthearea,andwhatBoblikestodoonaverage.Inotherwords,theparametersoftheHMMareknown.TheycanbewrittendowninthePythonprogramminglanguage:

states=('Rainy','Sunny')

observations=('walk','shop','clean')

start_probability={'Rainy':

0.6,'Sunny':

0.4}

transition_probability={

'Rainy':

{'Rainy':

0.7,'Sunny':

0.3},

'Sunny':

{'Rainy':

0.4,'Sunny':

0.6},

}

emission_probability={

'Rainy':

{'walk':

0.1,'shop':

0.4,'clean':

0.5},

'Sunny':

{'walk':

0.6,'shop':

0.3,'clean':

0.1},

}

Inthispieceofcode,start_probabilityrepresentsAlice'sbeliefaboutwhichstatetheHMMisinwhenBobfirstcallsher(allsheknowsisthatittendstoberainyonaverage).Theparticularprobabilitydistributionusedhereisnottheequilibriumone,whichis(giventhetransitionprobabilities)approximately{'Rainy':

0.57,'Sunny':

0.43}.Thetransition_probabilityrepresentsthechangeoftheweatherintheunderlyingMarkovchain.Inthisexample,thereisonlya30%chancethattomorrowwillbesunnyiftodayisrainy.Theemission_probabilityrepresentshowlikelyBobistoperformacertainactivityoneachday.Ifitisrainy,thereisa50%chancethatheiscleaninghisapartment;ifitissunny,thereisa60%chancethatheisoutsideforawalk.

AlicetalkstoBobthreedaysinarowanddiscoversthatonthefirstdayhewentforawalk,ontheseconddayhewentshopping,andonthethirddayhecleanedhisapartment.Alicehasaquestion:

whatisthemostlikelysequenceofrainy/sunnydaysthatwouldexplaintheseobservations?

ThisisansweredbytheViterbialgorithm.

#HelpsvisualizethestepsofViterbi.

defprint_dptable(V):

print"",

foriinrange(len(V)):

print"%7s"%("%d"%i),

print

foryinV[0].keys():

print"%.5s:

"%y,

fortinrange(len(V)):

print"%.7s"%("%f"%V[t][y]),

print

defviterbi(obs,states,start_p,trans_p,emit_p):

V=[{}]

path={}

#Initializebasecases(t==0)

foryinstates:

V[0][y]=start_p[y]*emit_p[y][obs[0]]

path[y]=[y]

#RunViterbifort>0

fortinrange(1,len(obs)):

V.append({})

newpath={}

foryinstates:

(prob,state)=max([(V[t-1][y0]*trans_p[y0][y]*emit_p[y][obs[t]],y0)fory0instates])

V[t][y]=prob

newpath[y]=path[state]+[y]

#Don'tneedtoremembertheoldpaths

path=newpath

print_dptable(V)

(prob,state)=max([(V[len(obs)-1][y],y)foryinstates])

return(prob,path[state])

Thefunctionviterbitakesthefollowingarguments:

obsisthesequenceofobservations,e.g.['walk','shop','clean'];statesisthesetofhiddenstates;start_pisthestartprobability;trans_parethetransitionprobabilities;andemit_paretheemissionprobabilities.Forsimplicityofcode,weassumethattheobservationsequenceobsisnon-emptyandthattrans_p[i][j]andemit_p[i][j]isdefinedforallstatesi,j.

In

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1