weka.core.Instances.equalHeadersMsg()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中weka.core.Instances.equalHeadersMsg()方法的一些代码示例,展示了Instances.equalHeadersMsg()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Instances.equalHeadersMsg()方法的具体详情如下:
包路径:weka.core.Instances
类名称:Instances
方法名:equalHeadersMsg

Instances.equalHeadersMsg介绍

[英]Checks if two headers are equivalent. If not, then returns a message why they differ.
[中]检查两个标头是否相等。如果没有,则返回一条消息,说明它们存在差异的原因。

代码示例

代码示例来源:origin: Waikato/weka-trunk

/**
 * Checks if two headers are equivalent.
 * 
 * @param dataset another dataset
 * @return true if the header of the given dataset is equivalent to this
 *         header
 */
public/* @pure@ */boolean equalHeaders(Instances dataset) {
 return (equalHeadersMsg(dataset) == null);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Checks if two headers are equivalent.
 * 
 * @param dataset another dataset
 * @return true if the header of the given dataset is equivalent to this
 *         header
 */
public/* @pure@ */boolean equalHeaders(Instances dataset) {
 return (equalHeadersMsg(dataset) == null);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Sets a value of a relation-valued attribute. Creates a fresh list of
 * attribute values before it is set.
 * 
 * @param index the value's index
 * @param data the value
 * @throws IllegalArgumentException if the attribute is not relation-valued.
 */
final void setValue(int index, Instances data) {
 if (isRelationValued()) {
  if (!data.equalHeaders(((RelationalAttributeInfo)m_AttributeInfo).m_Header)) {
   throw new IllegalArgumentException("Can't set relational value. "
    + "Headers not compatible.\n" + data.equalHeadersMsg(((RelationalAttributeInfo)m_AttributeInfo).m_Header));
  }
  ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
   Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
  ((NominalAttributeInfo)m_AttributeInfo).m_Values.set(index, data);
 } else {
  throw new IllegalArgumentException("Can only set value for"
   + " relation-valued attributes!");
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Sets a value of a relation-valued attribute. Creates a fresh list of
 * attribute values before it is set.
 * 
 * @param index the value's index
 * @param data the value
 * @throws IllegalArgumentException if the attribute is not relation-valued.
 */
final void setValue(int index, Instances data) {
 if (isRelationValued()) {
  if (!data.equalHeaders(((RelationalAttributeInfo)m_AttributeInfo).m_Header)) {
   throw new IllegalArgumentException("Can't set relational value. "
    + "Headers not compatible.\n" + data.equalHeadersMsg(((RelationalAttributeInfo)m_AttributeInfo).m_Header));
  }
  ((NominalAttributeInfo)m_AttributeInfo).m_Values = 
   Utils.cast(((NominalAttributeInfo)m_AttributeInfo).m_Values.clone());
  ((NominalAttributeInfo)m_AttributeInfo).m_Values.set(index, data);
 } else {
  throw new IllegalArgumentException("Can only set value for"
   + " relation-valued attributes!");
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Checks if the headers of two instances are equivalent. If not, then returns
 * a message why they differ.
 * 
 * @param dataset another instance
 * @return null if the header of the given instance is equivalent to this
 *         instance's header, otherwise a message with details on why they
 *         differ
 */
@Override
public String equalHeadersMsg(Instance inst) {
 if (m_Dataset == null) {
  throw new UnassignedDatasetException(
   "Instance doesn't have access to a dataset!");
 }
 return m_Dataset.equalHeadersMsg(inst.dataset());
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Checks if the headers of two instances are equivalent. If not, then returns
 * a message why they differ.
 * 
 * @param dataset another instance
 * @return null if the header of the given instance is equivalent to this
 *         instance's header, otherwise a message with details on why they
 *         differ
 */
@Override
public String equalHeadersMsg(Instance inst) {
 if (m_Dataset == null) {
  throw new UnassignedDatasetException(
   "Instance doesn't have access to a dataset!");
 }
 return m_Dataset.equalHeadersMsg(inst.dataset());
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

+ m_data.equalHeadersMsg(toAggregate.m_data));

代码示例来源:origin: nz.ac.waikato.cms.weka/NNge

/**
 * Updates the classifier using the given instance.
 *
 * @param instance the instance to include
 * @throws Exception if instance could not be incorporated
 * successfully
 */
public void updateClassifier(Instance instance) throws Exception {
 if (m_Train.equalHeaders(instance.dataset()) == false) {
  throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
 }    
 update(instance);    
}

代码示例来源:origin: com.github.fracpete/multisearch-weka-package

/**
 * Loads test data, if required.
 *
 * @param data
 *            the current training data
 * @throws Exception
 *             if test sets are not compatible with training data
 */
protected void loadTestData(Instances data) throws Exception {
 String msg;
 m_SearchSpaceTestInst = null;
 if (m_SearchSpaceTestSet.exists()
  && !m_SearchSpaceTestSet.isDirectory()) {
  m_SearchSpaceTestInst = DataSource.read(m_SearchSpaceTestSet
 .getAbsolutePath());
  m_SearchSpaceTestInst.setClassIndex(data.classIndex());
  msg = data.equalHeadersMsg(m_SearchSpaceTestInst);
  if (msg != null) {
 throw new IllegalArgumentException(
  "Test set for search space not compatible with training dta:\n"
   + msg);
  }
  m_SearchSpaceTestInst.deleteWithMissingClass();
  log("Using test set for search space: " + m_SearchSpaceTestSet);
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/NNge

/**
 * Classifies a given instance.
 *
 * @param instance the instance to be classified
 * @return index of the predicted class as a double
 * @throws Exception if instance could not be classified
 * successfully
 */
public double classifyInstance(Instance instance) throws Exception {
 /* check the instance */
 if (m_Train.equalHeaders(instance.dataset()) == false){
  throw new Exception("NNge.classifyInstance : Incompatible instance types !\n" + m_Train.equalHeadersMsg(instance.dataset()));
 }
 
 Exemplar matched = nearestExemplar(instance); 
 if(matched == null){
  throw new Exception("NNge.classifyInstance : NNge hasn't been trained !");
 }
 return matched.classValue();
}

代码示例来源:origin: Waikato/weka-trunk

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public NaiveBayes aggregate(NaiveBayes toAggregate) throws Exception {
 // Highly unlikely that discretization intervals will match between the
 // two classifiers
 if (m_UseDiscretization || toAggregate.getUseSupervisedDiscretization()) {
  throw new Exception("Unable to aggregate when supervised discretization "
   + "has been turned on");
 }
 if (!m_Instances.equalHeaders(toAggregate.m_Instances)) {
  throw new Exception("Can't aggregate - data headers don't match: "
   + m_Instances.equalHeadersMsg(toAggregate.m_Instances));
 }
 ((Aggregateable) m_ClassDistribution)
  .aggregate(toAggregate.m_ClassDistribution);
 // aggregate all conditional estimators
 for (int i = 0; i < m_Distributions.length; i++) {
  for (int j = 0; j < m_Distributions[i].length; j++) {
   ((Aggregateable) m_Distributions[i][j])
    .aggregate(toAggregate.m_Distributions[i][j]);
  }
 }
 return this;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public NaiveBayes aggregate(NaiveBayes toAggregate) throws Exception {
 // Highly unlikely that discretization intervals will match between the
 // two classifiers
 if (m_UseDiscretization || toAggregate.getUseSupervisedDiscretization()) {
  throw new Exception("Unable to aggregate when supervised discretization "
   + "has been turned on");
 }
 if (!m_Instances.equalHeaders(toAggregate.m_Instances)) {
  throw new Exception("Can't aggregate - data headers don't match: "
   + m_Instances.equalHeadersMsg(toAggregate.m_Instances));
 }
 ((Aggregateable) m_ClassDistribution)
  .aggregate(toAggregate.m_ClassDistribution);
 // aggregate all conditional estimators
 for (int i = 0; i < m_Distributions.length; i++) {
  for (int j = 0; j < m_Distributions[i].length; j++) {
   ((Aggregateable) m_Distributions[i][j])
    .aggregate(toAggregate.m_Distributions[i][j]);
  }
 }
 return this;
}

代码示例来源:origin: nz.ac.waikato.cms.weka/distributedWekaBase

/**
 * Aggregate the supplied reservoir into our reservoir. Does not increase the
 * size of the sample.
 * 
 * @param toAggregate the reservoir sample to aggregate
 * @throws Exception if the structure of the instances in the sample to
 *           aggregate does not match the structure of our sketch
 */
public void aggregateReservoir(WeightedReservoirSample toAggregate)
 throws Exception {
 if (toAggregate.getSample().size() > 0) {
  Instance structureCheck = toAggregate.getSample().peek().m_instance;
  if (!m_currentSketch.equalHeaders(structureCheck.dataset())) {
   throw new Exception(
    "Can't aggregate - instances structure is different: "
     + m_currentSketch.equalHeadersMsg(structureCheck.dataset()));
  }
 }
 m_weightedCenterSample.aggregate(toAggregate);
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Adds the supplied instance to the training set.
 *
 * @param instance the instance to add
 * @throws Exception if instance could not be incorporated
 * successfully
 */
public void updateClassifier(Instance instance) throws Exception {
 if (m_Train == null) {
  throw new Exception("No training instance structure set!");
 }
 else if (m_Train.equalHeaders(instance.dataset()) == false) {
  throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
 }
 if (!instance.classIsMissing()) {
  m_NNSearch.update(instance);
  m_Train.add(instance);
 }
}

代码示例来源:origin: Waikato/meka

public static void main(String[] args) throws Exception {
  if (args.length != 2)
   throw new IllegalArgumentException("Required arguments: <train> <predict>");

  System.out.println("Loading train: " + args[0]);
  Instances train = DataSource.read(args[0]);
  MLUtils.prepareData(train);

  System.out.println("Loading predict: " + args[1]);
  Instances predict = DataSource.read(args[1]);
  MLUtils.prepareData(predict);

  // compatible?
  String msg = train.equalHeadersMsg(predict);
  if (msg != null)
   throw new IllegalStateException(msg);

  System.out.println("Build BR classifier on " + args[0]);
  BR classifier = new BR();
  // further configuration of classifier
  classifier.buildClassifier(train);

  System.out.println("Use BR classifier on " + args[1]);
  for (int i = 0; i < predict.numInstances(); i++) {
   double[] dist = classifier.distributionForInstance(predict.instance(i));
   System.out.println((i+1) + ": " + Utils.arrayToString(dist));
  }
 }
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Adds the supplied instance to the training set.
 *
 * @param instance the instance to add
 * @throws Exception if instance could not be incorporated
 * successfully
 */
public void updateClassifier(Instance instance) throws Exception {
 if (m_Train == null) {
  throw new Exception("No training instance structure set!");
 }
 else if (m_Train.equalHeaders(instance.dataset()) == false) {
  throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
 }
 if (!instance.classIsMissing()) {
  m_NNSearch.update(instance);
  m_Train.add(instance);
 }
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Adds the supplied instance to the training set
 *
 * @param instance the instance to add
 * @throws Exception if instance could not be incorporated successfully
 */
public void updateClassifier(Instance instance) throws Exception {
 
 if (m_Train.equalHeaders(instance.dataset()) == false)
  throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
 if ( instance.classIsMissing() )
  return;
 m_Train.add(instance);
 // update relevant attributes ...
 update_m_Attributes();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/simpleEducationalLearningSchemes

/**
 * Updates the classifier.
 *
 * @param instance the instance to be put into the classifier
 * @throws Exception if the instance could not be included successfully
 */
public void updateClassifier(Instance instance) throws Exception {

 if (m_Train.equalHeaders(instance.dataset()) == false) {
  throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
 }
 if (instance.classIsMissing()) {
  return;
 }
 m_Train.add(instance);
 updateMinMax(instance);
}

代码示例来源:origin: Waikato/weka-trunk

/**
 * Adds the supplied instance to the training set
 *
 * @param instance the instance to add
 * @throws Exception if instance could not be incorporated successfully
 */
public void updateClassifier(Instance instance) throws Exception {
 
 if (m_Train.equalHeaders(instance.dataset()) == false)
  throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
 if ( instance.classIsMissing() )
  return;
 m_Train.add(instance);
 // update relevant attributes ...
 update_m_Attributes();
}

代码示例来源:origin: nz.ac.waikato.cms.weka/weka-stable

/**
 * Adds the supplied instance to the training set.
 *
 * @param instance the instance to add
 * @throws Exception if instance could not be incorporated
 * successfully
 */
public void updateClassifier(Instance instance) throws Exception {
 if (m_Train.equalHeaders(instance.dataset()) == false) {
  throw new Exception("Incompatible instance types\n" + m_Train.equalHeadersMsg(instance.dataset()));
 }
 if (instance.classIsMissing()) {
  return;
 }
 m_Train.add(instance);
 m_NNSearch.update(instance);
 m_kNNValid = false;
 if ((m_WindowSize > 0) && (m_Train.numInstances() > m_WindowSize)) {
  boolean deletedInstance=false;
  while (m_Train.numInstances() > m_WindowSize) {
 m_Train.delete(0);
   deletedInstance=true;
  }
  //rebuild datastructure KDTree currently can't delete
  if(deletedInstance==true)
   m_NNSearch.setInstances(m_Train);
 }
}

相关文章

Instances类方法