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


Java LabelVector类代码示例

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


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

示例1: createLabelVector

import cc.mallet.types.LabelVector; //导入依赖的package包/类
/** Constructs a LabelVector which is a distribution over indices of
 * the "positive" Instance. */
private LabelVector createLabelVector (LabelAlphabet labelAlphabet, double[] scores) {
	if (labelAlphabet.growthStopped())
		labelAlphabet.startGrowth();
	
	for (int i=0; i < scores.length; i++) 
		labelAlphabet.lookupIndex(String.valueOf(i), true);

	double[] allScores = new double[labelAlphabet.size()];

	for (int i=0; i < labelAlphabet.size(); i++) 
		allScores[i] = 0.0;

	for (int i=0; i < scores.length; i++) {
		int index = labelAlphabet.lookupIndex(String.valueOf(i), true);
		allScores[index] = scores[i];
	}
	return new LabelVector(labelAlphabet, allScores);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:21,代码来源:RankMaxEnt.java

示例2: ConfusionMatrix

import cc.mallet.types.LabelVector; //导入依赖的package包/类
/**
 * Constructs matrix and calculates values
 * @param t the trial to build matrix from
 */
public ConfusionMatrix(Trial t)
{
	this.trial = t;
	this.classifications = t;
	Labeling tempLabeling =
		((Classification)classifications.get(0)).getLabeling();
	this.numClasses = tempLabeling.getLabelAlphabet().size();
	values = new int[numClasses][numClasses];
	for(int i=0; i < classifications.size(); i++)
	{
		LabelVector lv =
			((Classification)classifications.get(i)).getLabelVector();
		Instance inst = ((Classification)classifications.get(i)).getInstance();
		int bestIndex = lv.getBestIndex();
		int correctIndex = inst.getLabeling().getBestIndex();
		assert(correctIndex != -1);
		//System.out.println("Best index="+bestIndex+". Correct="+correctIndex);
		values[correctIndex][bestIndex]++;
	}			
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:25,代码来源:ConfusionMatrix.java

示例3: classify

import cc.mallet.types.LabelVector; //导入依赖的package包/类
/**
 * Classifies an instance using Winnow's weights
 * @param instance an instance to be classified
 * @return an object containing the classifier's guess
    */
public Classification classify (Instance instance){
	int numClasses = getLabelAlphabet().size();
	double[] scores = new double[numClasses];
	FeatureVector fv = (FeatureVector) instance.getData ();
	// Make sure the feature vector's feature dictionary matches
	// what we are expecting from our data pipe (and thus our notion
	// of feature probabilities.
	assert (instancePipe == null || fv.getAlphabet () == this.instancePipe.getDataAlphabet ());
	int fvisize = fv.numLocations();
	
	// Set the scores by summing wi*xi
	for (int fvi = 0; fvi < fvisize; fvi++) {
		int fi = fv.indexAtLocation (fvi);
		for (int ci = 0; ci < numClasses; ci++)
	    scores[ci] += this.weights[ci][fi];
	}
	
	
	// Create and return a Classification object
	return new Classification (instance, this,
														 new LabelVector (getLabelAlphabet(),
																							scores));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:29,代码来源:Winnow.java

示例4: ConfusionMatrix

import cc.mallet.types.LabelVector; //导入依赖的package包/类
/**
 * Constructs matrix and calculates values
 * @param t the trial to build matrix from
 */
public ConfusionMatrix(Trial t) {
	this.trial = t;
	this.classifications = t;
	Labeling tempLabeling =
		((Classification) classifications.get(0)).getLabeling();
	this.numClasses = tempLabeling.getLabelAlphabet().size();
	values = new int[numClasses][numClasses];
	
	for (int i=0; i < classifications.size(); i++) {
		LabelVector lv =
			((Classification)classifications.get(i)).getLabelVector();
		Instance inst = ((Classification)classifications.get(i)).getInstance();
		int bestIndex = lv.getBestIndex();
		int correctIndex = inst.getLabeling().getBestIndex();
		assert(correctIndex != -1);
		//System.out.println("Best index="+bestIndex+". Correct="+correctIndex);
		
		values[correctIndex][bestIndex]++;
	}			
}
 
开发者ID:iamxiatian,项目名称:wikit,代码行数:25,代码来源:ConfusionMatrix.java

示例5: classify

import cc.mallet.types.LabelVector; //导入依赖的package包/类
@Override
public Classification classify(Instance instance) {
    SparseVector vector = SVMClassifierTrainer.getVector(instance);
    double[] scores = new double[model.nr_class];
    double sLabel = mltLabel2svmLabel.get(instance.getTarget().toString());//(getLabelAlphabet().lookupLabel(instance.getTarget().toString()));
    double p = SVMPredictor.predictProbability(new ca.uwo.csd.ai.nlp.libsvm.ex.Instance(sLabel, vector), model, scores);
    
    //if SVM is not predicting probability then assign a score of 1.0 to the best class(p)
    //and 0.0 to the other classes
    if (!predictProbability) {
        String label = svmLabel2mltLabel.get(p);
        int index = getLabelAlphabet().lookupIndex(label.toString(), false);
        scores[index] = 1.0;
    } else {
        rearrangeScores(scores);
    }        
    Classification classification = new Classification(instance, this,
            new LabelVector(getLabelAlphabet(), scores));

    return classification;
}
 
开发者ID:guanxin0520,项目名称:dhnowFilter,代码行数:22,代码来源:SVMClassifier.java

示例6: applyModel

import cc.mallet.types.LabelVector; //导入依赖的package包/类
@Override
public List<ModelApplication> applyModel(
        AnnotationSet instanceAS, AnnotationSet inputAS, AnnotationSet sequenceAS, String parms) {
  // NOTE: the crm should be of type CorpusRepresentationMalletClass for this to work!
  if(!(corpusRepresentation instanceof CorpusRepresentationMalletTarget)) {
    throw new GateRuntimeException("Cannot perform classification with data from "+corpusRepresentation.getClass());
  }
  CorpusRepresentationMalletTarget data = (CorpusRepresentationMalletTarget)corpusRepresentation;
  data.stopGrowth();
  List<ModelApplication> gcs = new ArrayList<ModelApplication>();
  LFPipe pipe = (LFPipe)data.getRepresentationMallet().getPipe();
  Classifier classifier = (Classifier)model;
  // iterate over the instance annotations and create mallet instances 
  for(Annotation instAnn : instanceAS.inDocumentOrder()) {
    Instance inst = data.extractIndependentFeatures(instAnn, inputAS);
    inst = pipe.instanceFrom(inst);
    Classification classification = classifier.classify(inst);
    Labeling labeling = classification.getLabeling();
    LabelVector labelvec = labeling.toLabelVector();
    List<String> classes = new ArrayList<String>(labelvec.numLocations());
    List<Double> confidences = new ArrayList<Double>(labelvec.numLocations());
    for(int i=0; i<labelvec.numLocations(); i++) {
      classes.add(labelvec.getLabelAtRank(i).toString());
      confidences.add(labelvec.getValueAtRank(i));
    }      
    ModelApplication gc = new ModelApplication(instAnn, labeling.getBestLabel().toString(), 
            labeling.getBestValue(), classes, confidences);
    //System.err.println("ADDING GC "+gc);
    // now save the class in our special class feature on the instance as well
    instAnn.getFeatures().put("gate.LF.target",labeling.getBestLabel().toString());
    gcs.add(gc);
  }
  data.startGrowth();
  return gcs;
}
 
开发者ID:GateNLP,项目名称:gateplugin-LearningFramework,代码行数:36,代码来源:EngineMBMalletClass.java

示例7: add

import cc.mallet.types.LabelVector; //导入依赖的package包/类
/**
 * Adds classification results to the ROC data
 * 
 * @param trial Trial results to add to ROC data
 */
public void add(Classification classification) {
    int correctIndex = classification.getInstance().getLabeling().getBestIndex();
    LabelVector lv = classification.getLabelVector();
    double[] values = lv.getValues();
    
    if (!Alphabet.alphabetsMatch(this, lv)) {
        throw new IllegalArgumentException ("Alphabets do not match");
    }
    
    int numLabels = this.labelAlphabet.size();
    for (int label = 0; label < numLabels; label++) {
        double labelValue = values[label];
        int[][] thresholdCounts = this.counts[label];
        int threshold = 0;
        
        // add the trial to all the thresholds it would be positive for
        for (; threshold < this.thresholds.length && labelValue >= this.thresholds[threshold]; threshold++) {
            if (correctIndex == label) {
                thresholdCounts[threshold][TRUE_POSITIVE]++;
            } else {
                thresholdCounts[threshold][FALSE_POSITIVE]++;
            }
        }
        
        // add the trial to the thresholds it would be negative for
        for (; threshold < this.thresholds.length; threshold++) {
            if (correctIndex == label) {
                thresholdCounts[threshold][FALSE_NEGATIVE]++;
            } else {
                thresholdCounts[threshold][TRUE_NEGATIVE]++;
            }
        }
    }
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:40,代码来源:ROCData.java

示例8: setUp

import cc.mallet.types.LabelVector; //导入依赖的package包/类
protected void setUp ()
{
	ld = new LabelAlphabet ();
	lv = new LabelVector (ld,
												new int[] {
													ld.lookupIndex ("a"),
													ld.lookupIndex ("b"),
													ld.lookupIndex ("c"),
													ld.lookupIndex ("d")},
												new double[] {3, 4, 2, 1});
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:TestLabelVector.java

示例9: pipe

import cc.mallet.types.LabelVector; //导入依赖的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

示例10: classify

import cc.mallet.types.LabelVector; //导入依赖的package包/类
public Classification classify (Instance instance)
{
    int numClasses = getLabelAlphabet().size();
    double[] scores = new double[numClasses];
    getClassificationScores (instance, scores);
    // Create and return a Classification object
    return new Classification (instance, this,
            new LabelVector (getLabelAlphabet(),
                    scores));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:11,代码来源:MCMaxEnt.java

示例11: compare

import cc.mallet.types.LabelVector; //导入依赖的package包/类
public final int compare (Object a, Object b)
{
	LabelVector x = (LabelVector) (((Classification)a).getLabelVector());
	LabelVector y = (LabelVector) (((Classification)b).getLabelVector());
	double difference = x.getBestValue() - y.getBestValue();
	int toReturn = 0;
	if(difference > 0)
		toReturn = 1;
	else if (difference < 0)
		toReturn = -1;
	return(toReturn);		
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:13,代码来源:AccuracyCoverage.java

示例12: printRank

import cc.mallet.types.LabelVector; //导入依赖的package包/类
public void printRank (PrintWriter pw) throws FileNotFoundException
{
	// xxx Fix this.
	/*System.out.print (classifier.getClass().getName() + "(.");
	System.out.print (") = [");
	for (int i = 0; i < labeling.numLocations(); i++)
		System.out.print (labeling.labelAtLocation(i).toString()+"="+labeling.valueAtLocation(i)+" ");
	System.out.println ("]");*/		
	pw.print(classifier.getClass().getName());
	pw.print(" ");
	pw.print(instance.getSource() + " ");
	LabelVector lv = labeling.toLabelVector();
	lv.printByRank(pw);
	pw.println ();
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:16,代码来源:Classification.java

示例13: classify

import cc.mallet.types.LabelVector; //导入依赖的package包/类
/**
  * Classifies an instance using BalancedWinnow's weights
  *
  * <p>Returns a Classification containing the normalized
  * dot products between class weight vectors and the instance 
  * feature vector.
  *
  * <p>One can obtain the confidence of the classification by 
  * calculating weight(j')/weight(j), where j' is the 
  * highest weight prediction and j is the 2nd-highest.
  * Another possibility is to calculate 
  * <br><tt><center>e^{dot(w_j', x} / sum_j[e^{dot(w_j, x)}]</center></tt>
  */
 public Classification classify (Instance instance)
 {
     int numClasses = getLabelAlphabet().size();
     int numFeats = getAlphabet().size();
     double[] scores = new double[numClasses];
     FeatureVector fv = (FeatureVector) instance.getData ();

     // Make sure the feature vector's feature dictionary matches
     // what we are expecting from our data pipe (and thus our notion
     // of feature probabilities.
     assert (instancePipe == null || fv.getAlphabet () == this.instancePipe.getDataAlphabet ());
     int fvisize = fv.numLocations();

     // Take dot products
     double sum = 0;
     for (int ci = 0; ci < numClasses; ci++) {
for (int fvi = 0; fvi < fvisize; fvi++) {
	int fi = fv.indexAtLocation (fvi);
	double vi = fv.valueAtLocation(fvi);

	if ( m_weights[ci].length > fi ) {
	scores[ci] += vi * m_weights[ci][fi];
	sum += vi * m_weights[ci][fi];
	}
}
scores[ci] += m_weights[ci][numFeats];
sum += m_weights[ci][numFeats];
     }
     MatrixOps.timesEquals(scores, 1.0 / sum);

     // Create and return a Classification object
     return new Classification (instance, this, new LabelVector (getLabelAlphabet(), scores));
 }
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:47,代码来源:BalancedWinnow.java

示例14: classify

import cc.mallet.types.LabelVector; //导入依赖的package包/类
public Classification classify (Instance instance)
{
	int numClasses = getLabelAlphabet().size();
	double[] scores = new double[numClasses];
	//getClassificationScores (instance, scores);
	getClassificationScores(instance, scores);
	// Create and return a Classification object
	return new Classification (instance, this,
			new LabelVector (getLabelAlphabet(),
					scores));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:12,代码来源:MaxEnt.java

示例15: classify

import cc.mallet.types.LabelVector; //导入依赖的package包/类
public Classification classify (Instance instance)
{
  int numLabels = ensemble[0].getLabelAlphabet().size();
  double[] scores = new double[numLabels];
  // Run each classifier on the instance, summing each one's per-class score, with a weight
  for (int i = 0; i < ensemble.length; i++) {
    Classification c = ensemble[i].classify(instance);
    c.getLabelVector().addTo(scores, weights[i]);
  }
  // Exponentiate and normalize scores
  expNormalize (scores);
  return new Classification (instance, this, new LabelVector (ensemble[0].getLabelAlphabet(), scores));
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:14,代码来源:ClassifierEnsemble.java


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