25
Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik Madsen Lecture Notes September 2016 Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 1 / 15

Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Modelling Non-linear and Non-stationary TimeSeries

Chapter 7(extra):(Generalized) Hidden Markov Models

Henrik Madsen

Lecture Notes

September 2016

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 1 / 15

Page 2: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Hidden Markov ModelFirst Order Markov Property

p(Xt|Xt−1) = p(Xt|X (t−1)), t ∈ N (1)

p(Yt|Xt) = p(Yt|X (t),Y(t−1)), t ∈ N (2)

X1 X2 X3 X4

Y1 Y2 Y3 Y4

Figure : Directed graph of basic HMM. The index denotes time.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 2 / 15

Page 3: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Markov Chains

Discrete state vector at time t, Xt, with m states.

Transition probabilityp(Xt = j|Xt−s = i) (3)

One-step transition probability

γij,t = p(Xt = j|Xt−1 = i) (4)

One-step transition probability matrix from time t − 1 to t

Γt =

γ11,t · · · γ1m,t...

. . ....

γm1,t · · · γmm,t

(5)

where the rows must sum to 1.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 3 / 15

Page 4: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Generalized State Space Models (GSSM)

Parameter driven - model evolve independently of the pastobservation process.

p(yt|xt) = p(yt|xt,X (t−1),Y(t−1)

)(6a)

p(xt+1|xt) = p(xt+1|xt,X (t−1),Y(t)

)(6b)

Observation driven - model depends on the past observationprocess.

p(yt|xt) = p(yt|xt,X (t−1),Y(t−1)

)(7a)

p(xt+1|Y(t)

)= p

(xt+1|xt,X (t−1),Y(t)

)(7b)

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 4 / 15

Page 5: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Model ValidationLikelihood Setting

Forward SelectionMaximum of 5 states and model chosen by AIC

AIC = −2L+ 2p (8)

Forecast Pseudo Residuals

zt = Φ−1 (p (Yt ≤ yt|Y(t−1)))

(9)

Marginal distribution

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 5 / 15

Page 6: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

DataIC-Meter

Table : 5-Minute Variables.

Dataset Feature (type) Unit Description

Indoor-Minutes Datetime Date and time

Indoor-Minutes Temperature In ◦C Indoor temperature

Indoor-Minutes Humidity In % Indoor humidity

Indoor-Minutes CO2 In ppm Indoor CO2 content

Indoor-Minutes Noise Avg DB Average noise level (5 min)

Indoor-Minutes Noise Peak DB Largest average of 3 subse-quent measurement (15 secper measurement)

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 6 / 15

Page 7: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 8: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Homogen HMMOriginal Scale

Setting

yt = CO2,t

p(xt|xt−1) ∼ Γ

p(yt|xt) ∼ N(µi, σ

2i)

for i = 1, 2, · · · ,m

Results

Table : Comparison of univariate homogen HMMs for 2 to 5 states.

L p AIC BIC2 states -97903 6 195818 1958643 states -91239 12 182502 1825954 states -87492 20 175023 1751785 states -83968 30 167995 168227

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 9: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Homogen HMMOriginal Scale

Table : Fit of the HMM (CO2) with 5 states.

δi µi σi γi1 γi2 γi3 γi4 γi5

State 1 0.21 410.79 6.88 0.99 0.01 0.01 0.00 0.00State 2 0.18 432.00 7.42 0.02 0.94 0.04 0.00 0.00State 3 0.20 477.92 24.17 0.00 0.05 0.90 0.05 0.00State 4 0.23 618.45 68.26 0.00 0.00 0.05 0.92 0.03State 5 0.18 1013.61 267.72 0.00 0.00 0.00 0.04 0.96

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 10: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Figure : Global Decoding of the HMM (CO2) with 5 states. Top is the entire time series. Bottom iszoomed in on one day. Vertical lines indicate 00:00. Horizontal lines indicate the state dependentmean.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 11: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Figure : Fit of the HMM (CO2) with 5 states.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 12: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Homogen HMMTransformed Scale

h(y) = log(y− 350)

Setting

yt = h(CO2,t)

p(xt|xt−1) ∼ Γ

p(yt|xt) ∼ N(µi, σ

2i)

for i = 1, 2, · · · ,m

Results

Table : Comparison of univariate (log transformed CO2) homogen HMMs for 2 to 5states.

