Java 类weka.core.UnsupportedAttributeTypeException 实例源码

项目:repo.kmeanspp.silhouette_score    文件:SwapValues.java   
/**
 * 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 UnsupportedAttributeTypeException if the selected attribute is not
 *           nominal or if it only has one value.
 * @throws Exception if the input format can't be set successfully
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute has less than " + "two values.");
  }
  setOutputFormat();
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:MakeIndicator.java   
/**
 * 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 UnsupportedAttributeTypeException the selecte attribute is not
 *           nominal
 * @throws UnsupportedAttributeTypeException the selecte attribute has fewer
 *           than two values.
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_ValIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less "
      + "than two values.");
  }
  setOutputFormat();
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:MergeManyValues.java   
/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {
  super.setInputFormat(instanceInfo);

  m_AttIndex.setUpper(inputFormatPeek().numAttributes() - 1);

  m_MergeRange.setUpper(inputFormatPeek().attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if ((inputFormatPeek().classIndex() > -1)
    && (inputFormatPeek().classIndex() == m_AttIndex.getIndex())) {
    throw new Exception("Cannot process class attribute.");
  }
  if (!inputFormatPeek().attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (inputFormatPeek().attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute has less than " + "two values.");
  }

  setOutputFormat();
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:RemoveFrequentValues.java   
/**
 * 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 can be collected immediately
 * @throws UnsupportedAttributeTypeException if the specified attribute is not
 *           nominal.
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {
  super.setInputFormat(instanceInfo);

  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);

  if (!isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Can only handle nominal attributes.");
  }

  m_Values = null;

  return false;
}
项目:autoweka    文件:SwapValues.java   
/**
 * 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 UnsupportedAttributeTypeException if the selected attribute
 * is not nominal or if it only has one value.
 * @throws Exception if the input format can't be set 
 * successfully
 */
public boolean setInputFormat(Instances instanceInfo) 
     throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.
      attribute(m_AttIndex.getIndex()).numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.
       attribute(m_AttIndex.getIndex()).numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less than " 
                  + "two values.");
  }
  setOutputFormat();
  return true;
}
项目:autoweka    文件:MakeIndicator.java   
/**
 * 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 UnsupportedAttributeTypeException the selecte attribute is not nominal
 * @throws UnsupportedAttributeTypeException the selecte attribute has fewer than two values.
 */
public boolean setInputFormat(Instances instanceInfo) 
     throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_ValIndex.setUpper(instanceInfo.attribute(m_AttIndex.
                   getIndex()).numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less " +
                  "than two values.");
  }
  setOutputFormat();
  return true;
}
项目:autoweka    文件:MergeManyValues.java   
/**
 * 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 {
  super.setInputFormat(instanceInfo);

  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);

  m_MergeRange.setUpper(instanceInfo.attribute(m_AttIndex.getIndex()).numValues() - 1);
  if ((instanceInfo.classIndex() > -1) && (instanceInfo.classIndex() == m_AttIndex.getIndex())) {
    throw new Exception("Cannot process class attribute.");
  }
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less than " +
    "two values.");
  }

  setOutputFormat();
  return true;
}
项目:umple    文件:SwapValues.java   
/**
 * 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 UnsupportedAttributeTypeException if the selected attribute is not
 *           nominal or if it only has one value.
 * @throws Exception if the input format can't be set successfully
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute has less than " + "two values.");
  }
  setOutputFormat();
  return true;
}
项目:umple    文件:MakeIndicator.java   
/**
 * 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 UnsupportedAttributeTypeException the selecte attribute is not
 *           nominal
 * @throws UnsupportedAttributeTypeException the selecte attribute has fewer
 *           than two values.
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_ValIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less "
      + "than two values.");
  }
  setOutputFormat();
  return true;
}
项目:umple    文件:MergeManyValues.java   
/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {
  super.setInputFormat(instanceInfo);

  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);

  m_MergeRange.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if ((instanceInfo.classIndex() > -1)
    && (instanceInfo.classIndex() == m_AttIndex.getIndex())) {
    throw new Exception("Cannot process class attribute.");
  }
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute has less than " + "two values.");
  }

  setOutputFormat();
  return true;
}
项目:umple    文件:RemoveFrequentValues.java   
/**
 * 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 can be collected immediately
 * @throws UnsupportedAttributeTypeException if the specified attribute is not
 *           nominal.
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {
  super.setInputFormat(instanceInfo);

  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);

  if (!isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Can only handle nominal attributes.");
  }

  m_Values = null;

  return false;
}
项目:petablox    文件:MyId3.java   
/**
 * Builds Id3 decision tree classifier.
 * 
 * @param data
 *            the training data
 * @exception Exception
 *                if classifier can't be built successfully
 */
