当前位置: 首页>>代码示例>>Java>>正文


Java AugmentableFeatureVector类代码示例

本文整理汇总了Java中cc.mallet.types.AugmentableFeatureVector的典型用法代码示例。如果您正苦于以下问题:Java AugmentableFeatureVector类的具体用法?Java AugmentableFeatureVector怎么用?Java AugmentableFeatureVector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AugmentableFeatureVector类属于cc.mallet.types包,在下文中一共展示了AugmentableFeatureVector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractIndependentFeaturesHelper

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
/**
 * Extract the independent features for a single instance annotation.
 * Extract the independent features for a single annotation according to the information
 * in the featureInfo object. The information in the featureInfo instance gets updated 
 * by this. 
 * NOTE: this method is static so that it can be used in the CorpusRepresentationMalletSeq class too.
 * @param instanceAnnotation
 * @param inputAS
 * @param targetFeatureName
 * @param featureInfo
 * @param pipe
 * @param nameFeature
 * @return 
 */
static Instance extractIndependentFeaturesHelper(
        Annotation instanceAnnotation,
        AnnotationSet inputAS,
        FeatureInfo featureInfo,
        Pipe pipe) {
  
  AugmentableFeatureVector afv = new AugmentableFeatureVector(pipe.getDataAlphabet());
  // Constructor parms: data, target, name, source
  Instance inst = new Instance(afv, null, null, null);
  for(FeatureSpecAttribute attr : featureInfo.getAttributes()) {
    FeatureExtraction.extractFeature(inst, attr, inputAS, instanceAnnotation);
  }
  // TODO: we destructively replace the AugmentableFeatureVector by a FeatureVector here,
  // but it is not clear if this is beneficial - our assumption is that yes.
  inst.setData(((AugmentableFeatureVector)inst.getData()).toFeatureVector());
  return inst;
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:32,代码来源:CorpusRepresentationMalletTarget.java

示例2: 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 ());
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:18,代码来源:TestAugmentableFeatureVector.java

示例3: induceFeatures

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
public void induceFeatures (InstanceList ilist, boolean withFeatureShrinkage, boolean inducePerClassFeatures)
	{
		if (inducePerClassFeatures) {
			int numClasses = ilist.getTargetAlphabet().size();
//			int numFeatures = ilist.getDataAlphabet().size();
			FeatureSelection[] pcfs = new FeatureSelection[numClasses];
			for (int j = 0; j < numClasses; j++)
				pcfs[j] = (FeatureSelection) ilist.getPerLabelFeatureSelection()[j].clone();
			for (int i = 0; i < ilist.size(); i++) {
				Object data = ilist.get(i).getData();
				AugmentableFeatureVector afv = (AugmentableFeatureVector) data;
				root.induceFeatures (afv, null, pcfs, ilist.getFeatureSelection(), ilist.getPerLabelFeatureSelection(),
														 withFeatureShrinkage, inducePerClassFeatures, addFeaturesClassEntropyThreshold);
			}
		} else {
			throw new UnsupportedOperationException ("Not yet implemented");
		}
	}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:19,代码来源:DecisionTree.java

示例4: createSubset

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
public DataHandler createSubset(Collection<String> instancesSelected, Set<String> featuresSelected) throws DataMiningException {
  MalletDataHandler dh = new MalletDataHandler();
  Map<String, Object> param = new HashMap<String, Object>();
  param.put("useFeatureSet", this);
  dh.createNewDataset(param);
  dh.featureAlphabet = new FeatureSequence(new Alphabet());
  dh.featureAlphabet.getAlphabet().startGrowth();
  dh.data = new InstanceList(dh.featureAlphabet.getAlphabet(), dh.labelAlphabet);
  for (String inst : instancesSelected) {
    AugmentableFeatureVector fv = this.getInstanceData(inst);
    for (int i = 0; i < fv.numLocations(); ++i) {
      String featurename = (String) fv.getAlphabet().lookupObject(fv.getIndices()[i]);
      if (featuresSelected.contains(featurename)) {
        dh.setDoubleValue(inst, featurename, fv.getValues()[i]);
      }
    }
    dh.setLabel(inst, this.getLabel(inst));
  }
  return dh;
}
 
开发者ID:begab,项目名称:kpe,代码行数:21,代码来源:MalletDataHandler.java

