# R/ce.simNormalNB.BIC.Init.R In breakpoint: An R Package for Multiple Break-Point Detection via the Cross-Entropy Method

#### Defines functions ce.simNormalNB.BIC.Init

```ce.simNormalNB.BIC.Init <-
function(N, init.locs, data, h, L0, L, M, Melite, eps, a, b, r, var.init){

#   r <- suppressWarnings(try(fitdistr(data[, 1], "negative binomial")[[1]][[1]], silent = T))

########################Parameter initialization######################################################
new_para <- rbind(init.locs, rep(var.init, N))
######################################################################################################

#    bic <- c()
k <- 0

repeat
{
k <- k + 1
ch <- array(0, dim = c(M, N + 2))
ch[, 1] <- c(1)
ch[, ( N + 2)] <- c(L + 1)
ch[, (2:(N + 1))] <- apply(new.para, 2, normrand, L0, L, M)
ch <- t(apply(ch, 1, sort))
loglike <- apply(ch, 1, llhoodnb, data, r, h)
bic.vals <- apply(as.data.frame(loglike), 1, BICnb, N, L)
ch <- cbind(ch, bic.vals, loglike)
ch <- ch[order(ch[, (N + 3)], decreasing = FALSE), ]
melitesmpl <- ch[1:Melite, ]
#      bic[k] <- melitesmpl[1, (N + 3)]

newpar.n <- array(0, dim = c(2, N))
newpar.n[1, ] <-apply(as.matrix(melitesmpl[, (2:(N + 1))]), 2, mean)
newpar.n[2, ] <-apply(as.matrix(melitesmpl[, (2:(N + 1))]), 2, sd)

new.para[1, ] <- a * newpar.n[1, ] + (1 - a) * new.para[1, ]
new.para[2, ] <- b * newpar.n[2, ] + (1 - b) * new.para[2, ]

mad <- apply(as.matrix(melitesmpl[, (2:(N + 1))]), 2, mad)