• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java StringLocator类的典型用法和代码示例

java 2次浏览

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

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

示例1: copyValues

点赞 2

import weka.core.StringLocator; //导入依赖的package包/类
/**
  * Copies string/relational values contained in the instance copied to a new
  * dataset. The Instance must already be assigned to a dataset. This
  * dataset and the destination dataset must have the same structure.
  *
  * @param instance		the Instance containing the string/relational 
  * 				values to copy.
  * @param isInput		if true the input format and input attribute 
  * 				locators are used otherwise the output format 
  * 				and output locators
  */
 protected void copyValues(Instance instance, boolean isInput) {

   RelationalLocator.copyRelationalValues(
instance, 
(isInput) ? m_InputFormat : m_OutputFormat, 
(isInput) ? m_InputRelAtts : m_OutputRelAtts);

   StringLocator.copyStringValues(
instance, 
(isInput) ? m_InputFormat : m_OutputFormat, 
(isInput) ? m_InputStringAtts : m_OutputStringAtts);
 }
 

开发者ID:dsibournemouth,
项目名称:autoweka,
代码行数:24,
代码来源:Filter.java

示例2: setInputFormat

点赞 2

import weka.core.StringLocator; //导入依赖的package包/类
/**
 * Sets the format of the input instances.
 *
 * @param instanceInfo an Instances object containing the input 
 * instance structure (any instances contained in the object are 
 * ignored - only the structure is required).
 * @return true if the outputFormat may be collected immediately
 * @throws Exception if the input format can't be set 
 * successfully
 */
public boolean setInputFormat(Instances instanceInfo) 
  throws Exception {

  if (instanceInfo.attribute(1).type()!=Attribute.RELATIONAL) {
    throw new Exception("Can only handle relational-valued attribute!");
  }  
  super.setInputFormat(instanceInfo);   

  m_NumBags = instanceInfo.numInstances();
  m_NumInstances = 0;
  for (int i=0; i<m_NumBags; i++)
    if (instanceInfo.instance(i).relationalValue(1) == null) {
      m_NumInstances++;
    } else {
      m_NumInstances += instanceInfo.instance(i).relationalValue(1).numInstances();
    }

  Attribute classAttribute = (Attribute) instanceInfo.classAttribute().copy();
  Attribute bagIndex = (Attribute) instanceInfo.attribute(0).copy();

  /* create a new output format (propositional instance format) */
  Instances newData = instanceInfo.attribute(1).relation().stringFreeStructure();
  newData.insertAttributeAt(bagIndex, 0);
  newData.insertAttributeAt(classAttribute, newData.numAttributes());
  newData.setClassIndex(newData.numAttributes() - 1);

  super.setOutputFormat(newData.stringFreeStructure());

  m_BagStringAtts = new StringLocator(instanceInfo.attribute(1).relation().stringFreeStructure());
  m_BagRelAtts    = new RelationalLocator(instanceInfo.attribute(1).relation().stringFreeStructure());

  return true;
}
 

开发者ID:williamClanton,
项目名称:jbossBA,
代码行数:44,
代码来源:MultiInstanceToPropositional.java

示例3: setInputFormat

点赞 2

import weka.core.StringLocator; //导入依赖的package包/类
/**
 * Sets the format of the input instances.
 *
 * @param instanceInfo an Instances object containing the input 
 * instance structure (any instances contained in the object are 
 * ignored - only the structure is required).
 * @return true if the outputFormat may be collected immediately
 * @throws Exception if the input format can't be set 
 * successfully
 */
public boolean setInputFormat(Instances instanceInfo) 
  throws Exception {

  if (instanceInfo.attribute(0).type()!= Attribute.NOMINAL) {
    throw new Exception("The first attribute type of the original propositional instance dataset must be Nominal!");
  }
  super.setInputFormat(instanceInfo);

  /* create a new output format (multi-instance format) */
  Instances newData = instanceInfo.stringFreeStructure();
  Attribute attBagIndex = (Attribute) newData.attribute(0).copy();
  Attribute attClass = (Attribute) newData.classAttribute().copy();
  // remove the bagIndex attribute
  newData.deleteAttributeAt(0);
  // remove the class attribute
  newData.setClassIndex(-1);
  newData.deleteAttributeAt(newData.numAttributes() - 1);

  FastVector attInfo = new FastVector(3); 
  attInfo.addElement(attBagIndex);
  attInfo.addElement(new Attribute("bag", newData)); // relation-valued attribute
  attInfo.addElement(attClass);
  Instances data = new Instances("Multi-Instance-Dataset", attInfo, 0); 
  data.setClassIndex(data.numAttributes() - 1);

  super.setOutputFormat(data.stringFreeStructure());

  m_BagStringAtts = new StringLocator(data.attribute(1).relation());
  m_BagRelAtts    = new RelationalLocator(data.attribute(1).relation());
  
  return true;
}
 

开发者ID:williamClanton,
项目名称:jbossBA,
代码行数:43,
代码来源:PropositionalToMultiInstance.java

示例4: addBag

点赞 2

import weka.core.StringLocator; //导入依赖的package包/类
/**
 * adds a new bag out of the given data and adds it to the output
 * 
 * @param input       the intput dataset
 * @param output      the dataset this bag is added to
 * @param bagInsts    the instances in this bag
 * @param bagIndex    the bagIndex of this bag
 * @param classValue  the associated class value
 * @param bagWeight   the weight of the bag
 */
