HMMlogLikeIntern <-
function(stateParameters,gamma,x,f,...){
  
  m = dim(gamma)[1]
  
  if(m==1) return(-Inf)

  #stationary distribution
  delta = stat_distr(gamma)
  
  #print(delta)
  
  #no. of observations
  n = ifelse(test=is.matrix(x),yes=n<-dim(x)[1],no=n<-length(x))
  
  
  #state dependent density values
  allprobs= matrix(NA,ncol=m,nrow=n)
  for(j in 1:m){
    allprobs[,j] = f(x=x,par=stateParameters[[j]])
  }
  
  allprobs   <- ifelse(!is.na(allprobs),allprobs,1)
  lscale     <- 0
  foo        <- delta
  for (i in 1:n)
  {
    foo    <- foo%*%gamma*allprobs[i,]
    sumfoo <- sum(foo)
    lscale <- lscale+log(sumfoo)
    foo    <- foo/sumfoo
  }
  mllk       <- -(lscale)
  mllk
}
