๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐“ก๐“ธ๐“ธ๐“ถ5: ๐’ฆ๐‘œ๐“‡๐‘’๐’ถ ๐’ฐ๐“ƒ๐’พ๐“‹/Artificial Intelligence(COSE361)

[์ธ๊ณต์ง€๋Šฅ] 16. Hidden Markov Models (HMM)

1. Definition of Hidden Markov Model : ์‹œ๊ฐ„์˜ ๊ฐœ๋…์ด ํฌํ•จ๋œ ํ™•๋ฅ  ๋ชจ๋ธ

  - single discrete random variable๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋Š” probabilistic model. 

  - state variable Xt ๋Š” ์ •์ˆ˜ 1, ... , S๋ฅผ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์œผ๋ฉฐ, S๋Š” ๊ฐ€๋Šฅํ•œ states์˜ ์ˆ˜์ด๋‹ค.

  - transition model P(Xt|Xt-1) ์€ S*S์˜ matrix T์ด๋‹ค. (T_ij = P(Xt = j | X_t-1 = i) 

  - evidence variable Et๋Š” ๊ฐ state์—์„œ specifyํ•˜๊ณ , ๊ฐ state i์—์„œ P(et | Xt = i) ๋ฅผ ํ†ตํ•ด state๊ฐ€ et๋ฅผ ์•ผ๊ธฐํ•˜๋Š”์ง€์— ๋Œ€ํ•ด ์•Œ ์ˆ˜ ์žˆ๋‹ค. ์ด value๋Š” ํŽธ์˜์ƒ S*S์˜ diagonal matrix Ot๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. i๋ฒˆ์งธ entry๊ฐ€ ๋ฐ”๋กœ P(et|Xt = i) ์ด๋‹ค. ๋‚˜๋จธ์ง„ ๋‹ค 0

 

transition matrix๋ฅผ ๋ณด๋ฉด, column์€ ํ˜„์žฌ state, row๋Š” ๊ทธ ์ „ state์ž„. ๊ทธ๋ž˜์„œ ํ˜„์žฌ STATE๊ฐ€ true์ผ ๋•Œ ์ง„๋ฆฌ๊ฐ’์€ ์ง€๋‚œ state์—์„œ t/f ์—ฌ๋ถ€์— ๋”ฐ๋ฅธ vector๋กœ ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์Œ. 

 

sensor model matrix๋ฅผ ๋ณด๋ฉด column์ด ํ˜„์žฌ state์˜ ์ง„๋ฆฌ๊ฐ’ t/f, row๊ฐ€ ๊ทธ์— ๋”ฐ๋ฅธ effect๊ฐ€ true์ผ ํ™•๋ฅ  

 

2. Forward-Backward Algorithms

 1) Forward Backward Messages

   - Forward Messages

 filtering : P(Xt|e_1:t) = f_1:t = αP(et | Xt)∑P(Xt|x_t-1) P(x_t-1 | e_ 1:t-1)

์—ฌ๊ธฐ์„œ sensor matrix์™€ transition matrix ๋ฅผ ํ–‰๋ ฌ๋กœ ์จ์„œ ํ•œ๋ฒˆ์— ๊ณ„์‚ฐํ•˜๋Š” ๊ฒƒ์ด ๋ฐ”๋กœ forward message

 

 f_1:t = α(sensor matrix) * (transition matrix์˜ transpose) * f_1:t-1

 

  - Backward Message

  P(e_k+1:t|Xk) = b_k+1:t = ∑ P(x_kx+1|Xk) P(e_k+1 | x_k+1) P(e_k+2:t | x_k+1)

  b_k+1:t = (transition matrix) * (sensor matrix) * b_k+2:t

 

  - Forward-Backward Algorithm 

  -> time complexity : O(S^2t) (SxS matrix, time t)

  -> space complexity : O(St) 

 

 2) Constant-space Forward-Backward Algorithm

"forward" message f ๋Š” backward๋กœ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค! ์ฆ‰, ํ˜„์žฌ time์˜ forward message(t-1)๋Š” ๋‹ค์Œ time์˜ ๊ฒƒ(t)์œผ๋กœ ๊ตฌํ•  ์ˆ˜ ์žˆ๋‹ค. 

  f_1:t = αOtT^t f_1:t-1

 ==> 1/α T^(-1) Ot^(-1) f_1:t = f_1:t-1

 

์ด๊ฑธ ์ด์šฉํ•ด์„œ smoothing algorithm์„ ์ˆ˜์ •ํ•  ์ˆ˜ ์žˆ์Œ

