All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.mallet.grmm.inference.MessageArray Maven / Gradle / Ivy

Go to download

MALLET is a Java-based package for statistical natural language processing, document classification, clustering, topic modeling, information extraction, and other machine learning applications to text.

The newest version!
/* Copyright (C) 2006 Univ. of Massachusetts Amherst, Computer Science Dept.
   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).
   http://mallet.cs.umass.edu/
   This software is provided under the terms of the Common Public License,
   version 1.0, as published by http://www.opensource.org.  For further
   information, see the file `LICENSE' included with this distribution. */
package cc.mallet.grmm.inference;

import gnu.trove.TIntObjectIterator;

import java.io.PrintWriter;
import java.io.OutputStreamWriter;

import cc.mallet.grmm.types.Factor;
import cc.mallet.grmm.types.FactorGraph;
import cc.mallet.grmm.types.LogTableFactor;
import cc.mallet.grmm.types.Variable;
import cc.mallet.grmm.util.MIntInt2ObjectMap;

/**
 * Efficiently manages a array of messages in a factor graph from
 *  variables to factors and vice versa.
 *
 * Created: Feb 1, 2006
 *
 * @author  0) {
        keys2 = messages.keys2 (keys1[idx1]);
      } else {
        keys2 = new int [0];
      }
    }

    private void increment () {
      idx2++;
      if (idx2 >= keys2.length) {
        idx2 = 0;
        idx1++;
        keys2 = messages.keys2 (keys1[idx1]);
      }
    }

    public boolean hasNext ()
    {
      return (idx1+1 < keys1.length) || (idx2+1 < keys2.length);
    }

    public Object next ()
    {
      increment ();
      return messages.get (keys1[idx1], keys2[idx2]);
    }

    public void remove ()
    {
      throw new UnsupportedOperationException ();
    }

    public Object from ()
    {
      return idx2obj (keys2[idx2]);
    }

    public Object to ()
    {
      return idx2obj (keys1[idx1]);
    }
  }

  final public static class ToMsgsIterator
  {
    private TIntObjectIterator subIt;
    private int toIdx = -1;

    private ToMsgsIterator (MIntInt2ObjectMap msgs, int toIdx)
    {
      this.toIdx = toIdx;
      subIt = msgs.curry (toIdx);
    }

    public boolean hasNext () { return subIt.hasNext (); }
    public Factor next () { subIt.advance (); return currentMessage (); }

    int currentFromIdx () { return subIt.key (); }
    public Factor currentMessage () { return (Factor) subIt.value (); }

    public int currentToIdx ()
    {
      return toIdx;
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy