Simulation d’un mélange de Poisson à 2 composantes

\[ \pi_1=0.4 \]

nks<-rmultinom(1,1000,c(0.4,0.6))
lambdas<-c(3,15)
x.z1<-rpois(nks[1],lambda=lambdas[1])
x.z2<-rpois(nks[2],lambda=lambdas[2])
ggplot(data = data.frame(x=seq(0,30),y=0.4*dpois(x=seq(0,30),lambdas[1])+0.6*dpois(x=seq(0,30),lambdas[2])), aes(x=x,y=y))+ geom_bar(stat="identity")

Algorithme EM associé

X<-data.frame(x=c(x.z1,x.z2))
K<-2
Init.parameters<-function(X,K=2){
  pis<-rep(1/K,K)
  lambdas<-X[sample(1:nrow(X),K),1]
  return(list(pis=pis,lambdas=lambdas))
}
parameters<-Init.parameters(X,2)
T<-matrix(1,nrow(X),K)
E.step<-function(X,parameters,T){
  for (k in 1:ncol(T)){
    T[,k]<-parameters$pis[k]*dpois(unlist(X),lambda=parameters$lambdas[k])
  }
  return(T=t(apply(T,1,function(x){x/sum(x)})))
}
T<-E.step(X,parameters,T)
M.step<-function(X,T){
  pis = apply(T,2,mean)
  lambdas<-colSums(T*(as.matrix(X)%*%rbind(rep(1,K))))/colSums(T)
  return(list(pis=pis,lambdas=lambdas))
}

