if (cmd.singlePointEstimate)
{
IHMM pmm = hmm.pmm(cmd.discreteTrajectories, cmd.nhidden, cmd.tau, cmd.timeshift, cmd.hmmNIter, cmd.hmmDecTol, null, null);
IDoubleArray hmmTC = pmm.getTransitionMatrix();
io.writeString(cmd.outdir+"/hmmTc.dat", doubles.toString(hmmTC,"\t","\n"));
IDoubleArray hmmChi = pmm.getOutputParameters();
io.writeString(cmd.outdir+"/hmmChi.dat", doubles.toString(hmmChi,"\t","\n"));
}
else if (cmd.hmmTimescalesEstimate)
{
IIntList lagtimes = intsNew.list(0);
lagtimes.append(cmd.taumin);
for (double tau = cmd.taumin; tau <= cmd.taumax; tau *= cmd.taumult)
{
int lag = (int)tau;
if (lag != lagtimes.get(lagtimes.size()-1))
lagtimes.append(lag);
}
PrintStream itsout = new PrintStream(cmd.outdir+"/hmm-its.dat");
IDoubleArray lastTC = cmd.init_T;
IDoubleArray lastChi = cmd.init_Chi;
for (int i=0; i<lagtimes.size(); i++)
{
//set lag and timeshift
int lag = lagtimes.get(i);
System.out.println("\ntau = "+lag+"\n");
// in direct mode, erase the results from last lag. Otherwise use as initialization.
if (cmd.direct)
{
lastTC = null;
lastChi = null;
}
System.out.println("Hidden state: "+cmd.nhidden);
IHMM pmm = hmm.pmm(cmd.discreteTrajectories, cmd.nhidden, lag, cmd.timeshift, cmd.hmmNIter, cmd.hmmDecTol, lastTC, lastChi);
// remember estimation results and use them as a next initializer.
lastTC = pmm.getTransitionMatrix();
lastChi = pmm.getOutputParameters();
//double[] logL = cmd.ninja.getHMMLikelihoodHistory();
double lastLogL = pmm.getLogLikelihood();
// output timescales
IDoubleArray hmmTimescales = msm.timescales(lastTC, lag);
itsout.println(lag+"\t"+lastLogL+"\t"+doubles.toString(hmmTimescales,""," "));
// output hidden matrix
PrintStream TCout = new PrintStream(cmd.outdir+"/hmm-TC-lag"+lag+".dat");
TCout.print(doubles.toString(lastTC,"\t","\n"));