์›๋ž˜๋Š” forward message์—์„œ t-10, ... t-1, t๋ฅผ ๋‹ค ๊ตฌํ•ด์„œ ๊ธฐ์–ตํ•˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ, ์ด์ œ๋Š” t๊นŒ์ง€ ๊ธฐ์–ต ์•ˆํ•˜๊ณ  ๋‹ค ๊ณ„์‚ฐํ•œ ๋‹ค์Œ์—, backward message์ฒ˜๋Ÿผ ๊ฑฐ๊พธ๋กœ ๋˜๋Œ์•„๊ฐ€๋ฉด์„œ ๊ฐ’์„ ๊ตฌํ•ด๋ƒ„ 

 

๊ทธ๋ž˜์„œ t๊ฐ’๊ณผ ๊ด€๊ณ„์—†์ด ํ•ญ์ƒ space complexity๊ฐ€ constantํ•˜๋‹ค!!!! 

 

 

 3) Fixed-Lag Forward-Backward Algorithm

 

์šฐ๋ฆฌ๊ฐ€ t๊นŒ์ง€์˜ evidence๋ฅผ ์•Œ๊ณ  ์žˆ์–ด์„œ ์ด๊ฑธ๋กœ t-d ์‹œ์ ์˜ state๋ฅผ ๊ตฌํ–ˆ๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ณด์ž. ๊ทธ๋ ‡๋‹ค๋ฉด ์šฐ๋ฆฌ๋Š”

P(X_t-d | e_1:t) = α f_1:t-d * b_t-d+1:t 

์„ ํ†ตํ•ด ๊ตฌํ•  ์ˆ˜ ์žˆ๊ฒ ์ง€?

๊ทผ๋ฐ ์ด ์ƒํ™ฉ์—์„œ ์ƒˆ๋กœ์šด observation์ด ๋„์ฐฉํ•œ๊ฑฐ์•ผ. ๊ทธ๋ž˜์„œ ์ด์   t-d+1์‹œ์ , ์ฆ‰ ๊ตฌํ•œ ์‹œ์ ์˜ state๋ณด๋‹ค ํ•œ ์นธ ํ›„์˜ state์„ ๊ตฌํ•˜๊ณ  ์‹ถ์€๊ฑฐ์ง€. 

 

์›๋ž˜๋Š” ์ด ๋•Œ t+1์„ ๊ตฌํ•œ๋‹ค์Œ์— ๋‹ค์‹œ -d๋ฅผ ํ•ด์ฃผ๋Š” ์ž‘์—…์„ ํ–ˆ์–ด์•ผ ํ–ˆ๋Š”๋ฐ, ์ด๊ฑธ ์ข€ ๋” ํšจ์œจ์ ์œผ๋กœ ๋ฐ”๊ฟ€๊ฑฐ์•ผ? ์–ด๋–ป๊ฒŒ? t-d๋ฅผ ์ด์šฉํ•ด์„œ!

 

t+1-d ๋Š” t-d์— +1 ํ•œ ๊ฐ’์ด์ง€? ๊ทธ๋ž˜์„œ ๊ตณ์ด ๋‹ค์‹œ t+1๋กœ ์•ˆ๋„˜์–ด๊ฐ€๊ณ  t-d์—์„œ ๋ฐ”๋กœ t-d+์„ ๊ตฌํ•  ๊ฒƒ์ด๋‹ค!

 

f_1:t+1-d๋Š” ์• ์ดˆ์— forward๋ผ์„œ filtering์„ ํ†ตํ•ด f_1:t-d๋ฅผ ํ†ตํ•ด ๊ตฌํ•  ์ˆ˜ ์žˆ์œผ๋‹ˆ๊นŒ ok~

 

b_(t+1-d : t+1)์€ ์–ด๋–ป๊ฒŒ ํ•  ๊ฑฐ๋ƒ~ 

b_(k+1 : t) = TO_(k+1)b_(k+2:t) 

b_(t+1-d : t) = TO_(t+1-d)b_(t+2-d : t) = TO_(t+1-d){TO_(t+2-d)b_(t-d+3 : t) = .....

b_(t+1-d : t) = ( ∏(t, i=t-d+1) TO_i )* b_(t+1:t) = B_(t-d+1:t) * 1

 

b_(t+2-d : t) = ( ∏(t+1, i=t-d+2) TO_i )* b_(t+2:t+1) = B_(t-d+2:t+1) * 1

 

์—ฌ๊ธฐ์„œ B_(t-d+1 : t) ์— ๋Œ€ํ•ด ์“ฐ๊ณ  ์‹ถ์œผ๋ฉด

b_(t+2-d : t) = (O_(t-d+1)) ^(-1) * T^(-1) * B_(t-d+1:t) * TO_(t+1) * 1

 

 

3. Viterbi Algorithm

 

- sudo code 

 

4. Applications

 

 1) erroneous sensor  

 

