kalman filtering and friends: inference in time series...

60
Kalman filtering and friends: Inference in time series models Herke van Hoof slides mostly by Michael Rubinstein

Upload: others

Post on 29-Mar-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Kalmanfilteringandfriends:Inferenceintimeseriesmodels

HerkevanHoofslidesmostlybyMichaelRubinstein

Page 2: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Problemoverview• Goal– Estimatemostprobablestateattimekusingmeasurementuptotimek’

k’<k:predictionk’=k:filteringk’>k:smoothing

• Input– (Noisy)Sensormeasurements– Knownorlearnedsystemmodel(seelastlecture)

• Manyproblemsrequireestimationofthestateofsystemsthatchangeovertimeusingnoisymeasurementsonthesystem

Page 3: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Applications• Ballistics• Robotics– Robotlocalization

• Trackinghands/cars/…• Econometrics– Stockprediction

• Navigation

• Manymore…

Page 4: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example:noisylocalization

https://img.clipartfest.com

Positionatt=0

Measurementatt=1

t=2

t=3t=4

t=5

t=6

Page 5: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example:noisylocalization

https://img.clipartfest.com

Positionatt=0

Measurementatt=1

t=2

t=3t=4

t=5

Smoothing:wherewasIinthepast

t=6

Page 6: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example:noisylocalization

https://img.clipartfest.com

Positionatt=0

Measurementatt=1

t=2

t=3t=4

t=5

t=6

Smoothing:wherewasIinthepast

Filtering:whereamInow

Page 7: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example:noisylocalization

https://img.clipartfest.com

Positionatt=0

Measurementatt=1

t=2

t=3t=4

t=5

t=6

Smoothing:wherewasIinthepast

Filtering:whereamInow

Prediction:wherewillIbeinthefuture

Page 8: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Today’slecture• Fundamentals• Formalizingtimeseriesmodels• Recursivefiltering

• Twocaseswithoptimalsolutions• LinearGaussianmodels• Discretesystems

• Suboptimalsolutions

Page 9: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

StochasticProcesses

• Stochasticprocess– Collectionofrandomvariablesindexedbysomeset– Ie.R.V.𝑥" foreveryelement𝑖 inindexset

• Timeseriesmodeling– Sequenceofrandomstates/variables– Measurementsavailableatdiscretetimes– Modeledasstochasticprocessindexedbyℕ

Page 10: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

StochasticProcesses

• Stochasticprocess– Collectionofrandomvariablesindexedbysomeset– Ie.R.V.𝑥" foreveryelement𝑖 inindexset

• Timeseriesmodeling– Sequenceofrandomstates/variables– Measurementsavailableatdiscretetimes– Modeledasstochasticprocessindexedbyℕ

𝑥$ (locationatt=1)

𝑝(𝑥$)

Page 11: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

StochasticProcesses

• Stochasticprocess– Collectionofrandomvariablesindexedbysomeset– Ie.R.V.𝑥" foreveryelement𝑖 inindexset

• Timeseriesmodeling– Sequenceofrandomstates/variables– Measurementsavailableatdiscretetimes– Modeledasstochasticprocessindexedbyℕ

𝑝(𝑥$)

𝑝(𝑥()

𝑝(𝑥))

Page 12: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

(First-order)Markovprocess

• TheMarkovproperty– thelikelihoodofafuturestatedependsonpresentstateonly

• Markovchain– AstochasticprocesswithMarkovproperty

k-1 k k+1 timexk-1 xk xk+1 States

Page 13: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

HiddenMarkovModel(HMM)

• thestateisnotdirectlyvisible,butoutputdependentonthestateisvisible

k-1 k k+1 timexk-1 xk xk+1 States

(hidden)

zk-1 zk zk+1 Measurements(observed)

Page 14: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Statespace

• Thestatevectorcontainsallavailableinformationtodescribetheinvestigatedsystem– usuallymultidimensional:

• Themeasurementvectorrepresentsobservationsrelatedtothestatevector– Generally(butnotnecessarily)oflowerdimensionthanthestatevector

Page 15: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Statespace

• Tracking: Econometrics:• Monetaryflow• Interestrates• Inflation• …

Page 16: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

HiddenMarkovModel(HMM)

• thestateisnotdirectlyvisible,butoutputdependentonthestateisvisible

k-1 k k+1 timexk-1 xk xk+1 States

(hidden)

zk-1 zk zk+1 Measurements(observed)

Page 17: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

DynamicSystem

Stateequation:statevectorattimeinstantkstatetransitionfunction,i.i.dprocessnoise

Observationequation:observationsattimeinstantkobservationfunction,i.i.dmeasurementnoise

k-1 k k+1xk-1 xk xk+1

zk-1 zk zk+1Stochasticdiffusion

Page 18: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Asimpledynamicsystem• (4-dimensionalstatespace)• Constantvelocitymotion:

• Onlypositionisobserved:

Page 19: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Gaussiandistribution

μ

YacovHel-Or

Page 20: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Today’slecture• Fundamentals• Formalizingtimeseriesmodels• Recursivefiltering