public void buildClassifier(Instances data) throws Exception {
    if (!data.classAttribute().isNominal()) {
        throw new UnsupportedClassTypeException("Id3: nominal class, please.");
    }
    Enumeration enumAtt = data.enumerateAttributes();
    while (enumAtt.hasMoreElements()) {
        if (!((Attribute) enumAtt.nextElement()).isNominal()) {
            throw new UnsupportedAttributeTypeException("Id3: only nominal "
                + "attributes, please.");
        }
    }
    data = new Instances(data);
    data.deleteWithMissingClass();
    makeTree(data);
}
项目:jbossBA    文件:HyperPipes.java   
/**
    * Creates the HyperPipe as the n-dimensional parallel-piped 
    * with minimum volume containing all the points in
    * pointSet.
    *
    * @param instances all instances belonging to the same class
    * @throws Exception if missing values are found
    */
   public HyperPipe(Instances instances) throws Exception {

     m_NumericBounds = new double [instances.numAttributes()][];
     m_NominalBounds = new boolean [instances.numAttributes()][];

     for (int i = 0; i < instances.numAttributes(); i++) {
switch (instances.attribute(i).type()) {
case Attribute.NUMERIC:
  m_NumericBounds[i] = new double [2];
  m_NumericBounds[i][0] = Double.POSITIVE_INFINITY;
  m_NumericBounds[i][1] = Double.NEGATIVE_INFINITY;
  break;
case Attribute.NOMINAL:
  m_NominalBounds[i] = new boolean [instances.attribute(i).numValues()];
  break;
default:
  throw new UnsupportedAttributeTypeException("Cannot process string attributes!");
}
     }

     for (int i = 0; i < instances.numInstances(); i++) {
addInstance(instances.instance(i));
     }
   }
项目:jbossBA    文件:SwapValues.java   
/**
 * 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 UnsupportedAttributeTypeException if the selected attribute
 * is not nominal or if it only has one value.
 * @throws Exception if the input format can't be set 
 * successfully
 */
public boolean setInputFormat(Instances instanceInfo) 
     throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.
      attribute(m_AttIndex.getIndex()).numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.
       attribute(m_AttIndex.getIndex()).numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less than " 
                  + "two values.");
  }
  setOutputFormat();
  return true;
}
项目:jbossBA    文件:MakeIndicator.java   
/**
 * 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 UnsupportedAttributeTypeException the selecte attribute is not nominal
 * @throws UnsupportedAttributeTypeException the selecte attribute has fewer than two values.
 */
public boolean setInputFormat(Instances instanceInfo) 
     throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_ValIndex.setUpper(instanceInfo.attribute(m_AttIndex.
                   getIndex()).numValues() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less " +
                  "than two values.");
  }
  setOutputFormat();
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:MergeTwoValues.java   
/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if ((instanceInfo.classIndex() > -1)
    && (instanceInfo.classIndex() == m_AttIndex.getIndex())) {
    throw new Exception("Cannot process class attribute.");
  }
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute has less than " + "two values.");
  }
  if (m_SecondIndex.getIndex() <= m_FirstIndex.getIndex()) {
    // XXX Maybe we should just swap the values??
    throw new Exception("The second index has to be greater "
      + "than the first.");
  }
  setOutputFormat();
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:TimeSeriesDelta.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric.  
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesDelta: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + " d"
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Time delta attributes must be numeric!");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:TimeSeriesTranslate.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric or nominal.
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesTranslate: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNominal()
            || outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Only numeric and nominal attributes may be "
                                                      + " manipulated in time series.");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:ChangeDateFormat.java   
