本文整理汇总了Java中cc.mallet.types.AugmentableFeatureVector.add方法的典型用法代码示例。如果您正苦于以下问题:Java AugmentableFeatureVector.add方法的具体用法?Java AugmentableFeatureVector.add怎么用?Java AugmentableFeatureVector.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.AugmentableFeatureVector
的用法示例。
在下文中一共展示了AugmentableFeatureVector.add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddWithPrefix
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
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 ());
}
示例2: setInFeatureVector
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
/**
* Set a feature in the feature vector, to the given value.
* However, if growth is stopped, do not set the feature if the key is not known.
*
* This method assumes that the key for this feature vector is only set once, if it
* is set another time for the same feature vector, any old value is overridden!
*
* @param fv
* @param key
* @param val
*/
private static void setInFeatureVector(AugmentableFeatureVector fv, Object key, double val) {
Alphabet a = fv.getAlphabet();
if (!a.contains(key) && a.growthStopped()) {
//System.err.println("DEBUG: GROWTH STOPPED! key="+key+",a="+a);
return;
}
if(fv.contains(key)) {
System.err.println("LF DEBUG: setting/overriding a value where there is already one! key="+key);
fv.setValue(a.lookupIndex(key), val);
} else {
fv.add(key, val);
}
}
示例3: accumulateInFeatureVector
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
private static void accumulateInFeatureVector(AugmentableFeatureVector fv, Object key, double val) {
Alphabet a = fv.getAlphabet();
if (!a.contains(key) && a.growthStopped()) {
return;
}
fv.add(key,val);
// Instead of the previous statement the following was used for debugging:
//if(fv.contains(key)) {
// fv.add(key,val);
//System.err.println("DEBUG accumulate: adding to existing: key="+key+" index="+a.lookupIndex(key)+" loc="+fv.location(a.lookupIndex(key)));
//} else {
// fv.add(key,val);
//System.err.println("DEBUG accumulate: creating new: key="+key+" index="+a.lookupIndex(key)+" loc="+fv.location(a.lookupIndex(key)));
//}
}
示例4: makeAfv
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
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;
}
示例5: pipe
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
/**
* Add the token classifier's predictions as features to the instance.
* This method assumes the input instance contains FeatureVectorSequence as data
*/
public Instance pipe(Instance carrier)
{
FeatureVectorSequence fvs = (FeatureVectorSequence) carrier.getData();
InstanceList ilist = convert(carrier, (Noop) m_tokenClassifiers.getInstancePipe());
assert (fvs.size() == ilist.size());
// For passing instances to the token classifier, each instance's data alphabet needs to
// match that used by the token classifier at training time. For the resulting piped
// instance, each instance's data alphabet needs to contain token classifier's prediction
// as features
FeatureVector[] fva = new FeatureVector[fvs.size()];
for (int i = 0; i < ilist.size(); i++) {
Instance inst = ilist.get(i);
Classification c = m_tokenClassifiers.classify(inst, ! m_inProduction);
LabelVector lv = c.getLabelVector();
AugmentableFeatureVector afv1 = (AugmentableFeatureVector) inst.getData();
int[] indices = afv1.getIndices();
AugmentableFeatureVector afv2 = new AugmentableFeatureVector(m_dataAlphabet,
indices, afv1.getValues(), indices.length + m_predRanks2add.length);
for (int j = 0; j < m_predRanks2add.length; j++) {
Label label = lv.getLabelAtRank(m_predRanks2add[j]);
int idx = m_dataAlphabet.lookupIndex("TOK_PRED=" + label.toString() + "[email protected]_RANK_" + m_predRanks2add[j]);
assert(idx >= 0);
afv2.add(idx, 1);
}
fva[i] = afv2;
}
carrier.setData(new FeatureVectorSequence(fva));
return carrier;
}
示例6: induceFeatures
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
public void induceFeatures (AugmentableFeatureVector afv,
FeatureSelection featuresAlreadyThere,
FeatureSelection[] perClassFeaturesAlreadyThere,
FeatureSelection newFeatureSelection,
FeatureSelection[] perClassNewFeatureSelection,
boolean withInteriorNodes,
boolean addPerClassFeatures,
double classEntropyThreshold)
{
if (!isRoot() && (isLeaf() || withInteriorNodes) && labelEntropy < classEntropyThreshold) {
String name = getName();
logger.info("Trying to add feature "+name);
//int conjunctionIndex = afv.getAlphabet().lookupIndex (name, false);
if (addPerClassFeatures) {
int classIndex = labeling.getBestIndex();
if (!perClassFeaturesAlreadyThere[classIndex].contains (name)) {
afv.add (name, 1.0);
perClassNewFeatureSelection[classIndex].add (name);
}
} else {
throw new UnsupportedOperationException ("Not yet implemented.");
}
}
boolean featurePresent = afv.value (featureIndex) != 0;
if (child0 != null && !featurePresent)
child0.induceFeatures (afv, featuresAlreadyThere, perClassFeaturesAlreadyThere,
newFeatureSelection, perClassNewFeatureSelection,
withInteriorNodes, addPerClassFeatures, classEntropyThreshold);
if (child1 != null && featurePresent)
child1.induceFeatures (afv, featuresAlreadyThere, perClassFeaturesAlreadyThere,
newFeatureSelection, perClassNewFeatureSelection,
withInteriorNodes, addPerClassFeatures, classEntropyThreshold);
}
示例7: Record
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
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());
}
}
示例8: pipe
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
@Override
public Instance pipe(Instance inst) {
FeatureVectorSequence vs = (FeatureVectorSequence) inst.getData();
for (int i = 0; i < vs.size(); i++) {
AugmentableFeatureVector v = (AugmentableFeatureVector) vs.get(i);
// System.out.println("Before augment: " + v.numLocations());
double[] values = scl.transform(v);
for (int j = 0; j < values.length; j++) {
String key = "SCL_AUG" + j;
// if (values[j] != 0)
// v.add("SCL_AUG" + j, values[j]);
// if (values[j] < -1) {
// v.add(key + "(<-1)", 1);
// } else if (values[j] < -0.5) {
// v.add(key + "(<-0.5)", 1);
// } else if (values[j] < 0) {
// v.add(key + "(<0)", 1);
// } else if (values[j] > 1) {
// v.add(key + "(>1)", 1);
// } else if (values[j] > 0.5) {
// v.add(key + "(>0.5)", 1);
// } else if (values[j] > 0) {
// v.add(key + "(>0)", 1);
// } else {
// v.add(key + "(=0)", 1);
// }
// if (values[j] > 0) {
// v.add(key + "(>0)", 1);
// } else if (values[j] < 0) {
// v.add(key + "(<0)", 1);
// }
if (values[j] != 0)
v.add(key, values[j]);
}
// System.out.println(v);
// System.out.println("After augment: " + v.numLocations());
}
return inst;
}
示例9: setDoubleValue
import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
protected void setDoubleValue(String instanceId, String featureName, double value) {
AugmentableFeatureVector fv = getInstanceData(instanceId);
int index = featureAlphabet.getAlphabet().lookupIndex(featureName);
if (index < 0) {
return; // it can occur when featureAlphabet.getStopGrowth()==true and the featureset does not contain the feature
}
int location = fv.location(index);
if (location < 0) {
fv.add(index, value);
featureAlphabet.add(index);
} else {
fv.setValueAtLocation(location, value);
}
}