public void add (Object key, double value) { //System.out.println ("AugmentableFeatureVector dictionary = "+dictionary+", size = "+dictionary.size()); int index = dictionary.lookupIndex (key); //System.out.println ("AugmentableFeatureVector index("+key+") = "+index); assert (index != -1); add (index, value); }
private AugmentableFeatureVector makeAfv (int[] ints, boolean binary) { AugmentableFeatureVector afv = new AugmentableFeatureVector (new Alphabet(), binary); for (int i = 0; i < ints.length; i++) { int idx = ints[i]; afv.add (idx, 1.0); } return afv; }
public AugmentableFeatureVector (FeatureSequence fs, boolean binary) { this (fs.getAlphabet(), binary); for (int i = fs.size()-1; i >= 0; i--) add (fs.getIndexAtPosition(i), 1.0); }
/** * Adds all indices that are present in some other feature vector * with value 1.0. * Beware that this may have unintended effects if * <tt>fv.dictionary != this.dictionary</tt> */ public void add (FeatureVector fv) { for (int loc = 0; loc < fv.numLocations (); loc++) { int index = fv.indexAtLocation (loc); if (location (index) == -1) { add (index, 1.0); } } }
/** * Adds all features from some other feature vector with weight 1.0. * The names of the added features are generated by adding a prefix to * their names in the original feature vector. * This does not require that <tt>fv.dictionary != this.dictionary</tt>. * @param fv A feature vector to add from. Its feature names must be Strings. * @param prefix String to add when generating new feature names * @param binary true if <tt>fv</tt> is binary */ public void add (FeatureVector fv, String prefix, boolean binary) { if (binary) add( fv, prefix); else { Alphabet otherDict = fv.getAlphabet (); for (int loc = 0; loc < fv.numLocations (); loc++) { int idx = fv.indexAtLocation (loc); double val = fv.valueAtLocation (loc); String otherName = (String) otherDict.lookupObject (idx); add (prefix+otherName, val); } } }
/** * Adds all features from some other feature vector with weight 1.0. * The names of the added features are generated by adding a prefix to * their names in the original feature vector. * This does not require that <tt>fv.dictionary != this.dictionary</tt>. * @param fv A feature vector to add from. Its feature names must be Strings. * @param prefix String to add when generating new feature names */ public void add (FeatureVector fv, String prefix) { Alphabet otherDict = fv.getAlphabet (); for (int loc = 0; loc < fv.numLocations (); loc++) { int idx = fv.indexAtLocation (loc); String otherName = (String) otherDict.lookupObject (idx); add (prefix+otherName, 1.0); } }
public void addTo (AugmentableFeatureVector fv, double value, FeatureSelection fs) { // xxx This could be simplified for the special case of a FeatureConjunction with only one conjunct if (this.satisfiedBy (fv)) { index = fv.getAlphabet().lookupIndex (name); // Make sure that this feature is selected if (fs != null) fs.add (index); if (index >= 0 && fv.value(index) > 0) // Don't add features that are already there return; assert (index != -1); fv.add (index, value); } }
while (grams[di][si] == 1 && --si >= 0) gramString = uniAlphabet.lookupObject(fs.getIndexAtPosition(si)).toString() + "_" + gramString; afv.add(gramString, 1.0);
public AugmentableFeatureVector (Alphabet dict, PropertyList pl, boolean binary, boolean growAlphabet) { this (dict, binary); if (pl == null) return; PropertyList.Iterator iter = pl.numericIterator(); while (iter.hasNext()) { iter.nextProperty(); //System.out.println ("AugmentableVector ("+dict.size()+") adding "+iter.getKey()+" "+iter.getNumericValue()); int index = dict.lookupIndex (iter.getKey(), growAlphabet); if (index >= 0) add (index, iter.getNumericValue()); } }
int classIndex = labeling.getBestIndex(); if (!perClassFeaturesAlreadyThere[classIndex].contains (name)) { afv.add (name, 1.0); perClassNewFeatureSelection[classIndex].add (name);
afv.add (index, iter.getNumericValue());
public void testAddWithPrefix () { Alphabet dict = new Alphabet (); dict.lookupIndex ("ZERO"); dict.lookupIndex ("ONE"); dict.lookupIndex ("TWO"); dict.lookupIndex ("THREE"); FeatureVector fv = new FeatureVector (dict, new int[] { 1,3 }); AugmentableFeatureVector afv = new AugmentableFeatureVector (new Alphabet (), true); afv.add (fv, "O:"); assertEquals (4, dict.size()); assertEquals (2, afv.getAlphabet ().size()); assertEquals ("O:ONE\nO:THREE\n", afv.toString ()); }
afv2.add(idx, 1);