machine learning - NA/NaN/Inf error when fitting HMM using depmixS4 in R -
i'm trying fit simple hidden markov models in r using depmix. obscure errors (na/nan/inf in foreign function call). instance
require(depmixs4) t = data.frame(v=c(0.0622031327669583,-0.12564002739468,-0.117354660120178,0.0115062213361335,0.122992418345013,-0.0177816909620965,0.0164821157439354,0.161981367176501,-0.174367935386872,0.00429417498601576,0.00870091566593177,-0.00324734222267713,-0.0609817740148078,0.0840679943325736,-0.0722982123741866,0.00309386232501072,0.0136237132601905,-0.0569072400881981,0.102323872007477,-0.0390675463642003,0.0373248728294635,-0.0839484669503484,0.0514620475651086,-0.0306598076180909,-0.0664992242224042,0.826857872461293,-0.172970803143762,-0.071091459861684,-0.0128631184461384,-0.0439382422065227,-0.0552809574423446,0.0596321725192134,-0.06043926984848,0.0398700063815422)) mod = depmix(response=v~1, data=t, nstates=2) fit(mod) ... na/nan/inf in foreign function call (arg 10)
and can have input of identical size , complexity work fine...is there preferred tool depmixs4 here?
there no guarantee em algorithm can find fit every dataset given arbitrary number of states. example try fit 2 state gaussian model data generated poisson distribution lambda = 1 receive same error.
set.seed(3) ydf <- data.frame(y=rpois(100,1)) m1 <- depmix(y~1,ns=2,family=gaussian(),data=ydf) fit(m1) iteration 0 loglik: -135.6268 iteration 5 loglik: -134.2392 iteration 10 loglik: -128.7834 iteration 15 loglik: -111.5922 error in fb(init = init, = trdens, b = dens, ntimes = ntimes(object), : na/nan/inf in foreign function call (arg 10)
with regards data, can fit model data fine 1 state. 2 states algorithm cannot find solution (even 10000 random starts). 3 states, issue seems initialization of starting states of model. if 1 attempts run same model 100 times data provided convergence in of 100 iterations. example below:
>require(depmixs4) >t = data.frame(v=c(0.0622031327669583,-0.12564002739468,-0.117354660120178,0.0115062213361335,0.122992418345013,-0.0177816909620965,0.0164821157439354,0.161981367176501,-0.174367935386872,0.00429417498601576,0.00870091566593177,-0.00324734222267713,-0.0609817740148078,0.0840679943325736,-0.0722982123741866,0.00309386232501072,0.0136237132601905,-0.0569072400881981,0.102323872007477,-0.0390675463642003,0.0373248728294635,-0.0839484669503484,0.0514620475651086,-0.0306598076180909,-0.0664992242224042,0.826857872461293,-0.172970803143762,-0.071091459861684,-0.0128631184461384,-0.0439382422065227,-0.0552809574423446,0.0596321725192134,-0.06043926984848,0.0398700063815422)) >mod = depmix(response=v~1, data=t, nstates=2) >fit(mod) ... na/nan/inf in foreign function call (arg 10) >replicate(100, try(fit(mod, verbose = f))) [[1]] [1] "error in fb(init = init, = trdens, b = dens, ntimes = ntimes(object), : \n na/nan/inf in foreign function call (arg 10)\n" [[2]] [1] "error in fb(init = init, = trdens, b = dens, ntimes = ntimes(object), : \n na/nan/inf in foreign function call (arg 10)\n" [[3]] convergence info: log likelihood converged within tol. (relative change) 'log lik.' 34.0344 (df=14) aic: -40.0688 bic: -18.69975 ... output truncated
Comments
Post a Comment