/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isDate()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not date.");
  }

  setOutputFormat();
  return true;
}
项目:autoweka    文件:MergeTwoValues.java   
/**
 * 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 {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.
      attribute(m_AttIndex.getIndex()).numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.
       attribute(m_AttIndex.getIndex()).numValues() - 1);
  if ((instanceInfo.classIndex() > -1) && (instanceInfo.classIndex() == m_AttIndex.getIndex())) {
    throw new Exception("Cannot process class attribute.");
  }
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less than " +
                  "two values.");
  }
  if (m_SecondIndex.getIndex() <= m_FirstIndex.getIndex()) {
    // XXX Maybe we should just swap the values??
    throw new Exception("The second index has to be greater "+
      "than the first.");
  }
  setOutputFormat();
  return true;
}
项目:autoweka    文件:TimeSeriesDelta.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric.  
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesDelta: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + " d"
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Time delta attributes must be numeric!");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:autoweka    文件:TimeSeriesTranslate.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric or nominal.
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesTranslate: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNominal()
            || outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Only numeric and nominal attributes may be "
                                                      + " manipulated in time series.");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:autoweka    文件:ChangeDateFormat.java   
/**
 * 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 {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isDate()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not date.");
  }

  setOutputFormat();
  return true;
}
项目:umple    文件:MergeTwoValues.java   
/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.attribute(m_AttIndex.getIndex())
    .numValues() - 1);
  if ((instanceInfo.classIndex() > -1)
    && (instanceInfo.classIndex() == m_AttIndex.getIndex())) {
    throw new Exception("Cannot process class attribute.");
  }
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException(
      "Chosen attribute has less than " + "two values.");
  }
  if (m_SecondIndex.getIndex() <= m_FirstIndex.getIndex()) {
    // XXX Maybe we should just swap the values??
    throw new Exception("The second index has to be greater "
      + "than the first.");
  }
  setOutputFormat();
  return true;
}
项目:umple    文件:TimeSeriesDelta.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric.  
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesDelta: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + " d"
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Time delta attributes must be numeric!");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:umple    文件:TimeSeriesTranslate.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric or nominal.
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesTranslate: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNominal()
            || outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Only numeric and nominal attributes may be "
                                                      + " manipulated in time series.");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:umple    文件:ChangeDateFormat.java   
/**
 * 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
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isDate()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not date.");
  }

  setOutputFormat();
  return true;
}
项目:jbossBA    文件:MergeTwoValues.java   
/**
 * 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 {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  m_FirstIndex.setUpper(instanceInfo.
      attribute(m_AttIndex.getIndex()).numValues() - 1);
  m_SecondIndex.setUpper(instanceInfo.
       attribute(m_AttIndex.getIndex()).numValues() - 1);
  if ((instanceInfo.classIndex() > -1) && (instanceInfo.classIndex() == m_AttIndex.getIndex())) {
    throw new Exception("Cannot process class attribute.");
  }
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isNominal()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");
  }
  if (instanceInfo.attribute(m_AttIndex.getIndex()).numValues() < 2) {
    throw new UnsupportedAttributeTypeException("Chosen attribute has less than " +
                  "two values.");
  }
  if (m_SecondIndex.getIndex() <= m_FirstIndex.getIndex()) {
    // XXX Maybe we should just swap the values??
    throw new Exception("The second index has to be greater "+
      "than the first.");
  }
  setOutputFormat();
  return true;
}
项目:jbossBA    文件:TimeSeriesDelta.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric.  
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesDelta: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + " d"
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Time delta attributes must be numeric!");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:jbossBA    文件:TimeSeriesTranslate.java   
/**
 * 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 UnsupportedAttributeTypeException if selected
 * attributes are not numeric or nominal.
 */
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  if ((instanceInfo.classIndex() > 0) && (!getFillWithMissing())) {
    throw new IllegalArgumentException("TimeSeriesTranslate: Need to fill in missing values " +
                                       "using appropriate option when class index is set.");
  }
  super.setInputFormat(instanceInfo);
  // Create the output buffer
  Instances outputFormat = new Instances(instanceInfo, 0); 
  for(int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (i != instanceInfo.classIndex()) {
      if (m_SelectedCols.isInRange(i)) {
        if (outputFormat.attribute(i).isNominal()
            || outputFormat.attribute(i).isNumeric()) {
          outputFormat.renameAttribute(i, outputFormat.attribute(i).name()
                                       + (m_InstanceRange < 0 ? '-' : '+')
                                       + Math.abs(m_InstanceRange));
        } else {
          throw new UnsupportedAttributeTypeException("Only numeric and nominal attributes may be "
                                                      + " manipulated in time series.");
        }
      }
    }
  }
  outputFormat.setClassIndex(instanceInfo.classIndex());
  setOutputFormat(outputFormat);
  return true;
}
项目:jbossBA    文件:ChangeDateFormat.java   
/**
 * 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 {

  super.setInputFormat(instanceInfo);
  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  if (!instanceInfo.attribute(m_AttIndex.getIndex()).isDate()) {
    throw new UnsupportedAttributeTypeException("Chosen attribute not date.");
  }

  setOutputFormat();
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:FirstOrder.java   
/**
 * 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 UnsupportedAttributeTypeException if any of the selected attributes
 *           are not numeric
 * @throws Exception if only one attribute has been selected.
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);

  m_DeltaCols.setUpper(getInputFormat().numAttributes() - 1);
  int selectedCount = 0;
  for (int i = getInputFormat().numAttributes() - 1; i >= 0; i--) {
    if (m_DeltaCols.isInRange(i)) {
      selectedCount++;
      if (!getInputFormat().attribute(i).isNumeric()) {
        throw new UnsupportedAttributeTypeException(
          "Selected attributes must be all numeric");
      }
    }
  }
  if (selectedCount == 1) {
    throw new Exception("Cannot select only one attribute.");
  }

  // Create the output buffer
  ArrayList<Attribute> newAtts = new ArrayList<Attribute>();
  boolean inRange = false;
  String foName = null;
  int clsIndex = -1;
  for (int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (m_DeltaCols.isInRange(i) && (i != instanceInfo.classIndex())) {
      if (inRange) {
        Attribute newAttrib = new Attribute(foName);
        newAtts.add(newAttrib);
      }
      foName = instanceInfo.attribute(i).name();
      foName = "'FO " + foName.replace('\'', ' ').trim() + '\'';
      inRange = true;
    } else {
      newAtts.add((Attribute) instanceInfo.attribute(i).copy());
      if ((i == instanceInfo.classIndex())) {
        clsIndex = newAtts.size() - 1;
      }
    }
  }
  Instances data = new Instances(instanceInfo.relationName(), newAtts, 0);
  data.setClassIndex(clsIndex);
  setOutputFormat(data);
  return true;
}
项目:repo.kmeanspp.silhouette_score    文件:RemoveWithValues.java   
/**
 * 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).
 * @throws UnsupportedAttributeTypeException if the specified attribute is
 *           neither numeric or nominal.
 * @return true because outputFormat can be collected immediately
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);

  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  if (!isNumeric() && !isNominal()) {
    throw new UnsupportedAttributeTypeException("Can only handle numeric "
      + "or nominal attributes.");
  }
  m_Values
    .setUpper(instanceInfo.attribute(m_AttIndex.getIndex()).numValues() - 1);
  if (isNominal() && m_ModifyHeader) {
    instanceInfo = new Instances(instanceInfo, 0); // copy before modifying
    Attribute oldAtt = instanceInfo.attribute(m_AttIndex.getIndex());
    int[] selection = m_Values.getSelection();
    ArrayList<String> newVals = new ArrayList<String>();
    for (int element : selection) {
      newVals.add(oldAtt.value(element));
    }
    Attribute newAtt = new Attribute(oldAtt.name(), newVals);
    newAtt.setWeight(oldAtt.weight());
    instanceInfo.replaceAttributeAt(newAtt, m_AttIndex.getIndex());
    m_NominalMapping = new int[oldAtt.numValues()];
    for (int i = 0; i < m_NominalMapping.length; i++) {
      boolean found = false;
      for (int j = 0; j < selection.length; j++) {
        if (selection[j] == i) {
          m_NominalMapping[i] = j;
          found = true;
          break;
        }
      }
      if (!found) {
        m_NominalMapping[i] = -1;
      }
    }
  }
  setOutputFormat(instanceInfo);
  return true;
}
项目:autoweka    文件:FirstOrder.java   
/**
  * 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 UnsupportedAttributeTypeException if any of the
  * selected attributes are not numeric 
  * @throws Exception if only one attribute has been selected.
  */
 public boolean setInputFormat(Instances instanceInfo) throws Exception {

   super.setInputFormat(instanceInfo);

   m_DeltaCols.setUpper(getInputFormat().numAttributes() - 1);
   int selectedCount = 0;
   for (int i = getInputFormat().numAttributes() - 1; i >= 0; i--) {
     if (m_DeltaCols.isInRange(i)) {
       selectedCount++;
       if (!getInputFormat().attribute(i).isNumeric()) {
         throw new UnsupportedAttributeTypeException("Selected attributes must be all numeric");
       }
     }
   }
   if (selectedCount == 1) {
     throw new Exception("Cannot select only one attribute.");
   }

   // Create the output buffer
   FastVector newAtts = new FastVector();
   boolean inRange = false;
   String foName = null;
   int clsIndex = -1;
   for(int i = 0; i < instanceInfo.numAttributes(); i++) {
     if (m_DeltaCols.isInRange(i) && (i != instanceInfo.classIndex())) {
if (inRange) {
  Attribute newAttrib = new Attribute(foName);
         newAtts.addElement(newAttrib);
}
       foName = instanceInfo.attribute(i).name();
       foName = "'FO " + foName.replace('\'', ' ').trim() + '\'';
       inRange = true;
     } else {
newAtts.addElement((Attribute)instanceInfo.attribute(i).copy());
if ((i == instanceInfo.classIndex()))
  clsIndex = newAtts.size() - 1;
     }      
   }
   Instances data = new Instances(instanceInfo.relationName(), newAtts, 0);
   data.setClassIndex(clsIndex);
   setOutputFormat(data);
   return true;
 }
