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


Java InstanceList.add方法代码示例

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


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

示例1: deserializePage

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/** Deserialize a page. This restores a page serialized using
 * {@link #serializePage(ObjectOutputStream, InstanceList)}.
 * @param in Object input stream
 * @return New page
 * @throws IOException
 * @throws ClassNotFoundException
 */
private InstanceList deserializePage(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    InstanceList page = new InstanceList(noopPipe);
    int size = in.readInt();
    
    for (int i = 0; i < size; i++) {
        Object data = deserializeObject (in);
        Object target = deserializeObject (in);
        Object name = in.readObject ();
        Object source = in.readObject ();
        double weight = in.readDouble ();
        page.add (new Instance (data, target, name, source), weight);
    }
    
    return page;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:24,代码来源:PagedInstanceList.java

示例2: split

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public void split (FeatureSelection fs)
{
	if (ilist == null)
		throw new IllegalStateException ("Frozen.  Cannot split.");
	InstanceList ilist0 = new InstanceList (ilist.getPipe());
	InstanceList ilist1 = new InstanceList (ilist.getPipe());
	for (int i = 0; i < ilist.size(); i++) {
		Instance instance = ilist.get(i);
		FeatureVector fv = (FeatureVector) instance.getData ();
		// xxx What test should this be?  What to do with negative values?
			// Whatever is decided here should also go in InfoGain.calcInfoGains()
		if (fv.value (featureIndex) != 0) {
			//System.out.println ("list1 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i));
			ilist1.add (instance, ilist.getInstanceWeight(i));
		} else {
			//System.out.println ("list0 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i));
			ilist0.add (instance, ilist.getInstanceWeight(i));
		}
	}
	logger.info("child0="+ilist0.size()+" child1="+ilist1.size());
	child0 = new Node (ilist0, this, fs);
	child1 = new Node (ilist1, this, fs);
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:24,代码来源:DecisionTree.java

示例3: shallowClone

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public InstanceList shallowClone () {
    InstanceList ret = this.cloneEmpty ();
    for (int i = 0; i < this.size (); i++) {
        ret.add (get (i));
    }
    return ret;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:8,代码来源:PagedInstanceList.java

示例4: convert

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/**
 * Converts each instance containing a FeatureVectorSequence to multiple instances, 
 * each containing an AugmentableFeatureVector as data.  
 *  
 * @param ilist Instances with FeatureVectorSequence as data field
 * @param alphabetsPipe a Noop pipe containing the data and target alphabets for the resulting InstanceList 
 * @return an InstanceList where each Instance contains one Token's AugmentableFeatureVector as data 
 */
public static InstanceList convert(InstanceList ilist, Noop alphabetsPipe)
{
	if (ilist == null) return null;
	
	// This monstrosity is necessary b/c Classifiers obtain the data/target alphabets via pipes
	InstanceList ret = new InstanceList(alphabetsPipe);

	for (Instance inst : ilist)
		ret.add(inst);
	//for (int i = 0; i < ilist.size(); i++) ret.add(convert(ilist.get(i), alphabetsPipe));

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

示例5: getInstances

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public InstanceList getInstances() 
{ 
	InstanceList ret = new InstanceList(m_ilist.getPipe());
	for (int ii = 0; ii < m_instIndices.length; ii++)
		ret.add(m_ilist.get(m_instIndices[ii]));
	return ret; 
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:8,代码来源:C45.java

示例6: train

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public NaiveBayes train (InstanceList trainingSet)
{

  // Get a classifier trained on the labeled examples only
  NaiveBayes c = (NaiveBayes) nbTrainer.newClassifierTrainer().train (trainingSet);
  double prevLogLikelihood = 0, logLikelihood = 0;
  boolean converged = false;

  int iteration = 0;
  while (!converged) {
    // Make a new trainingSet that has some labels set
    InstanceList trainingSet2 = new InstanceList (trainingSet.getPipe());
    for (int ii = 0; ii < trainingSet.size(); ii++) {
      Instance inst = trainingSet.get(ii);
      if (inst.getLabeling() != null)
        trainingSet2.add(inst, 1.0);
      else {
        Instance inst2 = inst.shallowCopy();
        inst2.unLock();
        inst2.setLabeling(c.classify(inst).getLabeling());
        inst2.lock();
        trainingSet2.add(inst2, unlabeledDataWeight);
      }
    }
    c = (NaiveBayes) nbTrainer.newClassifierTrainer().train (trainingSet2);
    logLikelihood = c.dataLogLikelihood (trainingSet2);
    System.err.println ("Loglikelihood = "+logLikelihood);
    // Wait for a change in log-likelihood of less than 0.01% and at least 10 iterations
    if (Math.abs((logLikelihood - prevLogLikelihood)/logLikelihood) < 0.0001)
      converged = true;
    prevLogLikelihood = logLikelihood;
    iteration++;
  }
  return c;    
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:36,代码来源:NaiveBayesEMTrainer.java

示例7: getCluster

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/** Return an list of instances with a particular label. */
public InstanceList getCluster(int label) {		
	InstanceList cluster = new InstanceList(instances.getPipe());		
	for (int n=0 ; n<instances.size() ; n++) 
    if (labels[n] == label)
			cluster.add(instances.get(n));			
	return cluster;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:9,代码来源:Clustering.java

示例8: combineLists

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/**
 * @param li
 * @param lj
 * @return A new {@link InstanceList} where <code>lj</code> is appended to <code>li</code>.
 */
public static InstanceList combineLists (InstanceList li,
																				 InstanceList lj) {
	InstanceList newList = new InstanceList(li.getPipe());
	for (int i = 0; i < li.size(); i++) 
		newList.add(li.get(i));
	for (int i = 0; i < lj.size(); i++) 
		newList.add(lj.get(i));
	return newList;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:15,代码来源:ClusterUtils.java

示例9: makeList

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/**
 *
 * @param i
 * @param j
 * @return A new {@link InstanceList} containing the two argument {@link Instance}s.
 */
public static InstanceList makeList (Instance i, Instance j) {
	InstanceList list = new InstanceList(new Noop(i.getDataAlphabet(), i.getTargetAlphabet()));
	list.add(i);
	list.add(j);
	return list;
}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:13,代码来源:ClusterUtils.java

示例10: main

import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public static void main (String[] args) throws IOException {
	CommandOption
								.setSummary(Text2Clusterings.class,
														"A tool to convert a list of text files to a Clusterings.");
	CommandOption.process(Text2Clusterings.class, args);

	if (classDirs.value.length == 0) {
		logger
					.warning("You must include --input DIR1 DIR2 ...' in order to specify a"
										+ "list of directories containing the documents for each class.");
		System.exit(-1);
	}

	Clustering[] clusterings = new Clustering[classDirs.value.length];
	int fi = 0;
	for (int i = 0; i < classDirs.value.length; i++) {
		Alphabet fieldAlph = new Alphabet();
		Alphabet valueAlph = new Alphabet();
		File directory = new File(classDirs.value[i]);
		File[] subdirs = getSubDirs(directory);
		Alphabet clusterAlph = new Alphabet();
		InstanceList instances = new InstanceList(new Noop());
		TIntArrayList labels = new TIntArrayList();
		for (int j = 0; j < subdirs.length; j++) {
			ArrayList<File> records = new FileIterator(subdirs[j]).getFileArray();
			int label = clusterAlph.lookupIndex(subdirs[j].toString());
			for (int k = 0; k < records.size(); k++) {
				if (fi % 100 == 0) System.out.print(fi);
				else if (fi % 10 == 0) System.out.print(".");
				if (fi % 1000 == 0 && fi > 0) System.out.println();
				System.out.flush();
				fi++;


				File record = records.get(k);
				labels.add(label);
				instances.add(new Instance(new Record(fieldAlph, valueAlph, parseFile(record)),
											new Integer(label), record.toString(),
											record.toString()));
			}
		}
		clusterings[i] =
				new Clustering(instances, subdirs.length, labels.toNativeArray());
	}

	logger.info("\nread " + fi + " objects in " + clusterings.length + " clusterings.");
	try {
		ObjectOutputStream oos =
				new ObjectOutputStream(new FileOutputStream(outputFile.value));
		oos.writeObject(new Clusterings(clusterings));
		oos.close();
	} catch (Exception e) {
		logger.warning("Exception writing clustering to file " + outputFile.value
										+ " " + e);
		e.printStackTrace();
	}

}
 
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:59,代码来源:Text2Clusterings.java


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