• Twocaseswithoptimalsolutions• LinearGaussianmodels• Discretesystems

• Suboptimalsolutions

Page 21: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Recursivefilters• Formanyproblems,estimateisrequiredeachtimeanewmeasurementarrives

• Batch processing– Requiresall availabledata

• Sequential processing– Newdataisprocesseduponarrival– Neednotstorethecompletedataset– Neednotreprocessalldataforeachnewmeasurement

– Assumenoout-of-sequencemeasurements(solutionsforthisexistaswell…)

Page 22: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Bayesianfilter• Constructtheposteriorprobabilitydensityfunctionofthestatebasedonallavailableinformation

• Byknowingtheposteriormanykindsofestimatesfor canbederived– mean(expectation),mode,median,…– Canalsogiveestimationoftheaccuracy(e.g.covariance)

ThomasBayes

Samplespace

Posterior

Page 23: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

RecursiveBayesfilters

• Given:– Systemmodelsinprobabilisticforms

(knownstatisticsofvk,wk)– Initialstate alsoknownastheprior–Measurements

Markovianprocess

Measurementsconditionallyindependentgivenstate

𝑧$, … , 𝑧-

Page 24: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

RecursiveBayesfilters• Predictionstep(a-priori)

– Usesthesystemmodeltopredictforward– Deforms/translates/spreadsstatepdfduetorandomnoise

• Updatestep(a-posteriori)

– Updatethepredictioninlightofnewdata– Tightensthestatepdf

Page 25: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Priorvsposterior?

• Itcanseemoddtoregard𝑝 𝑥- 𝑧$:-/$ asprior• Compare

to

• Inupdatewith𝑧-,itisaworkingprior

𝑃(𝑥-|𝑧-, 𝑧$:-/$ ) =𝑝 𝑧- 𝑥-, 𝑧$:-/$ 𝑃(𝑥-|𝑧$:-/$)

𝑝(𝑧-|𝑧$:-/$)

posteriorlikelihood prior

evidence

𝑃(𝑥-|𝑧-, 𝑧$:-/$) =𝑝 𝑧- 𝑥-, 𝑧$:-/$ 𝑃(𝑥-|𝑧$:-/$)

𝑝(𝑧-|𝑧$:-/$)

Page 26: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Generalprediction-updateframework

• Assume isgivenattimek-1• Prediction:

• UsingChapman-Kolmogorovidentity+Markovproperty

(1)

PreviousposteriorSystemmodel

Page 27: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Generalprediction-updateframework

• Updatestep

Where

(2)

Measurementmodel

Currentprior

Normalizationconstant

Page 28: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Generatingestimates

• Knowledgeof enablestocomputeoptimalestimatewithrespecttoanycriterion.e.g.–Minimummean-squareerror(MMSE)

–Maximuma-posteriori

Page 29: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Generalprediction-updateframework

➔So(1)and(2)giveoptimalsolutionfortherecursiveestimationproblem!

• Unfortunately…onlyconceptualsolution– integralsareintractable…– Cannotrepresentarbitrarypdfs!

• However,optimalsolutiondoes existforseveralrestrictivecases

Page 30: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Today’slecture• Fundamentals• Formalizingtimeseriesmodels• Recursivefiltering

• Twocaseswithoptimalsolutions• LinearGaussianmodels• Discretesystems

• Suboptimalsolutions

Page 31: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Restrictivecase#1

• PosteriorateachtimestepisGaussian– Completelydescribedbymeanandcovariance

• If isGaussianitcanbeshownthatisalsoGaussianprovidedthat:

– areGaussian– arelinear

Page 32: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Restrictivecase#1

• WhyLinear?

YacovHel-Or

Page 33: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Restrictivecase#1

• WhyLinear?

YacovHel-Or

Page 34: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Restrictivecase#1

• Linearsystemwithadditivenoise

• Simpleexampleagain

/$

/$

Page 35: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheKalmanfilter

• Substitutinginto(1)and(2)yieldsthepredictandupdateequations

RudolfE.Kalman

Page 36: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheKalmanfilter

Predict:

Update:

Page 37: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Intuitionvia1Dexample

• Lostatsea– Night– Noideaoflocation– Forsimplicity– let’sassume1D

– Notmoving

*ExampleandplotsbyMaybeck,“Stochasticmodels,estimationandcontrol,volume1”

Page 38: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example– cont’d

• Timet1:StarSighting– Denotez(t1)=z1

• Uncertainty(inaccuracies,humanerror,etc)– Denoteσ1(normal)

• Canestablishtheconditionalprobabilityofx(t1)givenmeasurementz1

Page 39: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example– cont’d

• Probabilityforanylocation,basedonmeasurement• ForGaussiandensity– 68.3%within±σ1• Bestestimateofposition:Mean/Mode/Median

Page 40: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example– cont’d

• Timet2:friend(moretrained)– x(t2)=z2,σ(t2)=σ2– Sinceshehashigherskill:σ2<σ1