项目:autoweka    文件:RemoveWithValues.java   
/**
  * 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).
  * @throws UnsupportedAttributeTypeException if the specified attribute
  * is neither numeric or nominal.
  * @return true because outputFormat can be collected immediately
  */
 public boolean setInputFormat(Instances instanceInfo) throws Exception {

   super.setInputFormat(instanceInfo);

   m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
   if (!isNumeric() && !isNominal()) {
     throw new UnsupportedAttributeTypeException("Can only handle numeric " +
                      "or nominal attributes.");
   }
   m_Values.setUpper(instanceInfo.attribute(m_AttIndex.getIndex()).numValues() - 1);
   if (isNominal() && m_ModifyHeader) {
     instanceInfo = new Instances(instanceInfo, 0); // copy before modifying
     Attribute oldAtt = instanceInfo.attribute(m_AttIndex.getIndex());
     int [] selection = m_Values.getSelection();
     FastVector newVals = new FastVector();
     for (int i = 0; i < selection.length; i++) {
newVals.addElement(oldAtt.value(selection[i]));
     }
     instanceInfo.deleteAttributeAt(m_AttIndex.getIndex());
     Attribute newAtt = new Attribute(oldAtt.name(), newVals);
     newAtt.setWeight(oldAtt.weight());
     instanceInfo.insertAttributeAt(newAtt,
                  m_AttIndex.getIndex());
     m_NominalMapping = new int [oldAtt.numValues()];
     for (int i = 0; i < m_NominalMapping.length; i++) {
boolean found = false;
for (int j = 0; j < selection.length; j++) {
  if (selection[j] == i) {
    m_NominalMapping[i] = j;
    found = true;
    break;
  }
}
if (!found) {
  m_NominalMapping[i] = -1;
}
     }
   }
   setOutputFormat(instanceInfo);
   return true;
 }
