public void add (int index) { if (values != null) throw new IllegalArgumentException ("Trying to add binary feature to real-valued vector"); assert (index >= 0); add (index, 1.0); }
public void add (int index) { if (values != null) throw new IllegalArgumentException ("Trying to add binary feature to real-valued vector"); assert (index >= 0); add (index, 1.0); }
public void add (int index) { if (values != null) throw new IllegalArgumentException ("Trying to add binary feature to real-valued vector"); assert (index >= 0); add (index, 1.0); }
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); }
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); }
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; }
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); }
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); }
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); }
public Record (Alphabet fieldAlph, Alphabet valueAlph, String[][] vals) { this(fieldAlph, valueAlph); for (int i = 0; i < vals.length; i++) { AugmentableFeatureVector afv = new AugmentableFeatureVector(valueAlph, false); for (int j = 1; j < vals[i].length; j++) afv.add(valueAlph.lookupIndex(vals[i][j]), 1.0); field2values.put(fieldAlph.lookupIndex(vals[i][0]), afv.toFeatureVector()); } }
public Record (Alphabet fieldAlph, Alphabet valueAlph, String[][] vals) { this(fieldAlph, valueAlph); for (int i = 0; i < vals.length; i++) { AugmentableFeatureVector afv = new AugmentableFeatureVector(valueAlph, false); for (int j = 1; j < vals[i].length; j++) afv.add(valueAlph.lookupIndex(vals[i][j]), 1.0); field2values.put(fieldAlph.lookupIndex(vals[i][0]), afv.toFeatureVector()); } }
public Record (Alphabet fieldAlph, Alphabet valueAlph, String[][] vals) { this(fieldAlph, valueAlph); for (int i = 0; i < vals.length; i++) { AugmentableFeatureVector afv = new AugmentableFeatureVector(valueAlph, false); for (int j = 1; j < vals[i].length; j++) afv.add(valueAlph.lookupIndex(vals[i][j]), 1.0); field2values.put(fieldAlph.lookupIndex(vals[i][0]), afv.toFeatureVector()); } }
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); } }
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()); } }
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()); } }
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()); } }
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 ()); }
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 ()); }