IIntList goodStates = intsNew.list(0);
int nselect = errors.size()/2;
IIntArray sortedIndexes = doubles.sortedIndexes(errors);
IIntArray mergeCandidates = ints.subToNew(sortedIndexes, 0, nselect);
*/
IIntArray mergeCandidates = intsNew.arrayRange(hmmChi.rows());
// compute coming-from-probabilities
/*
IDoubleArray pComeFrom = hmmChi.copy();
for (int i=0; i<pComeFrom.rows(); i++)
for (int I=0; I<pComeFrom.columns(); I++)
pComeFrom.set(i,I, hmmChi.get(i,I) * hmmpiC.get(I) / msmpi.get(i));
*/
IDoubleArray pComeFrom = hmmChi.copy();
alg.normalizeRows(pComeFrom, 1);
System.out.println(" COME-FROM array:");
doubles.print(pComeFrom,"\t","\n");
// select optimal groups
ArrayList<IIntArray> groups = new ArrayList();
for (int i=0; i<nhidden; i++)
groups.add(intsNew.list(0));
for (int i=0; i<mergeCandidates.size(); i++)
{
int s = mergeCandidates.get(i);
int g = doubleArrays.maxIndex(pComeFrom.getRow(s));
if (pComeFrom.get(i,g) > 0.99)
((IIntList)groups.get(g)).append(s);
}
// remove empty groups
for (int i=groups.size()-1; i>=0; i--)
{
if (groups.get(i).size() <= 1)
{
System.out.println("removing merge group "+i+" with size "+groups.get(i).size());
groups.remove(i);
}
else
{
// output
for (int j=0; j<groups.size(); j++)
{
IIntArray group = groups.get(j);
System.out.println("- merge group "+j+": "+ints.toString(group,"",","));
IDoubleArray groupChi = pComeFrom.view(group.getArray(), intsNew.arrayRange(0, nhidden).getArray());
doubles.print(groupChi,"\t","\n");
System.out.println();
}
}
}