项目:umple    文件:FirstOrder.java   
/**
 * 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 UnsupportedAttributeTypeException if any of the selected attributes
 *           are not numeric
 * @throws Exception if only one attribute has been selected.
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);

  m_DeltaCols.setUpper(getInputFormat().numAttributes() - 1);
  int selectedCount = 0;
  for (int i = getInputFormat().numAttributes() - 1; i >= 0; i--) {
    if (m_DeltaCols.isInRange(i)) {
      selectedCount++;
      if (!getInputFormat().attribute(i).isNumeric()) {
        throw new UnsupportedAttributeTypeException(
          "Selected attributes must be all numeric");
      }
    }
  }
  if (selectedCount == 1) {
    throw new Exception("Cannot select only one attribute.");
  }

  // Create the output buffer
  ArrayList<Attribute> newAtts = new ArrayList<Attribute>();
  boolean inRange = false;
  String foName = null;
  int clsIndex = -1;
  for (int i = 0; i < instanceInfo.numAttributes(); i++) {
    if (m_DeltaCols.isInRange(i) && (i != instanceInfo.classIndex())) {
      if (inRange) {
        Attribute newAttrib = new Attribute(foName);
        newAtts.add(newAttrib);
      }
      foName = instanceInfo.attribute(i).name();
      foName = "'FO " + foName.replace('\'', ' ').trim() + '\'';
      inRange = true;
    } else {
      newAtts.add((Attribute) instanceInfo.attribute(i).copy());
      if ((i == instanceInfo.classIndex())) {
        clsIndex = newAtts.size() - 1;
      }
    }
  }
  Instances data = new Instances(instanceInfo.relationName(), newAtts, 0);
  data.setClassIndex(clsIndex);
  setOutputFormat(data);
  return true;
}
项目:umple    文件:RemoveWithValues.java   
/**
 * 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).
 * @throws UnsupportedAttributeTypeException if the specified attribute is
 *           neither numeric or nominal.
 * @return true because outputFormat can be collected immediately
 */
