public void addTo (AugmentableFeatureVector fv, double value) { addTo (fv, value, null); }
public FeatureConjunction (Alphabet dictionary, int[] features, boolean[] negations) { this (getName (dictionary, features, negations), dictionary, features, negations, true); }
int[] featureIndices = FeatureConjunction.getFeatureIndices(origV, s); if (FeatureConjunction.isValidConjunction (featureIndices) fcl.add (new FeatureConjunction (origV, featureIndices)); int index = origV.size()-1; fcl.add (new FeatureConjunction (origV, new int[] {index})); logger.info ("Added feature a "+numFeaturesAdded+" "+gg2.getValueAtRank(i)+ ' ' + gg2.getObjectAtRank(i)); numFeaturesAdded++;
int[] featureIndices = getFeatureIndices (dictionary, (String) dictionary.lookupObject(features[i])); if (featureIndices.length > 1) { int newLength = features.length-1+featureIndices.length; newFeatures[n++] = features[j]; Arrays.sort (newFeatures); return getName (dictionary, newFeatures); for (int j = i+1; j < features.length; j++) newFeatures[n++] = features[j]; return getName (dictionary, newFeatures);
public AugmentableFeatureVectorAddConjunctions addConjunction (String name, Alphabet v, int[] features, boolean[] negations) { conjunctions.add (new FeatureConjunction (name, v, features, negations)); return this; }
public static boolean featuresOverlap (Alphabet dictionary, int feature1, int feature2) { if (feature1 == feature2) return true; int[] fis1 = getFeatureIndices (dictionary, (String)dictionary.lookupObject(feature1)); int[] fis2 = getFeatureIndices (dictionary, (String)dictionary.lookupObject(feature2)); for (int i = 0, j = 0; i < fis1.length; i++) { assert (i >= fis1.length-2 || fis1[i] < fis1[i+1]); assert (j >= fis2.length-2 || fis2[j] < fis2[j+1]); while (fis2[j] < fis1[i] && j < fis2.length-1) j++; if (fis1[i] == fis2[j]) return true; } return false; }
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 FeatureConjunction (Alphabet dictionary, int[] features) { this (getName (dictionary, features, null), dictionary, features, null, true, true, false); }
public void addTo (AugmentableFeatureVector fv) { this.addTo (fv, 1.0); }
public static String getName (Alphabet dictionary, int feature1, int feature2) { if (feature1 < feature2) return getName (dictionary, new int[] {feature1, feature2}); else return getName (dictionary, new int[] {feature2, feature1}); //assert (feature1 != feature2); //String string1 = dictionary.lookupObject(feature1).toString(); //String string2 = dictionary.lookupObject(feature2).toString(); //if (feature1 < feature2) //return string1 + conjunctionString + string2; //else //return string2 + conjunctionString + string1; }
public void addTo (AugmentableFeatureVector fv, double value, FeatureSelection fs) { // xxx Make this more efficient for (int i = 0; i < conjunctions.size(); i++) ((FeatureConjunction)conjunctions.get(i)).addTo (fv, value, fs); }
public static String getName (Alphabet dictionary, int[] features, boolean[] negations) { if (true) { if (negations != null) for (int i = 0; i < negations.length; i++) if (negations[i]) throw new UnsupportedOperationException ("Doesn't yet check for sub-duplicates with negations."); return getName (dictionary, features); } // Split apart any feature[i] that is itself a conjunction feature //int[] featureIndices = getFeatureIndices (dictionary, dictionary.lookupObject( // xxx Add code here to do the sorting... // Make sure the the features area sorted for (int i = 1; i < features.length; i++) if (features[i-1] >= features[i]) throw new IllegalArgumentException ("feature index not sorted, or contains duplicate"); StringBuffer sb = new StringBuffer (); for (int i = 0; i < features.length; i++) { if (i > 0) sb.append (conjunctionString); if (negations != null && negations[i]) sb.append (negationString); sb.append (dictionary.lookupObject(features[i]).toString()); } return sb.toString(); }
for (int j = 0; j < fv.indices.length; j++) { if (conjunctions[ci] != fv.indices[j]) { int index = newVocab.lookupIndex (FeatureConjunction.getName (v, conjunctions[ci], fv.indices[j])); if (index == newVocab.size()-1 && index % 3 == 0) logger.info ("New feature "+ newVocab.lookupObject(index));
int index = newVocab.lookupIndex (FeatureConjunction.getName (v, fv.indices[i], fv.indices[j])); if (index != -1) // this can be -1 if newVocab.growthStopped newIndices[size++] = index;