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


Java AugmentableFeatureVector.numLocations方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: addDataHandler

import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
public void addDataHandler(DataHandler dh) throws DataMiningException {
  if (!(dh instanceof MalletDataHandler)) {
    throw new DataMiningException("MalletDataHandler can add just MalletDataHandlers");
  }
  for (String inst : dh.getInstanceIds()) {
    AugmentableFeatureVector fv = ((MalletDataHandler) dh).getInstanceData(inst);
    for (int i = 0; i < fv.numLocations(); ++i) {
      this.setDoubleValue(inst, (String) fv.getAlphabet().lookupObject(fv.getIndices()[i]), fv.getValues()[i]);
    }
    this.setLabel(inst, dh.getLabel(inst));
  }
}
 
开发者ID:begab,项目名称:kpe,代码行数:13,代码来源:MalletDataHandler.java

示例5: saveDatasetWeka

import cc.mallet.types.AugmentableFeatureVector; //导入方法依赖的package包/类
public void saveDatasetWeka(String target) {
  try {
    if (!target.endsWith(".arff")) {
      target += ".arff";
    }
    PrintWriter out = new PrintWriter(target);
    out.println("@relation MalletData");
    for (Object f : data.getAlphabet().toArray()) {
      String name = f.toString().replaceAll("'", "");
      out.println("@attribute '" + name + "' numeric");
    }
    out.println("@attribute classlabel {0,1}");
    out.println("@data");
    for (String id : instanceIds.keySet()) {
      out.print("{");
      AugmentableFeatureVector fv = getInstanceData(id);
      for (int i = 0; i < fv.numLocations(); ++i) {
        if (i > 0) {
          out.print(",");
        }
        out.print((fv.getIndices()[i]) + " " + fv.getValues()[i]);
      }
      if ((boolean) getLabel(id)) {
        out.print("," + data.getAlphabet().size() + " 1");
      }
      out.println("}");
    }
    out.close();
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  }
}
 
开发者ID:begab,项目名称:kpe,代码行数:33,代码来源:MalletDataHandler.java


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