View Javadoc

1   package classification;
2   
3   import java.io.Serializable;
4   
5   import types.Alphabet;
6   import types.FeatureFunction;
7   import types.SparseVector;
8   
9   public class CompleteFeatureFunction implements FeatureFunction, Serializable {
10  
11  	/*** this is the last feature for each y */
12  	public int defalutFeatureIndex;
13  	int numY;
14  
15  	private static final long serialVersionUID = 1L;
16  
17  	public CompleteFeatureFunction(Alphabet xAlphabet, Alphabet yAlphabet) {
18  		xAlphabet.stopGrowth();
19  		yAlphabet.stopGrowth();
20  		numY = yAlphabet.size();
21  		defalutFeatureIndex = xAlphabet.size();
22  	}
23  
24  	public SparseVector apply(SparseVector x, int y) {
25  		SparseVector res = new SparseVector();
26  		for (int i = 0; i < x.numEntries(); i++) {
27  			res.add(y * (defalutFeatureIndex + 1) + x.getIndexAt(i), x
28  					.getValueAt(i));
29  		}
30  		res.add(y * (defalutFeatureIndex + 1) + defalutFeatureIndex, 1);
31  		return res;
32  	}
33  
34  	public int wSize() {
35  		return numY * (defalutFeatureIndex + 1);
36  	}
37  
38  }