hivemall-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From myui <...@git.apache.org>
Subject [GitHub] incubator-hivemall pull request #93: Maximum Entropy Model
Date Sun, 02 Jul 2017 09:49:05 GMT
Github user myui commented on a diff in the pull request:

    https://github.com/apache/incubator-hivemall/pull/93#discussion_r125178629
  
    --- Diff: core/src/main/java/hivemall/smile/tools/MatrixEventStream.java ---
    @@ -0,0 +1,79 @@
    +package hivemall.smile.tools;
    +
    +import java.util.Iterator;
    +import java.util.List;
    +
    +import hivemall.math.matrix.Matrix;
    +import hivemall.smile.data.Attribute;
    +import hivemall.smile.data.Attribute.AttributeType;
    +import opennlp.model.AbstractEventStream;
    +import opennlp.model.Event;
    +
    +public class MatrixEventStream extends AbstractEventStream {
    +	  Matrix ds;
    +	  int[] y;
    +	  Attribute[] attrs;
    +	  int rowNum;
    +	  Event next;
    +
    +	  public MatrixEventStream (Matrix ds, int[] y, Attribute[] attrs) {
    +	    this.ds = ds;
    +	    this.y = y;
    +	    this.attrs = attrs;
    +	    rowNum = 0;
    +	    
    +	    if (rowNum < ds.numRows()){
    +	      next = createEvent(ds.getRow(rowNum), y[rowNum]);
    +	    };
    +	  }
    +	  	  
    +	  /**
    +	   * Returns the next Event object held in this EventStream.  Each call to nextEvent
advances the EventStream.
    +	   *
    +	   * @return the Event object which is next in this EventStream
    +	   */
    +	  public Event next () {
    +	    while (next == null && (rowNum < ds.numRows()))
    +	      next = createEvent(ds.getRow(rowNum), y[rowNum]);
    +	    
    +	    Event current = next;
    +	    if (rowNum < ds.numRows()) {
    +	      next = createEvent(ds.getRow(rowNum), y[rowNum]);
    +	    }
    +	    else {
    +	      next = null;
    +	    }
    +	    return current;
    +	  }
    +	  
    +	  /**
    +	   * Test whether there are any Events remaining in this EventStream.
    +	   *
    +	   * @return true if this EventStream has more Events
    +	   */
    +	  public boolean hasNext () {
    +	    while (next == null && rowNum < ds.numRows())
    +	      next = createEvent(ds.getRow(rowNum), y[rowNum]);
    +	    return next != null;
    +	  }
    +	  
    +	  private Event createEvent(double[] obs, int y) {
    +		    rowNum++;
    +		    if (obs == null) 
    --- End diff --
    
    `{}` same as the above.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message