protected void addBag(
    Instances input,
    Instances output,
    Instances bagInsts, 
    int bagIndex, 
    double classValue, 
    double bagWeight) {
  
  // copy strings/relational values
  for (int i = 0; i < bagInsts.numInstances(); i++) {
    RelationalLocator.copyRelationalValues(
 bagInsts.instance(i), false, 
 input, m_InputRelAtts,
 bagInsts, m_BagRelAtts);

    StringLocator.copyStringValues(
 bagInsts.instance(i), false, 
 input, m_InputStringAtts,
 bagInsts, m_BagStringAtts);
  }
  
  int value = output.attribute(1).addRelation(bagInsts);
  Instance newBag = new Instance(output.numAttributes());        
  newBag.setValue(0, bagIndex);
  newBag.setValue(2, classValue);
  newBag.setValue(1, value);
  if (!m_DoNotWeightBags) {
    newBag.setWeight(bagWeight);
  }
  newBag.setDataset(output);
  output.add(newBag);
}
 

开发者ID:williamClanton,
项目名称:jbossBA,
代码行数:43,
代码来源:PropositionalToMultiInstance.java

示例5: convertInstance

点赞 2

import weka.core.StringLocator; //导入依赖的package包/类
/**
 * Convert a single bag over. The converted instances is 
 * added to the end of the output queue.
 *
 * @param bag the bag to convert
 */
private void convertInstance(Instance bag) {

  Instances data = bag.relationalValue(1);
  int bagSize = 1;
  if (data != null) {
    bagSize = data.numInstances();
  }
  double bagIndex = bag.value(0);
  double classValue = bag.classValue();
  double weight = 0.0; 
  //the proper weight for each instance in a bag 
  if (m_WeightMethod == WEIGHTMETHOD_1)
    weight = 1.0;
  else if (m_WeightMethod == WEIGHTMETHOD_INVERSE1)
    weight = (double) 1.0 / bagSize;
  else if (m_WeightMethod == WEIGHTMETHOD_INVERSE2)
    weight=(double) m_NumInstances / (m_NumBags * bagSize);
  else 
    weight = (double) bag.weight() / bagSize;

  Instance newInst;
  Instances outputFormat = getOutputFormat().stringFreeStructure();

  for (int i = 0; i < bagSize; i++) {
    newInst = new Instance(outputFormat.numAttributes());
    newInst.setDataset(outputFormat);
    newInst.setValue(0,bagIndex);
    if (!bag.classIsMissing())
      newInst.setClassValue(classValue);
    // copy the attribute values to new instance
    for (int j = 1; j < outputFormat.numAttributes() - 1; j++){
      if (data == null) {
        newInst.setMissing(j);
      } else {
        newInst.setValue(j,data.instance(i).value(j - 1));
      }
    }	

    newInst.setWeight(weight);

    // copy strings/relational values
    StringLocator.copyStringValues(
 newInst, false, 
 data, m_BagStringAtts, 
 outputFormat, m_OutputStringAtts);

    RelationalLocator.copyRelationalValues(
 newInst, false, 
 data, m_BagRelAtts, 
 outputFormat, m_OutputRelAtts);
    
    push(newInst);
  }
}
 

开发者ID:williamClanton,
项目名称:jbossBA,
代码行数:61,
代码来源:MultiInstanceToPropositional.java

示例6: copyValues

点赞 1

import weka.core.StringLocator; //导入依赖的package包/类
/**
 * Copies string/relational values contained in the instance copied to a new
 * dataset. The Instance must already be assigned to a dataset. This dataset
 * and the destination dataset must have the same structure.
 *
 * @param instance the Instance containing the string/relational values to
 *          copy.
 * @param isInput if true the input format and input attribute locators are
 *          used otherwise the output format and output locators
 */
protected void copyValues(Instance instance, boolean isInput) {

  RelationalLocator.copyRelationalValues(instance, (isInput) ? m_InputFormat
    : m_OutputFormat, (isInput) ? m_InputRelAtts : m_OutputRelAtts);

  StringLocator.copyStringValues(instance, (isInput) ? m_InputFormat
    : m_OutputFormat, (isInput) ? m_InputStringAtts : m_OutputStringAtts);
}
 

开发者ID:mydzigear,
项目名称:repo.kmeanspp.silhouette_score,
代码行数:19,
代码来源:Filter.java

示例7: copyValues

点赞 1

import weka.core.StringLocator; //导入依赖的package包/类
/**
 * Copies string/relational values contained in the instance copied to a new
 * dataset. The Instance must already be assigned to a dataset. This dataset
 * and the destination dataset must have the same structure.
 * 
 * @param instance the Instance containing the string/relational values to
 *          copy.
 * @param isInput if true the input format and input attribute locators are
 *          used otherwise the output format and output locators
 */
protected void copyValues(Instance instance, boolean isInput) {

  RelationalLocator.copyRelationalValues(instance, (isInput) ? m_InputFormat
    : m_OutputFormat, (isInput) ? m_InputRelAtts : m_OutputRelAtts);

  StringLocator.copyStringValues(instance, (isInput) ? m_InputFormat
    : m_OutputFormat, (isInput) ? m_InputStringAtts : m_OutputStringAtts);
}
 

开发者ID:umple,
项目名称:umple,
代码行数:19,
代码来源:Filter.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)