@Override
public boolean setInputFormat(Instances instanceInfo) throws Exception {

  super.setInputFormat(instanceInfo);

  m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
  if (!isNumeric() && !isNominal()) {
    throw new UnsupportedAttributeTypeException("Can only handle numeric "
      + "or nominal attributes.");
  }
  m_Values
    .setUpper(instanceInfo.attribute(m_AttIndex.getIndex()).numValues() - 1);
  if (isNominal() && m_ModifyHeader) {
    instanceInfo = new Instances(instanceInfo, 0); // copy before modifying
    Attribute oldAtt = instanceInfo.attribute(m_AttIndex.getIndex());
    int[] selection = m_Values.getSelection();
    ArrayList<String> newVals = new ArrayList<String>();
    for (int element : selection) {
      newVals.add(oldAtt.value(element));
    }
    Attribute newAtt = new Attribute(oldAtt.name(), newVals);
    newAtt.setWeight(oldAtt.weight());
    instanceInfo.replaceAttributeAt(newAtt, m_AttIndex.getIndex());
    m_NominalMapping = new int[oldAtt.numValues()];
    for (int i = 0; i < m_NominalMapping.length; i++) {
      boolean found = false;
      for (int j = 0; j < selection.length; j++) {
        if (selection[j] == i) {
          m_NominalMapping[i] = j;
          found = true;
          break;
        }
      }
      if (!found) {
        m_NominalMapping[i] = -1;
      }
    }
  }
  setOutputFormat(instanceInfo);
  return true;
}
项目:jbossBA    文件:FirstOrder.java   
/**
  * 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 UnsupportedAttributeTypeException if any of the
  * selected attributes are not numeric 
  * @throws Exception if only one attribute has been selected.
  */
 public boolean setInputFormat(Instances instanceInfo) throws Exception {

   super.setInputFormat(instanceInfo);

   m_DeltaCols.setUpper(getInputFormat().numAttributes() - 1);
   int selectedCount = 0;
   for (int i = getInputFormat().numAttributes() - 1; i >= 0; i--) {
     if (m_DeltaCols.isInRange(i)) {
       selectedCount++;
       if (!getInputFormat().attribute(i).isNumeric()) {
         throw new UnsupportedAttributeTypeException("Selected attributes must be all numeric");
       }
     }
   }
   if (selectedCount == 1) {
     throw new Exception("Cannot select only one attribute.");
   }

   // Create the output buffer
   FastVector newAtts = new FastVector();
   boolean inRange = false;
   String foName = null;
   int clsIndex = -1;
   for(int i = 0; i < instanceInfo.numAttributes(); i++) {
     if (m_DeltaCols.isInRange(i) && (i != instanceInfo.classIndex())) {
if (inRange) {
  Attribute newAttrib = new Attribute(foName);
         newAtts.addElement(newAttrib);
}
       foName = instanceInfo.attribute(i).name();
       foName = "'FO " + foName.replace('\'', ' ').trim() + '\'';
       inRange = true;
     } else {
newAtts.addElement((Attribute)instanceInfo.attribute(i).copy());
if ((i == instanceInfo.classIndex()))
  clsIndex = newAtts.size() - 1;
     }      
   }
   Instances data = new Instances(instanceInfo.relationName(), newAtts, 0);
   data.setClassIndex(clsIndex);
   setOutputFormat(data);
   return true;
 }