Page 41: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example– cont’d

• f(x(t2)|z1,z2)alsoGaussian

Page 42: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example– cont’d

• σ lessthanbothσ1andσ2• σ1=σ2:average• σ1>σ2:moreweighttoz2• Rewrite:

Page 43: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Example– cont’d

• TheKalmanupdaterule:

BestPredictionpriortoz2(apriori)

OptimalWeighting(KalmanGain)

Residual

BestestimateGivenz2

(aposteriori)

Page 44: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheKalmanfilter

Predict:

Update:Generallyincreases

variance

Generallydecreasesvariance

Page 45: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Kalmangain

• Smallmeasurementerror,𝐻 invertible:

• Smallpredictionerror:

Page 46: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheKalmanfilter• Pros (comparedtoe.g.particlefilter)– Optimalclosed-formsolutiontothetrackingproblem(undertheassumptions)• Noalgorithmcandobetterinalinear-Gaussianenvironment!

– All‘logical’estimationscollapsetoauniquesolution– Simpletoimplement– Fasttoexecute

• Cons– Ifeitherthesystemormeasurementmodelisnon-linearà theposteriorwillbenon-Gaussian

Smoothingpossiblewithabackwardmessage

(cf HMMs,lecture10)

Page 47: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Restrictivecase#2

• Thestatespace(domain)isdiscreteandfinite• Assumethestatespaceattimek-1consistsofstates

• Let betheconditionalprobabilityofthestateattimek-1,givenmeasurementsuptok-1

Page 48: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheGrid-basedfilter

• Theposteriorpdfatk-1canbeexpressedassumofdeltafunctions

• Again,substitutioninto(1)and(2)yieldsthepredictandupdateequations

EquivalenttobeliefmonitoringinHMMs

(Lecture10)

Page 49: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheGrid-basedfilter• Prediction

• Newpriorisalsoweightedsumofdeltafunctions• Newpriorweightsarereweightingofoldposteriorweightsusingstatetransition

probabilities

(1)

Page 50: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheGrid-basedfilter• Update

• Posteriorweightsarereweightingofpriorweightsusinglikelihoods(+normalization)

(2)

Page 51: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheGrid-basedfilter

• Pros:– assumedknown,butnoconstraintontheir(discrete)shapes

– Easyextensiontovaryingnumberofstates– Optimalsolutionforthediscrete-finiteenvironment!

• Cons:– Curseofdimensionality

• Inefficientifthestatespaceislarge– Staticallyconsidersall possiblehypotheses

Smoothingpossiblewithabackwardmessage

(cf HMMs,lecture10)

Page 52: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Today’slecture• Fundamentals• Formalizingtimeseriesmodels• Recursivefiltering

• Twocaseswithoptimalsolutions• LinearGaussianmodels• Discretesystems

• Suboptimalsolutions

Page 53: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Suboptimalsolutions• Inmanycasestheseassumptionsdonothold– Practicalenvironmentsarenonlinear,non-Gaussian,continuous

➔Approximationsarenecessary…

– ExtendedKalmanfilter(EKF)– Approximategrid-basedmethods– Multiple-modelestimators– UnscentedKalmanfilter(UKF)– Particlefilters(PF)– …

Analyticapproximations

Samplingapproaches

Numericalmethods

Gaussian-sumfilters

Page 54: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheextendedKalmanfilter

• Theidea:locallinearizationofthedynamicsystemmightbesufficientdescriptionofthenonlinearity

• Themodel:nonlinearsystemwithadditivenoise

Page 55: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheextendedKalmanfilter

• f,hareapproximatedusingafirst-orderTaylorseriesexpansion(evalatstateestimations)

Predict:

Update:

Page 56: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheextendedKalmanfilter

Page 57: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheextendedKalmanfilter• Pros– Goodapproximationwhenmodelsarenear-linear– Efficienttocalculate(defactomethodfornavigationsystemsandGPS)

• Cons– Onlyapproximation(optimalitynotproven)– StillasingleGaussianapproximations

• Nonlinearityà non-Gaussianity(e.g.bimodal)– Ifwehavemultimodalhypothesis,andchooseincorrectly– canbedifficulttorecover

– Inapplicablewhenf,h discontinuous

Page 58: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

TheunscentedKalman filter

• CangivemoreaccuratelyapproximatesposteriorYacovHel-Or

Page 59: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Challenges• Detectionspecific– Full/partialocclusions– Falsepositives/falsenegatives– Entering/leavingthescene

• Efficiency• Multiplemodelsandswitchingdynamics• Multipletargets• …

Page 60: Kalman filtering and friends: Inference in time series modelsdprecup/courses/ML/Lectures/ml-lecture17.pdf · Kalman filtering and friends: Inference in time series models Herke van

Conclusion• Inferenceintimeseriesmodels:• Past:smoothing• Present:filtering• Future:prediction

• RecursiveBayesfilteroptimal• Computableintwocases• LinearGaussiansystems:Kalman filter• Discretesystems:Gridfilter

• Approximatesolutionsforothersystems