L p AIC BIC2 states -9378 6 18768 188143 states -4292 12 8609 87014 states -800 20 1640 17955 states 2181 30 -4303 -4071

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 13: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Figure : Fit of the HMM (log CO2) with 5 states.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 14: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Generalized FormHierarchical Model

p(yt|xt,θ)

p(xt+1|xt,θ

)Hierarchical model by random effects

Y|(U = u) ∼ fY|u(y; u,β

)(10a)

U ∼ fU(u;Ψ

)(10b)

The likelihood is given by

L(β,Ψ; y, u

)= f

(y;θ

)= f

(y, u;β,Ψ

)= fY|u

(y; u,β

)fU

(u;Ψ

)(11)

The distribution f(y, u;β,Ψ

)is given by an exponential dispersion model with density

given by Equation (??) with canonical link η = h(µ).The random effect is given by fU

(u;Ψ

)and the conditional likelihood by fY|u

(y; u,β

).

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 15: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Transition Probability Matrix with Covariates

Γt =

exp(XT

D,tβ11 + ZU11)

exp(XTD,tβ11 + ZU11) +

∑j6=1 exp(τ1j)

· · ·exp(τ1m)

exp(XTD,tβ11 + ZU11) +

∑j6=1 exp(τ1j)

.... . .

...exp(τm1)

exp(XTD,tβmm + ZUmm) +

∑j6=m exp(τmj)

· · ·exp(XT

D,tβmm + ZUmm)

exp(XTD,tβmm + ZUmm) +

∑j6=m exp(τmj)

(12)

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 16: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Figure : Periodic Splines. The knots are indicated on the x-axis.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 17: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Inhomogen HMMTransformed Scale

Setting

yt = h(CO2,t)

p(xt|xt−1) ∼ Γt

p(yt|xt) ∼ N(µi, σ

2i)

for i = 1, 2, · · · ,m

Results

Table : Comparison of univariate (log transformed CO2) inhomogen HMMs for 2 to 5states.

L p AIC BIC2 states -9319 14 18667 187753 states -4229 24 8506 86924 states -742 36 1556 18355 states 2258 50 -4417 -4030

Same trend in residuals - not appropriate

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 7 / 15

Page 18: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Markov Switching AR(1)

p(xt+1|xt) = p(xt+1|xt,X (t−1),Y(t)

)(13a)

p(yt|xt, yt−1) = p(yt|xt,X (t−1),Y(t−1)

)(13b)

Xt−1 Xt Xt+1 Xt+2

Yt−1 Yt Yt+1 Yt+2

Figure : Directed graph of Markov switching AR(1).

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 8 / 15

Page 19: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Inhomogen Markov Switching AR(1)Transformed Scale

Setting

yt = h(CO2,t)

p(xt|xt−1) ∼ Γt

p(yt|xt, yt−1) ∼ N(ci + φiyt−1 , σ

2i)

for i = 1, 2, · · · ,m

Results

Table : Comparison of univariate (log transformed CO2) inhomogen AR(1) for 2 to 5states.

L p AIC BIC2 states 15845 16 -31659 -315353 states 16204* 27 -32354 -321454 states 16964 40 -33848 -335385 states 17336 55 -34561 -34136

Residuals - appropriate for 4 and 5 state model!!

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 9 / 15

Page 20: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Final Model - 5 statesResiduals

Figure : Model diagnostics of the final model.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 10 / 15

Page 21: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Final ModelMarginal Distribution

Figure : Comparison of the distribution of the measured CO2 and the simulated distribution.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 11 / 15

Page 22: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Final ModelInterpretation of the states

State 1: Absence or sleepingState 2: Long term absenceState 3: Outdoor interactionState 4: Presence (high activity)State 5: Presence (long term, low activity)

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 12 / 15

Page 23: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Figure : Transition probabilities over the day of the final model. The lower right plot isthe stationary distribution.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 13 / 15

Page 24: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Figure : Profile of the states over the course of the day. I.e. Stackedstationary probabilities over the course of the day of the final model.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 14 / 15

Page 25: Modelling Non-linear and Non-stationary Time Series · 2016-09-28 · Modelling Non-linear and Non-stationary Time Series Chapter 7(extra): (Generalized) Hidden Markov Models Henrik

Figure : Global Decoding of the final model. Top is the entire time series. Bottom iszoomed in on one day. Vertical lines indicate 00:00. Horizontal lines indicate the statedependent mean.

Henrik Madsen (02427 Adv. TS Analysis) Lecture Notes September 2016 15 / 15