M.step(X,T)
## $pis
## [1] 0.3725544 0.6274456
## 
## $lambdas
## [1]  2.619087 13.909171
T
##                 [,1]         [,2]
##    [1,] 9.998129e-01 1.870590e-04
##    [2,] 9.998129e-01 1.870590e-04
##    [3,] 9.999875e-01 1.247278e-05
##    [4,] 9.998129e-01 1.870590e-04
##    [5,] 9.999875e-01 1.247278e-05
##    [6,] 9.972014e-01 2.798556e-03
##    [7,] 6.129546e-01 3.870454e-01
##    [8,] 9.998129e-01 1.870590e-04
##    [9,] 9.999875e-01 1.247278e-05
##   [10,] 9.999992e-01 8.315280e-07
##   [11,] 9.998129e-01 1.870590e-04
##   [12,] 6.129546e-01 3.870454e-01
##   [13,] 4.690174e-04 9.995310e-01
##   [14,] 9.549610e-02 9.045039e-01
##   [15,] 9.998129e-01 1.870590e-04
##   [16,] 9.596044e-01 4.039564e-02
##   [17,] 9.999875e-01 1.247278e-05
##   [18,] 9.999992e-01 8.315280e-07
##   [19,] 9.596044e-01 4.039564e-02
##   [20,] 9.972014e-01 2.798556e-03
##   [21,] 9.998129e-01 1.870590e-04
##   [22,] 9.998129e-01 1.870590e-04
##   [23,] 9.999875e-01 1.247278e-05
##   [24,] 6.129546e-01 3.870454e-01
##   [25,] 9.972014e-01 2.798556e-03
##   [26,] 9.998129e-01 1.870590e-04
##   [27,] 9.998129e-01 1.870590e-04
##   [28,] 9.972014e-01 2.798556e-03
##   [29,] 9.549610e-02 9.045039e-01
##   [30,] 9.972014e-01 2.798556e-03
##   [31,] 9.999992e-01 8.315280e-07
##   [32,] 6.129546e-01 3.870454e-01
##   [33,] 9.999875e-01 1.247278e-05
##   [34,] 9.596044e-01 4.039564e-02
##   [35,] 9.596044e-01 4.039564e-02
##   [36,] 9.999875e-01 1.247278e-05
##   [37,] 9.999875e-01 1.247278e-05
##   [38,] 9.998129e-01 1.870590e-04
##   [39,] 9.999875e-01 1.247278e-05
##   [40,] 9.998129e-01 1.870590e-04
##   [41,] 9.999992e-01 8.315280e-07
##   [42,] 9.596044e-01 4.039564e-02
##   [43,] 9.596044e-01 4.039564e-02
##   [44,] 9.972014e-01 2.798556e-03
##   [45,] 9.596044e-01 4.039564e-02
##   [46,] 9.972014e-01 2.798556e-03
##   [47,] 9.999992e-01 8.315280e-07
##   [48,] 9.596044e-01 4.039564e-02
##   [49,] 9.972014e-01 2.798556e-03
##   [50,] 9.998129e-01 1.870590e-04
##   [51,] 6.989367e-03 9.930106e-01
##   [52,] 9.549610e-02 9.045039e-01
##   [53,] 9.549610e-02 9.045039e-01
##   [54,] 9.972014e-01 2.798556e-03
##   [55,] 9.596044e-01 4.039564e-02
##   [56,] 3.128152e-05 9.999687e-01
##   [57,] 9.999875e-01 1.247278e-05
##   [58,] 9.972014e-01 2.798556e-03
##   [59,] 9.596044e-01 4.039564e-02
##   [60,] 9.596044e-01 4.039564e-02
##   [61,] 9.998129e-01 1.870590e-04
##   [62,] 9.998129e-01 1.870590e-04
##   [63,] 9.999875e-01 1.247278e-05
##   [64,] 9.998129e-01 1.870590e-04
##   [65,] 9.596044e-01 4.039564e-02
##   [66,] 9.596044e-01 4.039564e-02
##   [67,] 9.999875e-01 1.247278e-05
##   [68,] 9.999875e-01 1.247278e-05
##   [69,] 6.129546e-01 3.870454e-01
##   [70,] 9.972014e-01 2.798556e-03
##   [71,] 9.972014e-01 2.798556e-03
##   [72,] 9.596044e-01 4.039564e-02
##   [73,] 9.972014e-01 2.798556e-03
##   [74,] 9.972014e-01 2.798556e-03
##   [75,] 9.972014e-01 2.798556e-03
##   [76,] 9.999992e-01 8.315280e-07
##   [77,] 9.998129e-01 1.870590e-04
##   [78,] 9.972014e-01 2.798556e-03
##   [79,] 6.129546e-01 3.870454e-01
##   [80,] 9.596044e-01 4.039564e-02
##   [81,] 9.998129e-01 1.870590e-04
##   [82,] 9.972014e-01 2.798556e-03
##   [83,] 9.999875e-01 1.247278e-05
##   [84,] 6.129546e-01 3.870454e-01
##   [85,] 9.998129e-01 1.870590e-04
##   [86,] 9.972014e-01 2.798556e-03
##   [87,] 6.129546e-01 3.870454e-01
##   [88,] 9.972014e-01 2.798556e-03
##   [89,] 9.999992e-01 8.315280e-07
##   [90,] 6.129546e-01 3.870454e-01
##   [91,] 9.596044e-01 4.039564e-02
##   [92,] 9.998129e-01 1.870590e-04
##   [93,] 9.596044e-01 4.039564e-02
##   [94,] 9.972014e-01 2.798556e-03
##   [95,] 9.596044e-01 4.039564e-02
##   [96,] 9.972014e-01 2.798556e-03
##   [97,] 9.999875e-01 1.247278e-05
##   [98,] 9.999992e-01 8.315280e-07
##   [99,] 9.972014e-01 2.798556e-03
##  [100,] 6.129546e-01 3.870454e-01
##  [101,] 6.989367e-03 9.930106e-01
##  [102,] 9.998129e-01 1.870590e-04
##  [103,] 9.596044e-01 4.039564e-02
##  [104,] 6.129546e-01 3.870454e-01
##  [105,] 9.596044e-01 4.039564e-02
##  [106,] 9.596044e-01 4.039564e-02
##  [107,] 9.596044e-01 4.039564e-02
##  [108,] 6.129546e-01 3.870454e-01
##  [109,] 9.972014e-01 2.798556e-03
##  [110,] 9.998129e-01 1.870590e-04
##  [111,] 9.999875e-01 1.247278e-05
##  [112,] 9.596044e-01 4.039564e-02
##  [113,] 9.998129e-01 1.870590e-04
##  [114,] 9.998129e-01 1.870590e-04
##  [115,] 6.129546e-01 3.870454e-01
##  [116,] 9.998129e-01 1.870590e-04
##  [117,] 9.999875e-01 1.247278e-05
##  [118,] 9.998129e-01 1.870590e-04
##  [119,] 9.999875e-01 1.247278e-05
##  [120,] 9.972014e-01 2.798556e-03
##  [121,] 4.690174e-04 9.995310e-01
##  [122,] 9.972014e-01 2.798556e-03
##  [123,] 9.998129e-01 1.870590e-04
##  [124,] 9.972014e-01 2.798556e-03
##  [125,] 9.972014e-01 2.798556e-03
##  [126,] 9.972014e-01 2.798556e-03
##  [127,] 6.129546e-01 3.870454e-01
##  [128,] 9.972014e-01 2.798556e-03
##  [129,] 9.999875e-01 1.247278e-05
##  [130,] 9.596044e-01 4.039564e-02
##  [131,] 6.129546e-01 3.870454e-01
##  [132,] 9.998129e-01 1.870590e-04
##  [133,] 9.999875e-01 1.247278e-05
##  [134,] 9.998129e-01 1.870590e-04
##  [135,] 9.596044e-01 4.039564e-02
##  [136,] 6.129546e-01 3.870454e-01
##  [137,] 9.596044e-01 4.039564e-02
##  [138,] 9.998129e-01 1.870590e-04
##  [139,] 9.596044e-01 4.039564e-02
##  [140,] 9.999875e-01 1.247278e-05
##  [141,] 9.549610e-02 9.045039e-01
##  [142,] 9.972014e-01 2.798556e-03
##  [143,] 9.999875e-01 1.247278e-05
##  [144,] 9.596044e-01 4.039564e-02
##  [145,] 9.999875e-01 1.247278e-05
##  [146,] 9.972014e-01 2.798556e-03
##  [147,] 9.972014e-01 2.798556e-03
##  [148,] 9.998129e-01 1.870590e-04
##  [149,] 9.972014e-01 2.798556e-03
##  [150,] 9.972014e-01 2.798556e-03
##  [151,] 9.596044e-01 4.039564e-02
##  [152,] 9.596044e-01 4.039564e-02
##  [153,] 9.972014e-01 2.798556e-03
##  [154,] 9.999875e-01 1.247278e-05
##  [155,] 6.129546e-01 3.870454e-01
##  [156,] 9.972014e-01 2.798556e-03
##  [157,] 9.972014e-01 2.798556e-03
##  [158,] 9.998129e-01 1.870590e-04
##  [159,] 9.549610e-02 9.045039e-01
##  [160,] 9.998129e-01 1.870590e-04
##  [161,] 9.549610e-02 9.045039e-01
##  [162,] 9.999875e-01 1.247278e-05
##  [163,] 9.972014e-01 2.798556e-03
##  [164,] 6.989367e-03 9.930106e-01
##  [165,] 9.999875e-01 1.247278e-05
##  [166,] 9.972014e-01 2.798556e-03
##  [167,] 9.596044e-01 4.039564e-02
##  [168,] 9.596044e-01 4.039564e-02
##  [169,] 9.999875e-01 1.247278e-05
##  [170,] 9.998129e-01 1.870590e-04
##  [171,] 9.972014e-01 2.798556e-03
##  [172,] 6.129546e-01 3.870454e-01
##  [173,] 9.999875e-01 1.247278e-05
##  [174,] 9.596044e-01 4.039564e-02
##  [175,] 9.999875e-01 1.247278e-05
##  [176,] 9.999875e-01 1.247278e-05
##  [177,] 9.972014e-01 2.798556e-03
##  [178,] 9.999992e-01 8.315280e-07
##  [179,] 9.596044e-01 4.039564e-02
##  [180,] 9.972014e-01 2.798556e-03
##  [181,] 9.596044e-01 4.039564e-02
##  [182,] 9.972014e-01 2.798556e-03
##  [183,] 9.999875e-01 1.247278e-05
##  [184,] 9.972014e-01 2.798556e-03
##  [185,] 9.596044e-01 4.039564e-02
##  [186,] 9.998129e-01 1.870590e-04
##  [187,] 9.549610e-02 9.045039e-01
##  [188,] 9.972014e-01 2.798556e-03
##  [189,] 6.129546e-01 3.870454e-01
##  [190,] 9.972014e-01 2.798556e-03
##  [191,] 9.596044e-01 4.039564e-02
##  [192,] 9.999875e-01 1.247278e-05
##  [193,] 9.998129e-01 1.870590e-04
##  [194,] 6.989367e-03 9.930106e-01
##  [195,] 9.998129e-01 1.870590e-04
##  [196,] 9.596044e-01 4.039564e-02
##  [197,] 6.129546e-01 3.870454e-01
##  [198,] 9.596044e-01 4.039564e-02
##  [199,] 9.999875e-01 1.247278e-05
##  [200,] 9.998129e-01 1.870590e-04
##  [201,] 9.596044e-01 4.039564e-02
##  [202,] 9.596044e-01 4.039564e-02
##  [203,] 9.998129e-01 1.870590e-04
##  [204,] 9.999875e-01 1.247278e-05
##  [205,] 9.998129e-01 1.870590e-04
##  [206,] 6.129546e-01 3.870454e-01
##  [207,] 9.998129e-01 1.870590e-04
##  [208,] 9.999875e-01 1.247278e-05
##  [209,] 9.999875e-01 1.247278e-05
##  [210,] 9.999875e-01 1.247278e-05
##  [211,] 9.549610e-02 9.045039e-01
##  [212,] 9.549610e-02 9.045039e-01
##  [213,] 9.596044e-01 4.039564e-02
##  [214,] 9.998129e-01 1.870590e-04
##  [215,] 3.128152e-05 9.999687e-01
##  [216,] 9.999875e-01 1.247278e-05
##  [217,] 9.596044e-01 4.039564e-02
##  [218,] 6.129546e-01 3.870454e-01
##  [219,] 9.972014e-01 2.798556e-03
##  [220,] 9.972014e-01 2.798556e-03
##  [221,] 9.999875e-01 1.247278e-05
##  [222,] 9.549610e-02 9.045039e-01
##  [223,] 9.972014e-01 2.798556e-03
##  [224,] 9.998129e-01 1.870590e-04
##  [225,] 9.999992e-01 8.315280e-07
##  [226,] 9.549610e-02 9.045039e-01
##  [227,] 9.998129e-01 1.870590e-04
##  [228,] 9.998129e-01 1.870590e-04
##  [229,] 9.972014e-01 2.798556e-03
##  [230,] 9.596044e-01 4.039564e-02
##  [231,] 9.999992e-01 8.315280e-07
##  [232,] 9.596044e-01 4.039564e-02
##  [233,] 6.129546e-01 3.870454e-01
##  [234,] 9.998129e-01 1.870590e-04
##  [235,] 9.999992e-01 8.315280e-07
##  [236,] 9.596044e-01 4.039564e-02
##  [237,] 9.998129e-01 1.870590e-04
##  [238,] 9.998129e-01 1.870590e-04
##  [239,] 9.596044e-01 4.039564e-02
##  [240,] 9.999875e-01 1.247278e-05
##  [241,] 9.999875e-01 1.247278e-05
##  [242,] 9.972014e-01 2.798556e-03
##  [243,] 9.972014e-01 2.798556e-03
##  [244,] 9.972014e-01 2.798556e-03
##  [245,] 9.596044e-01 4.039564e-02
##  [246,] 9.972014e-01 2.798556e-03
##  [247,] 9.972014e-01 2.798556e-03
##  [248,] 9.596044e-01 4.039564e-02
##  [249,] 9.972014e-01 2.798556e-03
##  [250,] 9.999875e-01 1.247278e-05
##  [251,] 9.998129e-01 1.870590e-04
##  [252,] 9.549610e-02 9.045039e-01
##  [253,] 9.596044e-01 4.039564e-02
##  [254,] 9.972014e-01 2.798556e-03
##  [255,] 9.999992e-01 8.315280e-07
##  [256,] 9.972014e-01 2.798556e-03
##  [257,] 9.998129e-01 1.870590e-04
##  [258,] 6.129546e-01 3.870454e-01
##  [259,] 9.972014e-01 2.798556e-03
##  [260,] 9.596044e-01 4.039564e-02
##  [261,] 9.596044e-01 4.039564e-02
##  [262,] 9.999875e-01 1.247278e-05
##  [263,] 9.596044e-01 4.039564e-02
##  [264,] 9.596044e-01 4.039564e-02
##  [265,] 9.596044e-01 4.039564e-02
##  [266,] 9.998129e-01 1.870590e-04
##  [267,] 9.998129e-01 1.870590e-04
##  [268,] 9.972014e-01 2.798556e-03
##  [269,] 9.972014e-01 2.798556e-03
##  [270,] 9.998129e-01 1.870590e-04
##  [271,] 9.596044e-01 4.039564e-02
##  [272,] 6.129546e-01 3.870454e-01
##  [273,] 9.998129e-01 1.870590e-04
##  [274,] 9.596044e-01 4.039564e-02
##  [275,] 9.998129e-01 1.870590e-04
##  [276,] 9.972014e-01 2.798556e-03
##  [277,] 9.998129e-01 1.870590e-04
##  [278,] 9.998129e-01 1.870590e-04
##  [279,] 9.998129e-01 1.870590e-04
##  [280,] 9.998129e-01 1.870590e-04
##  [281,] 9.549610e-02 9.045039e-01
##  [282,] 6.129546e-01 3.870454e-01
##  [283,] 9.998129e-01 1.870590e-04
##  [284,] 6.129546e-01 3.870454e-01
##  [285,] 9.596044e-01 4.039564e-02
##  [286,] 9.972014e-01 2.798556e-03
##  [287,] 6.129546e-01 3.870454e-01
##  [288,] 9.998129e-01 1.870590e-04
##  [289,] 9.999875e-01 1.247278e-05
##  [290,] 9.999875e-01 1.247278e-05
##  [291,] 9.972014e-01 2.798556e-03
##  [292,] 9.998129e-01 1.870590e-04
##  [293,] 9.972014e-01 2.798556e-03
##  [294,] 9.999992e-01 8.315280e-07
##  [295,] 9.972014e-01 2.798556e-03
##  [296,] 9.998129e-01 1.870590e-04
##  [297,] 9.998129e-01 1.870590e-04
##  [298,] 9.999992e-01 8.315280e-07
##  [299,] 9.972014e-01 2.798556e-03
##  [300,] 9.999875e-01 1.247278e-05
##  [301,] 9.998129e-01 1.870590e-04
##  [302,] 9.999875e-01 1.247278e-05
##  [303,] 3.128152e-05 9.999687e-01
##  [304,] 9.596044e-01 4.039564e-02
##  [305,] 9.972014e-01 2.798556e-03
##  [306,] 9.596044e-01 4.039564e-02
##  [307,] 9.972014e-01 2.798556e-03
##  [308,] 9.972014e-01 2.798556e-03
##  [309,] 9.999992e-01 8.315280e-07
##  [310,] 9.999875e-01 1.247278e-05
##  [311,] 9.999875e-01 1.247278e-05
##  [312,] 9.549610e-02 9.045039e-01
##  [313,] 6.129546e-01 3.870454e-01
##  [314,] 9.998129e-01 1.870590e-04
##  [315,] 9.596044e-01 4.039564e-02
##  [316,] 9.998129e-01 1.870590e-04
##  [317,] 9.596044e-01 4.039564e-02
##  [318,] 6.129546e-01 3.870454e-01
##  [319,] 9.596044e-01 4.039564e-02
##  [320,] 9.972014e-01 2.798556e-03
##  [321,] 9.998129e-01 1.870590e-04
##  [322,] 9.596044e-01 4.039564e-02
##  [323,] 9.999875e-01 1.247278e-05
##  [324,] 9.972014e-01 2.798556e-03
##  [325,] 9.549610e-02 9.045039e-01
##  [326,] 6.989367e-03 9.930106e-01
##  [327,] 9.998129e-01 1.870590e-04
##  [328,] 9.998129e-01 1.870590e-04
##  [329,] 6.129546e-01 3.870454e-01
##  [330,] 6.989367e-03 9.930106e-01
##  [331,] 9.998129e-01 1.870590e-04
##  [332,] 9.998129e-01 1.870590e-04
##  [333,] 9.972014e-01 2.798556e-03
##  [334,] 9.972014e-01 2.798556e-03
##  [335,] 9.998129e-01 1.870590e-04
##  [336,] 9.999875e-01 1.247278e-05
##  [337,] 9.998129e-01 1.870590e-04
##  [338,] 9.998129e-01 1.870590e-04
##  [339,] 9.998129e-01 1.870590e-04
##  [340,] 9.972014e-01 2.798556e-03
##  [341,] 9.998129e-01 1.870590e-04
##  [342,] 9.998129e-01 1.870590e-04
##  [343,] 9.972014e-01 2.798556e-03
##  [344,] 9.549610e-02 9.045039e-01
##  [345,] 9.972014e-01 2.798556e-03
##  [346,] 9.999875e-01 1.247278e-05
##  [347,] 9.998129e-01 1.870590e-04
##  [348,] 9.972014e-01 2.798556e-03
##  [349,] 9.998129e-01 1.870590e-04
##  [350,] 9.998129e-01 1.870590e-04
##  [351,] 9.972014e-01 2.798556e-03
##  [352,] 9.998129e-01 1.870590e-04
##  [353,] 9.999875e-01 1.247278e-05
##  [354,] 9.998129e-01 1.870590e-04
##  [355,] 9.549610e-02 9.045039e-01
##  [356,] 9.999875e-01 1.247278e-05
##  [357,] 9.972014e-01 2.798556e-03
##  [358,] 9.596044e-01 4.039564e-02
##  [359,] 9.999875e-01 1.247278e-05
##  [360,] 6.129546e-01 3.870454e-01
##  [361,] 9.998129e-01 1.870590e-04
##  [362,] 9.998129e-01 1.870590e-04
##  [363,] 9.998129e-01 1.870590e-04
##  [364,] 6.129546e-01 3.870454e-01
##  [365,] 9.596044e-01 4.039564e-02
##  [366,] 9.596044e-01 4.039564e-02
##  [367,] 9.999875e-01 1.247278e-05
##  [368,] 9.972014e-01 2.798556e-03
##  [369,] 9.972014e-01 2.798556e-03
##  [370,] 9.972014e-01 2.798556e-03
##  [371,] 9.999992e-01 8.315280e-07
##  [372,] 9.998129e-01 1.870590e-04
##  [373,] 9.998129e-01 1.870590e-04
##  [374,] 9.596044e-01 4.039564e-02
##  [375,] 9.972014e-01 2.798556e-03
##  [376,] 9.998129e-01 1.870590e-04
##  [377,] 9.999875e-01 1.247278e-05
##  [378,] 9.999875e-01 1.247278e-05
##  [379,] 6.129546e-01 3.870454e-01
##  [380,] 9.998129e-01 1.870590e-04
##  [381,] 9.998129e-01 1.870590e-04
##  [382,] 9.972014e-01 2.798556e-03
##  [383,] 9.972014e-01 2.798556e-03
##  [384,] 9.999875e-01 1.247278e-05
##  [385,] 9.999992e-01 8.315280e-07
##  [386,] 9.998129e-01 1.870590e-04
##  [387,] 9.596044e-01 4.039564e-02
##  [388,] 9.596044e-01 4.039564e-02
##  [389,] 6.129546e-01 3.870454e-01
##  [390,] 9.549610e-02 9.045039e-01
##  [391,] 9.549610e-02 9.045039e-01
##  [392,] 9.972014e-01 2.798556e-03
##  [393,] 9.998129e-01 1.870590e-04
##  [394,] 9.596044e-01 4.039564e-02
##  [395,] 9.549610e-02 9.045039e-01
##  [396,] 9.596044e-01 4.039564e-02
##  [397,] 9.596044e-01 4.039564e-02
##  [398,] 6.129546e-01 3.870454e-01
##  [399,] 9.972014e-01 2.798556e-03
##  [400,] 9.999992e-01 8.315280e-07
##  [401,] 9.549610e-02 9.045039e-01
##  [402,] 9.998129e-01 1.870590e-04
##  [403,] 9.972014e-01 2.798556e-03
##  [404,] 9.972014e-01 2.798556e-03
##  [405,] 9.596044e-01 4.039564e-02
##  [406,] 9.972014e-01 2.798556e-03
##  [407,] 9.596044e-01 4.039564e-02
##  [408,] 9.999992e-01 8.315280e-07
##  [409,] 9.549610e-02 9.045039e-01
##  [410,] 6.129546e-01 3.870454e-01
##  [411,] 9.596044e-01 4.039564e-02
##  [412,] 9.972014e-01 2.798556e-03
##  [413,] 6.989367e-03 9.930106e-01
##  [414,] 9.972014e-01 2.798556e-03
##  [415,] 9.596044e-01 4.039564e-02
##  [416,] 9.998129e-01 1.870590e-04
##  [417,] 9.999875e-01 1.247278e-05
##  [418,] 9.972014e-01 2.798556e-03
##  [419,] 9.596044e-01 4.039564e-02
##  [420,] 9.549610e-02 9.045039e-01
##  [421,] 9.972014e-01 2.798556e-03
##  [422,] 9.596044e-01 4.039564e-02
##  [423,] 2.085495e-06 9.999979e-01
##  [424,] 2.085495e-06 9.999979e-01
##  [425,] 6.179259e-10 1.000000e+00
##  [426,] 1.830891e-13 1.000000e+00
##  [427,] 3.616576e-18 1.000000e+00
##  [428,] 5.424864e-17 1.000000e+00
##  [429,] 8.137295e-16 1.000000e+00
##  [430,] 2.085495e-06 9.999979e-01
##  [431,] 2.085495e-06 9.999979e-01
##  [432,] 8.137295e-16 1.000000e+00
##  [433,] 2.746337e-12 1.000000e+00
##  [434,] 6.179259e-10 1.000000e+00
##  [435,] 1.220594e-14 1.000000e+00
##  [436,] 4.119506e-11 1.000000e+00
##  [437,] 4.119506e-11 1.000000e+00
##  [438,] 9.268888e-09 1.000000e+00
##  [439,] 3.616576e-18 1.000000e+00
##  [440,] 1.220594e-14 1.000000e+00
##  [441,] 4.119506e-11 1.000000e+00
##  [442,] 2.746337e-12 1.000000e+00
##  [443,] 5.424864e-17 1.000000e+00
##  [444,] 6.179259e-10 1.000000e+00
##  [445,] 2.411050e-19 1.000000e+00
##  [446,] 6.179259e-10 1.000000e+00
##  [447,] 6.179259e-10 1.000000e+00
##  [448,] 9.268888e-09 1.000000e+00
##  [449,] 3.616576e-18 1.000000e+00
##  [450,] 4.119506e-11 1.000000e+00
##  [451,] 3.616576e-18 1.000000e+00
##  [452,] 4.119506e-11 1.000000e+00
##  [453,] 1.830891e-13 1.000000e+00
##  [454,] 1.390333e-07 9.999999e-01
##  [455,] 1.830891e-13 1.000000e+00
##  [456,] 1.830891e-13 1.000000e+00
##  [457,] 4.119506e-11 1.000000e+00
##  [458,] 6.179259e-10 1.000000e+00
##  [459,] 1.390333e-07 9.999999e-01
##  [460,] 6.179259e-10 1.000000e+00
##  [461,] 1.220594e-14 1.000000e+00
##  [462,] 1.830891e-13 1.000000e+00
##  [463,] 1.607367e-20 1.000000e+00
##  [464,] 3.128152e-05 9.999687e-01
##  [465,] 3.128152e-05 9.999687e-01
##  [466,] 2.085495e-06 9.999979e-01
##  [467,] 4.119506e-11 1.000000e+00
##  [468,] 2.746337e-12 1.000000e+00
##  [469,] 2.085495e-06 9.999979e-01
##  [470,] 2.746337e-12 1.000000e+00
##  [471,] 9.268888e-09 1.000000e+00
##  [472,] 1.390333e-07 9.999999e-01
##  [473,] 2.746337e-12 1.000000e+00
##  [474,] 4.119506e-11 1.000000e+00
##  [475,] 2.411050e-19 1.000000e+00
##  [476,] 6.179259e-10 1.000000e+00
##  [477,] 6.179259e-10 1.000000e+00
##  [478,] 4.119506e-11 1.000000e+00
##  [479,] 6.179259e-10 1.000000e+00
##  [480,] 6.179259e-10 1.000000e+00
##  [481,] 2.746337e-12 1.000000e+00
##  [482,] 1.830891e-13 1.000000e+00
##  [483,] 3.128152e-05 9.999687e-01
##  [484,] 6.179259e-10 1.000000e+00
##  [485,] 2.746337e-12 1.000000e+00
##  [486,] 1.071578e-21 1.000000e+00
##  [487,] 1.390333e-07 9.999999e-01
##  [488,] 5.424864e-17 1.000000e+00
##  [489,] 6.179259e-10 1.000000e+00
##  [490,] 1.220594e-14 1.000000e+00
##  [491,] 2.116697e-26 1.000000e+00
##  [492,] 8.137295e-16 1.000000e+00
##  [493,] 2.085495e-06 9.999979e-01
##  [494,] 1.390333e-07 9.999999e-01
##  [495,] 4.119506e-11 1.000000e+00
##  [496,] 1.830891e-13 1.000000e+00
##  [497,] 9.268888e-09 1.000000e+00
##  [498,] 8.137295e-16 1.000000e+00
##  [499,] 1.830891e-13 1.000000e+00
##  [500,] 6.179259e-10 1.000000e+00
##  [501,] 4.690174e-04 9.995310e-01
##  [502,] 6.179259e-10 1.000000e+00
##  [503,] 1.830891e-13 1.000000e+00
##  [504,] 1.830891e-13 1.000000e+00
##  [505,] 7.143853e-23 1.000000e+00
##  [506,] 6.179259e-10 1.000000e+00
##  [507,] 1.220594e-14 1.000000e+00
##  [508,] 3.128152e-05 9.999687e-01
##  [509,] 1.220594e-14 1.000000e+00
##  [510,] 4.119506e-11 1.000000e+00
##  [511,] 3.616576e-18 1.000000e+00
##  [512,] 4.119506e-11 1.000000e+00
##  [513,] 6.179259e-10 1.000000e+00
##  [514,] 3.128152e-05 9.999687e-01
##  [515,] 2.116697e-26 1.000000e+00
##  [516,] 6.179259e-10 1.000000e+00
##  [517,] 1.830891e-13 1.000000e+00
##  [518,] 4.119506e-11 1.000000e+00
##  [519,] 2.746337e-12 1.000000e+00
##  [520,] 3.616576e-18 1.000000e+00
##  [521,] 1.220594e-14 1.000000e+00
##  [522,] 6.271696e-30 1.000000e+00
##  [523,] 9.268888e-09 1.000000e+00
##  [524,] 9.268888e-09 1.000000e+00
##  [525,] 2.085495e-06 9.999979e-01
##  [526,] 2.746337e-12 1.000000e+00
##  [527,] 9.268888e-09 1.000000e+00
##  [528,] 1.220594e-14 1.000000e+00
##  [529,] 3.128152e-05 9.999687e-01
##  [530,] 3.128152e-05 9.999687e-01
##  [531,] 1.220594e-14 1.000000e+00
##  [532,] 5.424864e-17 1.000000e+00
##  [533,] 2.085495e-06 9.999979e-01
##  [534,] 8.137295e-16 1.000000e+00
##  [535,] 8.137295e-16 1.000000e+00
##  [536,] 1.830891e-13 1.000000e+00
##  [537,] 4.119506e-11 1.000000e+00
##  [538,] 3.128152e-05 9.999687e-01
##  [539,] 4.119506e-11 1.000000e+00
##  [540,] 1.220594e-14 1.000000e+00
##  [541,] 4.690174e-04 9.995310e-01
##  [542,] 6.179259e-10 1.000000e+00
##  [543,] 2.746337e-12 1.000000e+00
##  [544,] 2.085495e-06 9.999979e-01
##  [545,] 1.607367e-20 1.000000e+00
##  [546,] 1.220594e-14 1.000000e+00
##  [547,] 6.179259e-10 1.000000e+00
##  [548,] 1.390333e-07 9.999999e-01
##  [549,] 4.119506e-11 1.000000e+00
##  [550,] 2.411050e-19 1.000000e+00
##  [551,] 1.830891e-13 1.000000e+00
##  [552,] 6.179259e-10 1.000000e+00
##  [553,] 4.690174e-04 9.995310e-01
##  [554,] 1.830891e-13 1.000000e+00
##  [555,] 9.268888e-09 1.000000e+00
##  [556,] 6.179259e-10 1.000000e+00
##  [557,] 2.746337e-12 1.000000e+00
##  [558,] 2.085495e-06 9.999979e-01
##  [559,] 8.137295e-16 1.000000e+00
##  [560,] 2.411050e-19 1.000000e+00
##  [561,] 3.128152e-05 9.999687e-01
##  [562,] 8.137295e-16 1.000000e+00
##  [563,] 8.137295e-16 1.000000e+00
##  [564,] 9.268888e-09 1.000000e+00
##  [565,] 1.071578e-21 1.000000e+00
##  [566,] 1.830891e-13 1.000000e+00
##  [567,] 9.268888e-09 1.000000e+00
##  [568,] 1.220594e-14 1.000000e+00
##  [569,] 8.137295e-16 1.000000e+00
##  [570,] 8.137295e-16 1.000000e+00
##  [571,] 2.746337e-12 1.000000e+00
##  [572,] 3.128152e-05 9.999687e-01
##  [573,] 1.220594e-14 1.000000e+00
##  [574,] 4.119506e-11 1.000000e+00
##  [575,] 1.830891e-13 1.000000e+00
##  [576,] 9.549610e-02 9.045039e-01
##  [577,] 3.128152e-05 9.999687e-01
##  [578,] 2.746337e-12 1.000000e+00
##  [579,] 4.119506e-11 1.000000e+00
##  [580,] 4.690174e-04 9.995310e-01
##  [581,] 2.746337e-12 1.000000e+00
##  [582,] 4.119506e-11 1.000000e+00
##  [583,] 4.119506e-11 1.000000e+00
##  [584,] 2.411050e-19 1.000000e+00
##  [585,] 1.390333e-07 9.999999e-01
##  [586,] 2.085495e-06 9.999979e-01
##  [587,] 5.424864e-17 1.000000e+00
##  [588,] 1.220594e-14 1.000000e+00
##  [589,] 4.119506e-11 1.000000e+00
##  [590,] 2.085495e-06 9.999979e-01
##  [591,] 2.085495e-06 9.999979e-01
##  [592,] 2.411050e-19 1.000000e+00
##  [593,] 6.179259e-10 1.000000e+00
##  [594,] 1.607367e-20 1.000000e+00
##  [595,] 1.830891e-13 1.000000e+00
##  [596,] 9.268888e-09 1.000000e+00
##  [597,] 1.390333e-07 9.999999e-01
##  [598,] 4.690174e-04 9.995310e-01
##  [599,] 1.830891e-13 1.000000e+00
##  [600,] 1.220594e-14 1.000000e+00
##  [601,] 4.119506e-11 1.000000e+00
##  [602,] 6.179259e-10 1.000000e+00
##  [603,] 1.220594e-14 1.000000e+00
##  [604,] 1.390333e-07 9.999999e-01
##  [605,] 1.220594e-14 1.000000e+00
##  [606,] 4.119506e-11 1.000000e+00
##  [607,] 6.179259e-10 1.000000e+00
##  [608,] 1.390333e-07 9.999999e-01
##  [609,] 1.830891e-13 1.000000e+00
##  [610,] 2.085495e-06 9.999979e-01
##  [611,] 1.220594e-14 1.000000e+00
##  [612,] 8.137295e-16 1.000000e+00
##  [613,] 2.746337e-12 1.000000e+00
##  [614,] 6.179259e-10 1.000000e+00
##  [615,] 3.128152e-05 9.999687e-01
##  [616,] 1.830891e-13 1.000000e+00
##  [617,] 2.746337e-12 1.000000e+00
##  [618,] 2.746337e-12 1.000000e+00
##  [619,] 1.071578e-21 1.000000e+00
##  [620,] 6.129546e-01 3.870454e-01
##  [621,] 6.179259e-10 1.000000e+00
##  [622,] 6.179259e-10 1.000000e+00
##  [623,] 4.119506e-11 1.000000e+00
##  [624,] 4.690174e-04 9.995310e-01
##  [625,] 8.137295e-16 1.000000e+00
##  [626,] 2.746337e-12 1.000000e+00
##  [627,] 4.119506e-11 1.000000e+00
##  [628,] 2.411050e-19 1.000000e+00
##  [629,] 9.549610e-02 9.045039e-01
##  [630,] 1.830891e-13 1.000000e+00
##  [631,] 3.128152e-05 9.999687e-01
##  [632,] 4.119506e-11 1.000000e+00
##  [633,] 6.179259e-10 1.000000e+00
##  [634,] 1.220594e-14 1.000000e+00
##  [635,] 6.179259e-10 1.000000e+00
##  [636,] 2.746337e-12 1.000000e+00
##  [637,] 9.268888e-09 1.000000e+00
##  [638,] 1.607367e-20 1.000000e+00
##  [639,] 6.989367e-03 9.930106e-01
##  [640,] 1.220594e-14 1.000000e+00
##  [641,] 9.268888e-09 1.000000e+00
##  [642,] 1.830891e-13 1.000000e+00
##  [643,] 1.220594e-14 1.000000e+00
##  [644,] 1.830891e-13 1.000000e+00
##  [645,] 2.085495e-06 9.999979e-01
##  [646,] 8.137295e-16 1.000000e+00
##  [647,] 4.690174e-04 9.995310e-01
##  [648,] 1.390333e-07 9.999999e-01
##  [649,] 1.220594e-14 1.000000e+00
##  [650,] 1.830891e-13 1.000000e+00
##  [651,] 4.119506e-11 1.000000e+00
##  [652,] 4.119506e-11 1.000000e+00
##  [653,] 3.616576e-18 1.000000e+00
##  [654,] 5.424864e-17 1.000000e+00
##  [655,] 6.179259e-10 1.000000e+00
##  [656,] 9.549610e-02 9.045039e-01
##  [657,] 6.179259e-10 1.000000e+00
##  [658,] 6.179259e-10 1.000000e+00
##  [659,] 2.746337e-12 1.000000e+00
##  [660,] 3.616576e-18 1.000000e+00
##  [661,] 4.119506e-11 1.000000e+00
##  [662,] 2.085495e-06 9.999979e-01
##  [663,] 8.137295e-16 1.000000e+00
##  [664,] 2.085495e-06 9.999979e-01
##  [665,] 2.085495e-06 9.999979e-01
##  [666,] 4.119506e-11 1.000000e+00
##  [667,] 4.119506e-11 1.000000e+00
##  [668,] 9.549610e-02 9.045039e-01
##  [669,] 1.390333e-07 9.999999e-01
##  [670,] 9.268888e-09 1.000000e+00
##  [671,] 3.128152e-05 9.999687e-01
##  [672,] 4.119506e-11 1.000000e+00
##  [673,] 1.607367e-20 1.000000e+00
##  [674,] 4.119506e-11 1.000000e+00
##  [675,] 1.830891e-13 1.000000e+00
##  [676,] 5.424864e-17 1.000000e+00
##  [677,] 4.119506e-11 1.000000e+00
##  [678,] 6.179259e-10 1.000000e+00
##  [679,] 4.119506e-11 1.000000e+00
##  [680,] 1.220594e-14 1.000000e+00
##  [681,] 1.220594e-14 1.000000e+00
##  [682,] 2.085495e-06 9.999979e-01
##  [683,] 1.830891e-13 1.000000e+00
##  [684,] 6.179259e-10 1.000000e+00
##  [685,] 2.085495e-06 9.999979e-01
##  [686,] 1.390333e-07 9.999999e-01
##  [687,] 1.830891e-13 1.000000e+00
##  [688,] 4.119506e-11 1.000000e+00
##  [689,] 6.179259e-10 1.000000e+00
##  [690,] 6.179259e-10 1.000000e+00
##  [691,] 9.268888e-09 1.000000e+00
##  [692,] 8.137295e-16 1.000000e+00
##  [693,] 2.746337e-12 1.000000e+00
##  [694,] 2.085495e-06 9.999979e-01
##  [695,] 2.085495e-06 9.999979e-01
##  [696,] 5.424864e-17 1.000000e+00
##  [697,] 5.424864e-17 1.000000e+00
##  [698,] 2.746337e-12 1.000000e+00
##  [699,] 4.119506e-11 1.000000e+00
##  [700,] 1.220594e-14 1.000000e+00
##  [701,] 4.119506e-11 1.000000e+00
##  [702,] 9.268888e-09 1.000000e+00
##  [703,] 2.746337e-12 1.000000e+00
##  [704,] 1.390333e-07 9.999999e-01
##  [705,] 1.071578e-21 1.000000e+00
##  [706,] 6.179259e-10 1.000000e+00
##  [707,] 6.179259e-10 1.000000e+00
##  [708,] 1.390333e-07 9.999999e-01
##  [709,] 1.830891e-13 1.000000e+00
##  [710,] 1.220594e-14 1.000000e+00
##  [711,] 1.220594e-14 1.000000e+00
##  [712,] 2.746337e-12 1.000000e+00
##  [713,] 4.119506e-11 1.000000e+00
##  [714,] 9.407543e-29 1.000000e+00
##  [715,] 4.119506e-11 1.000000e+00
##  [716,] 1.830891e-13 1.000000e+00
##  [717,] 8.137295e-16 1.000000e+00
##  [718,] 8.137295e-16 1.000000e+00
##  [719,] 6.179259e-10 1.000000e+00
##  [720,] 4.119506e-11 1.000000e+00
##  [721,] 5.424864e-17 1.000000e+00
##  [722,] 4.119506e-11 1.000000e+00
##  [723,] 6.179259e-10 1.000000e+00
##  [724,] 9.549610e-02 9.045039e-01
##  [725,] 9.268888e-09 1.000000e+00
##  [726,] 1.220594e-14 1.000000e+00
##  [727,] 6.179259e-10 1.000000e+00
##  [728,] 8.137295e-16 1.000000e+00
##  [729,] 1.220594e-14 1.000000e+00
##  [730,] 3.128152e-05 9.999687e-01
##  [731,] 1.220594e-14 1.000000e+00
##  [732,] 2.746337e-12 1.000000e+00
##  [733,] 2.116697e-26 1.000000e+00
##  [734,] 9.268888e-09 1.000000e+00
##  [735,] 1.390333e-07 9.999999e-01
##  [736,] 6.179259e-10 1.000000e+00
##  [737,] 1.830891e-13 1.000000e+00
##  [738,] 1.220594e-14 1.000000e+00
##  [739,] 2.411050e-19 1.000000e+00
##  [740,] 4.119506e-11 1.000000e+00
##  [741,] 1.830891e-13 1.000000e+00
##  [742,] 3.175046e-25 1.000000e+00
##  [743,] 2.746337e-12 1.000000e+00
##  [744,] 4.119506e-11 1.000000e+00
##  [745,] 4.119506e-11 1.000000e+00
##  [746,] 6.179259e-10 1.000000e+00
##  [747,] 1.220594e-14 1.000000e+00
##  [748,] 1.220594e-14 1.000000e+00
##  [749,] 2.746337e-12 1.000000e+00
##  [750,] 1.390333e-07 9.999999e-01
##  [751,] 2.746337e-12 1.000000e+00
##  [752,] 1.220594e-14 1.000000e+00
##  [753,] 5.424864e-17 1.000000e+00
##  [754,] 6.179259e-10 1.000000e+00
##  [755,] 9.268888e-09 1.000000e+00
##  [756,] 1.830891e-13 1.000000e+00
##  [757,] 4.119506e-11 1.000000e+00
##  [758,] 1.390333e-07 9.999999e-01
##  [759,] 2.746337e-12 1.000000e+00
##  [760,] 4.119506e-11 1.000000e+00
##  [761,] 6.179259e-10 1.000000e+00
##  [762,] 4.119506e-11 1.000000e+00
##  [763,] 8.137295e-16 1.000000e+00
##  [764,] 1.830891e-13 1.000000e+00
##  [765,] 4.119506e-11 1.000000e+00
##  [766,] 8.137295e-16 1.000000e+00
##  [767,] 4.119506e-11 1.000000e+00
##  [768,] 1.830891e-13 1.000000e+00
##  [769,] 2.746337e-12 1.000000e+00
##  [770,] 1.390333e-07 9.999999e-01
##  [771,] 1.390333e-07 9.999999e-01
##  [772,] 1.390333e-07 9.999999e-01
##  [773,] 1.830891e-13 1.000000e+00
##  [774,] 1.830891e-13 1.000000e+00
##  [775,] 6.179259e-10 1.000000e+00
##  [776,] 2.085495e-06 9.999979e-01
##  [777,] 3.128152e-05 9.999687e-01
##  [778,] 2.085495e-06 9.999979e-01
##  [779,] 5.424864e-17 1.000000e+00
##  [780,] 8.137295e-16 1.000000e+00
##  [781,] 6.179259e-10 1.000000e+00
##  [782,] 5.424864e-17 1.000000e+00
##  [783,] 4.119506e-11 1.000000e+00
##  [784,] 3.128152e-05 9.999687e-01
##  [785,] 5.424864e-17 1.000000e+00
##  [786,] 9.268888e-09 1.000000e+00
##  [787,] 1.220594e-14 1.000000e+00
##  [788,] 2.411050e-19 1.000000e+00
##  [789,] 1.830891e-13 1.000000e+00
##  [790,] 9.268888e-09 1.000000e+00
##  [791,] 3.128152e-05 9.999687e-01
##  [792,] 4.690174e-04 9.995310e-01
##  [793,] 5.424864e-17 1.000000e+00
##  [794,] 6.179259e-10 1.000000e+00
##  [795,] 5.424864e-17 1.000000e+00
##  [796,] 1.830891e-13 1.000000e+00
##  [797,] 9.549610e-02 9.045039e-01
##  [798,] 1.830891e-13 1.000000e+00
##  [799,] 8.137295e-16 1.000000e+00
##  [800,] 4.119506e-11 1.000000e+00
##  [801,] 3.128152e-05 9.999687e-01
##  [802,] 2.746337e-12 1.000000e+00
##  [803,] 2.746337e-12 1.000000e+00
##  [804,] 5.424864e-17 1.000000e+00
##  [805,] 2.085495e-06 9.999979e-01
##  [806,] 9.268888e-09 1.000000e+00
##  [807,] 8.137295e-16 1.000000e+00
##  [808,] 1.390333e-07 9.999999e-01
##  [809,] 6.179259e-10 1.000000e+00
##  [810,] 1.830891e-13 1.000000e+00
##  [811,] 2.085495e-06 9.999979e-01
##  [812,] 4.119506e-11 1.000000e+00
##  [813,] 9.549610e-02 9.045039e-01
##  [814,] 6.179259e-10 1.000000e+00
##  [815,] 6.179259e-10 1.000000e+00
##  [816,] 1.220594e-14 1.000000e+00
##  [817,] 5.424864e-17 1.000000e+00
##  [818,] 1.830891e-13 1.000000e+00
##  [819,] 4.119506e-11 1.000000e+00
##  [820,] 8.137295e-16 1.000000e+00
##  [821,] 4.119506e-11 1.000000e+00
##  [822,] 1.390333e-07 9.999999e-01
##  [823,] 4.119506e-11 1.000000e+00
##  [824,] 6.179259e-10 1.000000e+00
##  [825,] 8.137295e-16 1.000000e+00
##  [826,] 3.616576e-18 1.000000e+00
##  [827,] 9.268888e-09 1.000000e+00
##  [828,] 2.746337e-12 1.000000e+00
##  [829,] 4.119506e-11 1.000000e+00
##  [830,] 1.830891e-13 1.000000e+00
##  [831,] 3.616576e-18 1.000000e+00
##  [832,] 7.143853e-23 1.000000e+00
##  [833,] 2.116697e-26 1.000000e+00
##  [834,] 1.607367e-20 1.000000e+00
##  [835,] 9.268888e-09 1.000000e+00
##  [836,] 4.119506e-11 1.000000e+00
##  [837,] 9.268888e-09 1.000000e+00
##  [838,] 4.119506e-11 1.000000e+00
##  [839,] 2.746337e-12 1.000000e+00
##  [840,] 9.268888e-09 1.000000e+00
##  [841,] 2.411050e-19 1.000000e+00
##  [842,] 1.830891e-13 1.000000e+00
##  [843,] 1.390333e-07 9.999999e-01
##  [844,] 1.830891e-13 1.000000e+00
##  [845,] 6.179259e-10 1.000000e+00
##  [846,] 2.085495e-06 9.999979e-01
##  [847,] 2.085495e-06 9.999979e-01
##  [848,] 2.746337e-12 1.000000e+00
##  [849,] 2.085495e-06 9.999979e-01
##  [850,] 1.830891e-13 1.000000e+00
##  [851,] 6.179259e-10 1.000000e+00
##  [852,] 1.220594e-14 1.000000e+00
##  [853,] 9.268888e-09 1.000000e+00
##  [854,] 2.085495e-06 9.999979e-01
##  [855,] 1.220594e-14 1.000000e+00
##  [856,] 8.137295e-16 1.000000e+00
##  [857,] 1.220594e-14 1.000000e+00
##  [858,] 1.220594e-14 1.000000e+00
##  [859,] 4.119506e-11 1.000000e+00
##  [860,] 1.220594e-14 1.000000e+00
##  [861,] 4.119506e-11 1.000000e+00
##  [862,] 1.220594e-14 1.000000e+00
##  [863,] 1.390333e-07 9.999999e-01
##  [864,] 9.268888e-09 1.000000e+00
##  [865,] 4.119506e-11 1.000000e+00
##  [866,] 4.119506e-11 1.000000e+00
##  [867,] 6.179259e-10 1.000000e+00
##  [868,] 4.119506e-11 1.000000e+00
##  [869,] 1.830891e-13 1.000000e+00
##  [870,] 1.830891e-13 1.000000e+00
##  [871,] 4.119506e-11 1.000000e+00
##  [872,] 8.137295e-16 1.000000e+00
##  [873,] 2.746337e-12 1.000000e+00
##  [874,] 5.424864e-17 1.000000e+00
##  [875,] 2.411050e-19 1.000000e+00
##  [876,] 2.085495e-06 9.999979e-01
##  [877,] 1.390333e-07 9.999999e-01
##  [878,] 2.085495e-06 9.999979e-01
##  [879,] 2.085495e-06 9.999979e-01
##  [880,] 1.607367e-20 1.000000e+00
##  [881,] 4.119506e-11 1.000000e+00
##  [882,] 2.746337e-12 1.000000e+00
##  [883,] 2.085495e-06 9.999979e-01
##  [884,] 3.175046e-25 1.000000e+00
##  [885,] 1.220594e-14 1.000000e+00
##  [886,] 1.220594e-14 1.000000e+00
##  [887,] 1.390333e-07 9.999999e-01
##  [888,] 4.119506e-11 1.000000e+00
##  [889,] 2.085495e-06 9.999979e-01
##  [890,] 6.179259e-10 1.000000e+00
##  [891,] 1.830891e-13 1.000000e+00
##  [892,] 5.424864e-17 1.000000e+00
##  [893,] 4.119506e-11 1.000000e+00
##  [894,] 5.424864e-17 1.000000e+00
##  [895,] 8.137295e-16 1.000000e+00
##  [896,] 5.424864e-17 1.000000e+00
##  [897,] 1.390333e-07 9.999999e-01
##  [898,] 9.549610e-02 9.045039e-01
##  [899,] 9.268888e-09 1.000000e+00
##  [900,] 5.424864e-17 1.000000e+00
##  [901,] 1.220594e-14 1.000000e+00
##  [902,] 8.137295e-16 1.000000e+00
##  [903,] 6.989367e-03 9.930106e-01
##  [904,] 2.746337e-12 1.000000e+00
##  [905,] 4.119506e-11 1.000000e+00
##  [906,] 4.119506e-11 1.000000e+00
##  [907,] 4.119506e-11 1.000000e+00
##  [908,] 5.424864e-17 1.000000e+00
##  [909,] 1.830891e-13 1.000000e+00
##  [910,] 1.220594e-14 1.000000e+00
##  [911,] 4.119506e-11 1.000000e+00
##  [912,] 5.424864e-17 1.000000e+00
##  [913,] 1.390333e-07 9.999999e-01
##  [914,] 4.119506e-11 1.000000e+00
##  [915,] 9.268888e-09 1.000000e+00
##  [916,] 5.424864e-17 1.000000e+00
##  [917,] 6.129546e-01 3.870454e-01
##  [918,] 1.830891e-13 1.000000e+00
##  [919,] 2.085495e-06 9.999979e-01
##  [920,] 1.830891e-13 1.000000e+00
##  [921,] 2.746337e-12 1.000000e+00
##  [922,] 2.746337e-12 1.000000e+00
##  [923,] 3.616576e-18 1.000000e+00
##  [924,] 1.390333e-07 9.999999e-01
##  [925,] 1.830891e-13 1.000000e+00
##  [926,] 1.607367e-20 1.000000e+00
##  [927,] 1.390333e-07 9.999999e-01
##  [928,] 4.119506e-11 1.000000e+00
##  [929,] 2.746337e-12 1.000000e+00
##  [930,] 1.220594e-14 1.000000e+00
##  [931,] 1.220594e-14 1.000000e+00
##  [932,] 2.746337e-12 1.000000e+00
##  [933,] 2.746337e-12 1.000000e+00
##  [934,] 2.746337e-12 1.000000e+00
##  [935,] 4.119506e-11 1.000000e+00
##  [936,] 2.746337e-12 1.000000e+00
##  [937,] 9.268888e-09 1.000000e+00
##  [938,] 2.746337e-12 1.000000e+00
##  [939,] 1.830891e-13 1.000000e+00
##  [940,] 2.085495e-06 9.999979e-01
##  [941,] 2.746337e-12 1.000000e+00
##  [942,] 9.268888e-09 1.000000e+00
##  [943,] 8.137295e-16 1.000000e+00
##  [944,] 4.119506e-11 1.000000e+00
##  [945,] 1.220594e-14 1.000000e+00
##  [946,] 6.179259e-10 1.000000e+00
##  [947,] 6.179259e-10 1.000000e+00
##  [948,] 1.390333e-07 9.999999e-01
##  [949,] 8.137295e-16 1.000000e+00
##  [950,] 1.607367e-20 1.000000e+00
##  [951,] 1.830891e-13 1.000000e+00
##  [952,] 1.830891e-13 1.000000e+00
##  [953,] 2.746337e-12 1.000000e+00
##  [954,] 5.424864e-17 1.000000e+00
##  [955,] 9.268888e-09 1.000000e+00
##  [956,] 3.128152e-05 9.999687e-01
##  [957,] 8.137295e-16 1.000000e+00
##  [958,] 2.411050e-19 1.000000e+00
##  [959,] 1.390333e-07 9.999999e-01
##  [960,] 9.268888e-09 1.000000e+00
##  [961,] 8.137295e-16 1.000000e+00
##  [962,] 1.830891e-13 1.000000e+00
##  [963,] 3.616576e-18 1.000000e+00
##  [964,] 3.128152e-05 9.999687e-01
##  [965,] 1.830891e-13 1.000000e+00
##  [966,] 2.085495e-06 9.999979e-01
##  [967,] 5.424864e-17 1.000000e+00
##  [968,] 1.830891e-13 1.000000e+00
##  [969,] 6.179259e-10 1.000000e+00
##  [970,] 2.746337e-12 1.000000e+00
##  [971,] 1.390333e-07 9.999999e-01
##  [972,] 1.220594e-14 1.000000e+00
##  [973,] 1.830891e-13 1.000000e+00
##  [974,] 6.179259e-10 1.000000e+00
##  [975,] 6.179259e-10 1.000000e+00
##  [976,] 1.830891e-13 1.000000e+00
##  [977,] 2.746337e-12 1.000000e+00
##  [978,] 4.119506e-11 1.000000e+00
##  [979,] 1.830891e-13 1.000000e+00
##  [980,] 8.137295e-16 1.000000e+00
##  [981,] 1.220594e-14 1.000000e+00
##  [982,] 4.119506e-11 1.000000e+00
##  [983,] 4.690174e-04 9.995310e-01
##  [984,] 6.179259e-10 1.000000e+00
##  [985,] 1.220594e-14 1.000000e+00
##  [986,] 2.746337e-12 1.000000e+00
##  [987,] 6.179259e-10 1.000000e+00
##  [988,] 3.128152e-05 9.999687e-01
##  [989,] 8.137295e-16 1.000000e+00
##  [990,] 3.128152e-05 9.999687e-01
##  [991,] 4.119506e-11 1.000000e+00
##  [992,] 5.424864e-17 1.000000e+00
##  [993,] 9.268888e-09 1.000000e+00
##  [994,] 2.746337e-12 1.000000e+00
##  [995,] 1.390333e-07 9.999999e-01
##  [996,] 2.085495e-06 9.999979e-01
##  [997,] 1.830891e-13 1.000000e+00
##  [998,] 2.085495e-06 9.999979e-01
##  [999,] 2.085495e-06 9.999979e-01
## [1000,] 6.179259e-10 1.000000e+00
EM<-function(X,K){
  parameters<-Init.parameters(X,K)
  old.parameters<-parameters
  old.parameters$pis<-rep(1,K)
  old.parameters$lambdas<-rep(1,K)
  T<-matrix(1,nrow(X),K)
  while(mean((unlist(parameters)-unlist(old.parameters))^2)>1e-16){
    print(mean((unlist(parameters)-unlist(old.parameters)^2)))
    old.parameters<-parameters
    T<-E.step(X,parameters,T)
    parameters<-M.step(X,T)
    print(parameters)
  }
      print(mean((unlist(parameters)-unlist(old.parameters))^2))

  return(list(T=T,parameters=parameters))
}

res.EM<-EM(X,2)
## [1] 3.25
## $pis
## [1] 0.02 0.98
## 
## $lambdas
## [1] 0.00000 9.90102
## 
## [1] -61.39974
## $pis
## [1] 0.019951 0.980049
## 
## $lambdas
## [1] 0.000000 9.900525
## 
## [1] -22.02262
## $pis
## [1] 0.01995085 0.98004915
## 
## $lambdas
## [1] 0.000000 9.900524
## 
## [1] -22.02019
## $pis
## [1] 0.01995085 0.98004915
## 
## $lambdas
## [1] 0.000000 9.900524
## 
## [1] 5.051499e-18