test_HMM.praat 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # test_HMM.praat
  2. appendInfoLine: "test_HMM"
  3. @mm
  4. @hmms_test_multiple_os
  5. # two state not hidden model
  6. procedure mm
  7. .mm1 = Create simple HMM: "m1", "no", "1 2", ""
  8. Set transition probabilities: 1, "0.8 0.2"
  9. Set transition probabilities: 2, "0.4 0.6"
  10. # check sum of p leaving
  11. for .it to 10
  12. .psum = 0
  13. for .istate to 2
  14. .lnp = Get p (time, state): .it , .istate
  15. .p = exp(.lnp)
  16. .psum += .p
  17. endfor
  18. assert (.psum>0.999 and .psum<1.001)
  19. endfor
  20. .os = To HMMObservationSequence: 0, 2000
  21. .mm2 = To HMM: 0, "no"
  22. plusObject: .os
  23. Learn: 0.001, 0.00000001, "no"
  24. selectObject: .mm2
  25. # check sum of p leaving
  26. for .it to 10
  27. .psum = 0
  28. for .istate to 2
  29. .p = Get p (time, state): .it, .istate
  30. .p = exp(.p)
  31. .psum += .p
  32. endfor
  33. assert (.psum>0.999 and .psum<1.001)
  34. endfor
  35. removeObject: .mm1, .mm2, .os
  36. endproc
  37. procedure hmms_test_multiple_os
  38. .hmm = Create simple HMM: "hmm1", "no", "1 2 3", ""
  39. Set transition probabilities: 1, "0.5 0.1 0.4"
  40. Set transition probabilities: 2, "0.3 0.5 0.2"
  41. Set transition probabilities: 3, "0.4 0.1 0.5"
  42. .os = To HMMObservationSequence: 0, 20000
  43. .s = To Strings
  44. .s1 = Extract part: 1, 10001
  45. .os1 = To HMMObservationSequence
  46. selectObject: .s
  47. .s2 = Extract part: 10002, 20000
  48. .os2 = To HMMObservationSequence
  49. .hmm2 = Create simple HMM: "hmm3", "no", "1 2 3", ""
  50. selectObject: .hmm2, .os1, .os2
  51. Learn: 0001, 0.00000001, "no"
  52. removeObject: .s, .s1, .s2, .hmm2, .os, .os1, .os2, .hmm
  53. endproc
  54. appendInfoLine: "test_HMM OK"