discriminant_tableofreal_mahalanobis.praat 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # discriminant_tableofreal_mahalanobis.praat
  2. # djmw 20100106
  3. # This scripts calculates the amount of overlap between two normal distributions
  4. # both distributions have sigma = 1
  5. # mu1 = 0 and mu2 varies from 1 to 5
  6. n = 20000
  7. t0 = Create TableOfReal... t0 n 1
  8. for i to n/2
  9. Set row label (index)... i 1
  10. endfor
  11. for i from n/2+1 to n
  12. Set row label (index)... i 2
  13. endfor
  14. for mu to 5
  15. select t0
  16. Formula... randomGauss ((if row < n/2 then 0 else mu fi), 1)
  17. d = To Discriminant
  18. for j to 2
  19. select d
  20. plus t0
  21. t'j' = To TableOfReal (mahalanobis)... 'j' n
  22. endfor
  23. tt = Copy... tt
  24. for nsigma to 5
  25. Formula... Object_'t1'[row,col] < nsigma and Object_'t2'[row,col] < nsigma
  26. nr = 0
  27. for kr to n
  28. if Object_'tt'[kr,1] = 1
  29. nr += 1
  30. endif
  31. endfor
  32. z12 = 0 + nsigma
  33. z21 = mu - nsigma
  34. expect = 0
  35. if z21 < z12
  36. # we have overlap
  37. expect = (gaussQ (z21) - gaussQ (z12)) * n
  38. endif
  39. diff = nr - expect
  40. printline For d='mu' and 'nsigma'-sigma: 'nr' from 'n' overlap; diff = 'diff:1' (expect = 'expect:1')
  41. endfor
  42. select d
  43. plus t1
  44. plus t2
  45. plus tt
  46. Remove
  47. endfor