๋กœ๋ด‡์˜ ์œ„์น˜๋ฅผ ํŒŒ์•…ํ•˜๋Š” ๋ฌธ์ œ ๊ธฐ์–ต๋‚˜๋‚˜์š” ๊ทธ๊ฑฐ ๋‹ค์‹œ ๋‚˜์˜ด

 

- state variable Xt : ๋กœ๋ด‡์˜ ํ˜„์žฌ ์œ„์น˜๋ฅผ ๋‚˜ํƒ€๋ƒ„

- transition model : ๋กœ๋ด‡์ด i๋ฒˆ์งธ ์นธ์—์„œ j๋ฒˆ์งธ ์นธ์œผ๋กœ ์˜ฎ๊ฒจ๊ฐˆ ํ™•๋ฅ 

  P(X_(t+1) = j | Xt = i) - Tij = 1/N(i) or 0

- ๋กœ๋ด‡์ด ์–ด๋””์„œ ์‹œ์ž‘ํ•  ์ง€ ๋ชจ๋ฅด๋‹ˆ๊นŒ ๊ฐ squares์— ์žˆ์„ ํ™•๋ฅ ์„ P(X0=i) = 1/n ์œผ๋กœ ๋ชจ๋‘ ๊ฐ™๋‹ค๊ณ  ๊ฐ€์ •

- sensor variable Et : ์ด 16๊ฐœ์˜ ๊ฐ’(2*2*2*2)์„ ๊ฐ€์งˆ ์ˆ˜ ์žˆ์Œ. ๊ฐ ๋ฐฉํ–ฅ ๋™์„œ๋‚จ๋ถ์— ์žฅ์• ๋ฌผ์ด ์—†๋Š”์ง€ ์žˆ๋Š”์ง€!

- sensor๊ฐ€ ํ‹€๋ฆด ํ™•๋ฅ ์„ ε๋ผ๊ณ  ํ•˜์ž. ๋ชจ๋“  ๋ฐฉํ–ฅ์— ๋Œ€ํ•œ sensor๋Š” ๋ชจ๋‘ ๋…๋ฆฝ์ ์ด๋ฏ€๋กœ ๋ชจ๋“  ๋ฐฉํ–ฅ์ด ๋‹ค ํ‹€๋ฆด ํ™•๋ฅ ์€ ε^4 ์ด๊ณ , ๋„ค ๋ฐฉํ–ฅ์ด ๋ชจ๋‘ ๋งž์„ ํ™•๋ฅ ์€ (1-ε)^4 ์ด๋‹ค.  

- ๋”ฐ๋ผ์„œ ๋กœ๋ด‡์ด state i์— ์žˆ์„ ๋•Œ ์‚ฌ์‹ค๋Œ€๋กœ et๋ฅผ ๊ด€์ธกํ•  ํ™•๋ฅ ์€ (1-ε)^(4-d_it) * ε^(d_it) ๊ฐ€ ๋œ๋‹ค.

 

  2) Inference for Robot Localization 

 - Filtering to estimate its current location

 P(X1 | E1 =  NSW): NSW์„ ๊ด€์ธกํ–ˆ์„ ๋•Œ ๋กœ๋ด‡์ด x1์— ์žˆ์„ ํ™•๋ฅ 

 - Smoothing : ๊ณผ๊ฑฐ์˜ ๋กœ๋ด‡ ์œ„์น˜๋ฅผ ์•Œ๊ณ  ์žˆ๋‹ค๋ฉด ์Šค๋ฌด๋”ฉ์„ ํ™œ์šฉํ•˜์ž

 - Viterbi algorithm : ๋กœ๋ด‡์ด ์–ด๋–ค ๊ฒฝ๋กœ๋กœ ์ง€๊ธˆ๊นŒ์ง€ ์™”๋Š”์ง€๋ฅผ ์•Œ์•„๋ณด์ž

 

 -> ๊ด€์ธกํ•˜๋ฉด ํ•  ์ˆ˜๋ก error๊ฐ€ ์ค„์–ด๋“ค์–ด์„œ ๋กœ๋ด‡์˜ ์œ„์น˜๋ฅผ ๋น ๋ฅด๊ฒŒ ์ฐพ์„ ์ˆ˜ ์žˆ๋‹ค. ๋˜ ๊ฒฝ๋กœ ์ •ํ™•๋„๋„ ๋†’์•„์ง„๋‹ค.