项目:jbossBA    文件:AddValues.java   
/**
  * 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 {
   Attribute    att;
   Attribute    attNew;
   Vector   allLabels;
   Enumeration enm;
   int  i;
   FastVector   values;
   FastVector   atts;
   Instances    instNew;

   super.setInputFormat(instanceInfo);

   m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
   att = instanceInfo.attribute(m_AttIndex.getIndex());
   if (!att.isNominal())
     throw new UnsupportedAttributeTypeException("Chosen attribute not nominal.");

   // merge labels
   allLabels = new Vector();
   enm = att.enumerateValues();
   while (enm.hasMoreElements())
     allLabels.add(enm.nextElement());
   for (i = 0; i < m_Labels.size(); i++) {
     if (!allLabels.contains(m_Labels.get(i)))
allLabels.add(m_Labels.get(i));
   }

   // generate index array
   if (getSort())
     Collections.sort(allLabels);
   m_SortedIndices = new int[att.numValues()];
   enm             = att.enumerateValues();
   i               = 0;
   while (enm.hasMoreElements()) {
     m_SortedIndices[i] = allLabels.indexOf(enm.nextElement());
     i++;
   }

   // generate new header
   values = new FastVector();
   for (i = 0; i < allLabels.size(); i++)
     values.addElement(allLabels.get(i));
   attNew = new Attribute(att.name(), values);

   atts = new FastVector();
   for (i = 0; i < instanceInfo.numAttributes(); i++) {
     if (i == m_AttIndex.getIndex())
atts.addElement(attNew);
     else
atts.addElement(instanceInfo.attribute(i));
   }

   instNew = new Instances(instanceInfo.relationName(), atts, 0);
   instNew.setClassIndex(instanceInfo.classIndex());

   // set new format
   setOutputFormat(instNew);

   return true;
 }
项目:jbossBA    文件:RemoveWithValues.java   
/**
  * 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).
  * @throws UnsupportedAttributeTypeException if the specified attribute
  * is neither numeric or nominal.
  * @return true because outputFormat can be collected immediately
  */
 public boolean setInputFormat(Instances instanceInfo) throws Exception {

   super.setInputFormat(instanceInfo);

   m_AttIndex.setUpper(instanceInfo.numAttributes() - 1);
   if (!isNumeric() && !isNominal()) {
     throw new UnsupportedAttributeTypeException("Can only handle numeric " +
                      "or nominal attributes.");
   }
   m_Values.setUpper(instanceInfo.attribute(m_AttIndex.getIndex()).numValues() - 1);
   if (isNominal() && m_ModifyHeader) {
     instanceInfo = new Instances(instanceInfo, 0); // copy before modifying
     Attribute oldAtt = instanceInfo.attribute(m_AttIndex.getIndex());
     int [] selection = m_Values.getSelection();
     FastVector newVals = new FastVector();
     for (int i = 0; i < selection.length; i++) {
newVals.addElement(oldAtt.value(selection[i]));
     }
     instanceInfo.deleteAttributeAt(m_AttIndex.getIndex());
     Attribute newAtt = new Attribute(oldAtt.name(), newVals);
     newAtt.setWeight(oldAtt.weight());
     instanceInfo.insertAttributeAt(newAtt,
                                     m_AttIndex.getIndex());
     m_NominalMapping = new int [oldAtt.numValues()];
     for (int i = 0; i < m_NominalMapping.length; i++) {
boolean found = false;
for (int j = 0; j < selection.length; j++) {
  if (selection[j] == i) {
    m_NominalMapping[i] = j;
    found = true;
    break;
  }
}
if (!found) {
  m_NominalMapping[i] = -1;
}
     }
   }
   setOutputFormat(instanceInfo);
   return true;
 }