示例5: saveDatasetMallet

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
public void saveDatasetMallet(String target) {
  try {
    PrintWriter out = new PrintWriter(target);
    for (String id : instanceIds.keySet()) {
      out.print(id + "@" + getLabel(id));
      AugmentableFeatureVector fv = getInstanceData(id);
      for (int i = 0; i < fv.numLocations(); ++i) {
        out.print("\t" + featureAlphabet.getAlphabet().lookupObject(fv.getIndices()[i]) + ":" + fv.getValues()[i]);
      }
      out.println();
    }
    out.close();
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  }
}
 
开发者ID:begab,项目名称:kpe,代码行数:17,代码来源:MalletDataHandler.java

示例6: 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);
  }
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:25,代码来源:FeatureExtraction.java

示例7: 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)));
  //}
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:16,代码来源:FeatureExtraction.java

示例8: testDotProductBinaryToSV

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
public void testDotProductBinaryToSV ()
{
  SparseVector v = makeSparseVectorToN (5);
  AugmentableFeatureVector afv = makeAfv (new int[] { 1, 3 }, true);
  double dp = afv.dotProduct (v);
  assertEquals (4.0, dp, 1e-5);
  new AugmentableFeatureVector (new Alphabet(), true);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:TestAugmentableFeatureVector.java

示例9: testDotProductSparseASVToSV

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
public void testDotProductSparseASVToSV ()
{
  SparseVector v = makeSparseVectorToN (7);
  AugmentableFeatureVector afv = makeAfv (new int[] { 1, 3 }, false);
  double dp = afv.dotProduct (v);
  assertEquals (4.0, dp, 1e-5);

  afv = makeAfv (new int[] { 2, 5 }, false);
  dp = afv.dotProduct (v);
  assertEquals (7.0, dp, 1e-5);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:TestAugmentableFeatureVector.java

示例10: 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;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:10,代码来源:TestAugmentableFeatureVector.java

示例11: 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;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:39,代码来源:AddClassifierTokenPredictions.java

示例12: convert

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
/**
 * 
 * @param inst input instance, with FeatureVectorSequence as data.
 * @param alphabetsPipe a Noop pipe containing the data and target alphabets for 
 * the resulting InstanceList and AugmentableFeatureVectors
 * @return list of instances, each with one AugmentableFeatureVector as data
 */
public static InstanceList convert(Instance inst, Noop alphabetsPipe)
{
	InstanceList ret = new InstanceList(alphabetsPipe);
	Object obj = inst.getData();
	assert(obj instanceof FeatureVectorSequence);

	FeatureVectorSequence fvs = (FeatureVectorSequence) obj;
	LabelSequence ls = (LabelSequence) inst.getTarget();
	assert(fvs.size() == ls.size());

	Object instName = (inst.getName() == null ? "NONAME" : inst.getName());
	
	for (int j = 0; j < fvs.size(); j++) {
		FeatureVector fv = fvs.getFeatureVector(j);
		int[] indices = fv.getIndices();
		FeatureVector data = new AugmentableFeatureVector (alphabetsPipe.getDataAlphabet(),
				indices, fv.getValues(), indices.length); 
		Labeling target = ls.getLabelAtPosition(j);
		String name = instName.toString() + "[email protected]_POS_" + (j + 1);
		Object source = inst.getSource();
		Instance toAdd = alphabetsPipe.pipe(new Instance(data, target, name, source));

		ret.add(toAdd);
	}

	return ret;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:35,代码来源:AddClassifierTokenPredictions.java

示例13: pipe

import cc.mallet.types.AugmentableFeatureVector; //导入依赖的package包/类
public Instance pipe (Instance carrier)
{
	AugmentableFeatureVector afv = (AugmentableFeatureVector)carrier.getData();
	double v;
	for (int i = afv.numLocations() - 1; i >= 0; i--) {
		v = afv.valueAtLocation (i);
		if (v >= 1)
			afv.setValueAtLocation (i, Math.log(v)+1);
	}
	return carrier;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:AugmentableFeatureVectorLogScale.java

示例14: 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());
	}
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:10,代码来源:Record.java

示例15: 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;
}
 
开发者ID:siqil,项目名称:udaner,代码行数:41,代码来源:SCLAugment.java


注:本文中的cc.mallet.types.AugmentableFeatureVector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。