Package classification

Source Code of classification.CompleteFeatureFunction

package classification;

import java.io.Serializable;

import types.Alphabet;
import types.FeatureFunction;
import types.SparseVector;

public class CompleteFeatureFunction implements FeatureFunction, Serializable {

  /** this is the last feature for each y */
  public int defalutFeatureIndex;
  int numY;

  private static final long serialVersionUID = 1L;

  public CompleteFeatureFunction(Alphabet xAlphabet, Alphabet yAlphabet) {
    xAlphabet.stopGrowth();
    yAlphabet.stopGrowth();
    numY = yAlphabet.size();
    defalutFeatureIndex = xAlphabet.size();
  }

  public SparseVector apply(SparseVector x, int y) {
    SparseVector res = new SparseVector();
    for (int i = 0; i < x.numEntries(); i++) {
      res.add(y * (defalutFeatureIndex + 1) + x.getIndexAt(i), x
          .getValueAt(i));
    }
    res.add(y * (defalutFeatureIndex + 1) + defalutFeatureIndex, 1);
    return res;
  }

  public int wSize() {
    return numY * (defalutFeatureIndex + 1);
  }

}
TOP

Related Classes of classification.CompleteFeatureFunction

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.