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


Java DenseInstance.setDataset方法代码示例

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


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

示例1: toWekaInstance

import weka.core.DenseInstance; //导入方法依赖的package包/类
/**
 * toWekaInstance
 * 
 * @param dataset
 * @return 
 */
public Instance toWekaInstance(Instances dataset) {
    // create instance
    DenseInstance instance = new DenseInstance(13);
    instance.setDataset(dataset);

    // set values
    instance.setValue(0, this.getMean());
    instance.setValue(1, this.getMedian());
    instance.setValue(2, this.getMin());
    instance.setValue(3, this.getMax());
    instance.setValue(4, this.getStd());
    instance.setValue(5, this.getLowQuantile());
    instance.setValue(6, this.getHighQuantile());
    instance.setValue(7, this.getIqr());
    instance.setValue(8, this.getKurtosis());
    instance.setValue(9, this.getRange());
    instance.setValue(10, this.getPower());
    instance.setValue(11, this.getTotalF0());
    instance.setValue(12, stressed ? "stressed" : "unstressed");

    // return instance
    return instance;
}
 
开发者ID:andrzejtrzaska,项目名称:VoiceStressAnalysis,代码行数:30,代码来源:VoiceStressInstance.java

示例2: fillData

import weka.core.DenseInstance; //导入方法依赖的package包/类
private void fillData(double[] featureValues, String className, Instances data) {

		double[] vals = new double[data.numAttributes()];

		if (vals.length != (featureValues.length + 1)) {
			if (FrameworkContext.WARN) Log.w(TAG, "Number of feature values and weka instance values differs.");
		}

		for (int i = 0; i < featureValues.length; i++) {
			vals[i] = featureValues[i];
		}

		vals[vals.length - 1] = attClassVals.indexOf(className);

		DenseInstance instance = new DenseInstance(1.0, vals);
		
		if (isLogDirectlyToFile) {
			instance.setDataset(data);
			logArffData(instance.toString());
		} else {
			// add
			data.add(instance);
		}
	}
 
开发者ID:teco-kit,项目名称:Android-Context-Framework,代码行数:25,代码来源:WekaManager.java

示例3: makeInstance

import weka.core.DenseInstance; //导入方法依赖的package包/类
/**
 * Method that converts a text message into an instance.
 */
private static Instance makeInstance(String text, Instances data) {

  // Create instance of length two.
  DenseInstance instance = new DenseInstance(2);

  // Set value for message attribute
  Attribute messageAtt = data.attribute("text");
  instance.setValue(messageAtt, messageAtt.addStringValue(text));

  // Give instance access to attribute information from the dataset.
  instance.setDataset(data);
  return instance;
}
 
开发者ID:SOBotics,项目名称:SOCVFinder,代码行数:17,代码来源:TestWekaClassifier.java

示例4: distributionForInstance

import weka.core.DenseInstance; //导入方法依赖的package包/类
@Override
public double[] distributionForInstance(Instance inst) throws Exception {
  double[] result = new double[2];

  tokenizeInstance(inst, false);
  double wx = dotProd(m_inputVector);
  double z = (wx + m_bias);

  if (m_loss == HINGE && m_fitLogistic) {
    double pred = z;
    double[] vals = new double[2];
    vals[0] = pred;
    vals[1] = Utils.missingValue();
    DenseInstance metaI = new DenseInstance(inst.weight(), vals);
    metaI.setDataset(m_fitLogisticStructure);
    return m_svmProbs.distributionForInstance(metaI);
  }

  if (z <= 0) {
    if (m_loss == LOGLOSS) {
      result[0] = 1.0 / (1.0 + Math.exp(z));
      result[1] = 1.0 - result[0];
    } else {
      result[0] = 1;
    }
  } else {
    if (m_loss == LOGLOSS) {
      result[1] = 1.0 / (1.0 + Math.exp(-z));
      result[0] = 1.0 - result[1];
    } else {
      result[1] = 1;
    }
  }

  return result;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:37,代码来源:SGDText.java

示例5: process

import weka.core.DenseInstance; //导入方法依赖的package包/类
/**
 * Processes the given data.
 * 
 * @param instances the data to process
 * @return the modified data
 * @throws Exception in case the processing goes wrong
 */
@Override
protected Instances process(Instances instances) throws Exception {

  // Generate the output and return it
  Instances result = new Instances(getOutputFormat(),
    instances.numInstances());
  for (int i = 0; i < instances.numInstances(); i++) {
    Instance inst = instances.instance(i);
    double[] newData = new double[instances.numAttributes()];
    for (int j = 0; j < instances.numAttributes(); j++) {
      if (m_AttToBeModified[j] && !inst.isMissing(j)) {
        newData[j] = m_Indicators[j][(int) inst.value(j)];
      } else {
        newData[j] = inst.value(j);
      }
    }
    DenseInstance instNew = new DenseInstance(1.0, newData);
    instNew.setDataset(result);

    // copy possible strings, relational values...
    copyValues(instNew, false, inst.dataset(), getOutputFormat());

    // Add instance to output
    result.add(instNew);
  }
  return result;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:35,代码来源:MergeNominalValues.java

示例6: process

import weka.core.DenseInstance; //导入方法依赖的package包/类
/**
 * Processes the given data.
 * 
 * @param instances the data to process
 * @return the modified data
 * @throws Exception in case the processing goes wrong
 */
@Override
protected Instances process(Instances instances) throws Exception {

  // Generate the output and return it
  Instances result = new Instances(getOutputFormat(),
    instances.numInstances());
  for (int i = 0; i < instances.numInstances(); i++) {
    Instance inst = instances.instance(i);
    double[] newData = new double[instances.numAttributes()];
    for (int j = 0; j < instances.numAttributes(); j++) {
      if (m_AttToBeModified[j] && !inst.isMissing(j)) {
        newData[j] = m_NewValues[j][(int) inst.value(j)];
      } else {
        newData[j] = inst.value(j);
      }
    }
    DenseInstance instNew = new DenseInstance(1.0, newData);
    instNew.setDataset(result);

    // copy possible strings, relational values...
    copyValues(instNew, false, inst.dataset(), getOutputFormat());

    // Add instance to output
    result.add(instNew);
  }
  return result;
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:35,代码来源:MergeInfrequentNominalValues.java

示例7: distributionForInstance

import weka.core.DenseInstance; //导入方法依赖的package包/类
public double[] distributionForInstance(Instance inst) throws Exception {
  double[] result = new double[2];
  
  tokenizeInstance(inst, false);
  double wx = dotProd(m_inputVector);
  double z = (wx + m_bias);
  
  if (m_loss == HINGE && m_fitLogistic) {
    double pred = z;
    double[] vals = new double[2];
    vals[0] = pred;
    vals[1] = Utils.missingValue();
    DenseInstance metaI = new DenseInstance(inst.weight(), vals);
    metaI.setDataset(m_fitLogisticStructure);
    return m_svmProbs.distributionForInstance(metaI);
  }
  
  if (z <= 0) {
    if (m_loss == LOGLOSS) {
      result[0] = 1.0 / (1.0 + Math.exp(z));
      result[1] = 1.0 - result[0];
    } else {
      result[0] = 1;
    }
  } else {
    if (m_loss == LOGLOSS) {
      result[1] = 1.0 / (1.0 + Math.exp(-z));
      result[0] = 1.0 - result[1];
    } else {
      result[1] = 1;
    }
  }
  
  return result;
}
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:36,代码来源:SGDText.java

示例8: execute

import weka.core.DenseInstance; //导入方法依赖的package包/类
/**
 * Perform the sub task
 */
@Override
public void execute() {

  m_random = new Random(m_rowNumber * 11);
  m_dataGenerator.setSeed(m_rowNumber * 11);
  m_result = new RemoteResult(m_rowNumber, m_panelWidth);
  m_status.setTaskResult(m_result);
  m_status.setExecutionStatus(TaskStatusInfo.PROCESSING);

  try {
    m_numOfSamplesPerGenerator = (int) Math.pow(m_samplesBase,
      m_trainingData.numAttributes() - 3);
    if (m_trainingData == null) {
      throw new Exception("No training data set (BoundaryPanel)");
    }
    if (m_classifier == null) {
      throw new Exception("No classifier set (BoundaryPanel)");
    }
    if (m_dataGenerator == null) {
      throw new Exception("No data generator set (BoundaryPanel)");
    }
    if (m_trainingData.attribute(m_xAttribute).isNominal()
      || m_trainingData.attribute(m_yAttribute).isNominal()) {
      throw new Exception("Visualization dimensions must be numeric "
        + "(RemoteBoundaryVisualizerSubTask)");
    }

    m_attsToWeightOn = new boolean[m_trainingData.numAttributes()];
    m_attsToWeightOn[m_xAttribute] = true;
    m_attsToWeightOn[m_yAttribute] = true;

    // generate samples
    m_weightingAttsValues = new double[m_attsToWeightOn.length];
    m_vals = new double[m_trainingData.numAttributes()];
    m_predInst = new DenseInstance(1.0, m_vals);
    m_predInst.setDataset(m_trainingData);

    System.err.println("Executing row number " + m_rowNumber);
    for (int j = 0; j < m_panelWidth; j++) {
      double[] preds = calculateRegionProbs(j, m_rowNumber);
      m_result.setLocationProbs(j, preds);
      m_result
        .setPercentCompleted((int) (100 * ((double) j / (double) m_panelWidth)));
    }
  } catch (Exception ex) {
    m_status.setExecutionStatus(TaskStatusInfo.FAILED);
    m_status.setStatusMessage("Row " + m_rowNumber + " failed.");
    System.err.print(ex);
    return;
  }

  // finished
  m_status.setExecutionStatus(TaskStatusInfo.FINISHED);
  m_status
    .setStatusMessage("Row " + m_rowNumber + " completed successfully.");
}
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:60,代码来源:RemoteBoundaryVisualizerSubTask.java

示例9: makeInstance

import weka.core.DenseInstance; //导入方法依赖的package包/类
protected Instance makeInstance() throws IOException {

    if (m_current == null) {
      return null;
    }

    double[] vals = new double[m_structure.numAttributes()];
    for (int i = 0; i < m_structure.numAttributes(); i++) {
      Object val = m_current.get(i);
      if (val.toString().equals("?")) {
        vals[i] = Utils.missingValue();
      } else if (m_structure.attribute(i).isString()) {
        vals[i] = 0;
        m_structure.attribute(i).setStringValue(Utils.unquote(val.toString()));
      } else if (m_structure.attribute(i).isDate()) {
        String format = m_structure.attribute(i).getDateFormat();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        String dateVal = Utils.unquote(val.toString());
        try {
          vals[i] = sdf.parse(dateVal).getTime();
        } catch (ParseException e) {
          throw new IOException("Unable to parse date value " + dateVal
            + " using date format " + format + " for date attribute "
            + m_structure.attribute(i) + " (line: " + m_rowCount + ")");
        }
      } else if (m_structure.attribute(i).isNumeric()) {
        try {
          Double v = Double.parseDouble(val.toString());
          vals[i] = v.doubleValue();
        } catch (NumberFormatException ex) {
          throw new IOException("Was expecting a number for attribute "
            + m_structure.attribute(i).name() + " but read " + val.toString()
            + " instead. (line: " + m_rowCount + ")");
        }
      } else {
        // nominal
        double index =
          m_structure.attribute(i).indexOfValue(Utils.unquote(val.toString()));
        if (index < 0) {
          throw new IOException("Read unknown nominal value " + val.toString()
            + "for attribute " + m_structure.attribute(i).name() + " (line: "
            + m_rowCount + "). Try increasing the size of the memory buffer"
            + " (-B option) or explicitly specify legal nominal values with "
            + "the -L option.");
        }
        vals[i] = index;
      }
    }

    DenseInstance inst = new DenseInstance(1.0, vals);
    inst.setDataset(m_structure);

    return inst;
  }
 
开发者ID:mydzigear,项目名称:repo.kmeanspp.silhouette_score,代码行数:55,代码来源:CSVLoader.java

示例10: execute

import weka.core.DenseInstance; //导入方法依赖的package包/类
/**
  * Perform the sub task
  */
 public void execute() {

   m_random = new Random(m_rowNumber * 11);
   m_dataGenerator.setSeed(m_rowNumber * 11);
   m_result = new RemoteResult(m_rowNumber, m_panelWidth);
   m_status.setTaskResult(m_result);
   m_status.setExecutionStatus(TaskStatusInfo.PROCESSING);

   try {
     m_numOfSamplesPerGenerator = 
(int)Math.pow(m_samplesBase, m_trainingData.numAttributes()-3);
     if (m_trainingData == null) {
throw new Exception("No training data set (BoundaryPanel)");
     }
     if (m_classifier == null) {
throw new Exception("No classifier set (BoundaryPanel)");
     }
     if (m_dataGenerator == null) {
throw new Exception("No data generator set (BoundaryPanel)");
     }
     if (m_trainingData.attribute(m_xAttribute).isNominal() || 
m_trainingData.attribute(m_yAttribute).isNominal()) {
throw new Exception("Visualization dimensions must be numeric "
		    +"(RemoteBoundaryVisualizerSubTask)");
     }
     
     m_attsToWeightOn = new boolean[m_trainingData.numAttributes()];
     m_attsToWeightOn[m_xAttribute] = true;
     m_attsToWeightOn[m_yAttribute] = true;
     
     // generate samples
     m_weightingAttsValues = new double [m_attsToWeightOn.length];
     m_vals = new double[m_trainingData.numAttributes()];
     m_predInst = new DenseInstance(1.0, m_vals);
     m_predInst.setDataset(m_trainingData);

     System.err.println("Executing row number "+m_rowNumber);
     for (int j = 0; j < m_panelWidth; j++) {
double [] preds = calculateRegionProbs(j, m_rowNumber);
m_result.setLocationProbs(j, preds);
m_result.
  setPercentCompleted((int)(100 * ((double)j / (double)m_panelWidth)));
     }
   } catch (Exception ex) {
     m_status.setExecutionStatus(TaskStatusInfo.FAILED);
     m_status.setStatusMessage("Row "+m_rowNumber+" failed.");
     System.err.print(ex);
     return;
   }

   // finished
   m_status.setExecutionStatus(TaskStatusInfo.FINISHED);
   m_status.setStatusMessage("Row "+m_rowNumber+" completed successfully.");
 }
 
开发者ID:dsibournemouth,项目名称:autoweka,代码行数:58,代码来源:RemoteBoundaryVisualizerSubTask.java

示例11: makeInstance

import weka.core.DenseInstance; //导入方法依赖的package包/类
protected Instance makeInstance() throws IOException {

    if (m_current == null) {
      return null;
    }

    double[] vals = new double[m_structure.numAttributes()];
    for (int i = 0; i < m_structure.numAttributes(); i++) {
      Object val = m_current.get(i);
      if (val.toString().equals("?")) {
        vals[i] = Utils.missingValue();
      } else if (m_structure.attribute(i).isString()) {
        vals[i] = 0;
        m_structure.attribute(i).setStringValue(Utils.unquote(val.toString()));
      } else if (m_structure.attribute(i).isDate()) {
        String format = m_structure.attribute(i).getDateFormat();
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        try {
          vals[i] = sdf.parse(val.toString()).getTime();
        } catch (ParseException e) {
          throw new IOException("Unable to parse date value " + val.toString()
            + " using date format " + format + " for date attribute "
            + m_structure.attribute(i) + " (line: " + m_rowCount + ")");
        }
      } else if (m_structure.attribute(i).isNumeric()) {
        try {
          Double v = Double.parseDouble(val.toString());
          vals[i] = v.doubleValue();
        } catch (NumberFormatException ex) {
          throw new IOException("Was expecting a number for attribute "
            + m_structure.attribute(i).name() + " but read " + val.toString()
            + " instead. (line: " + m_rowCount + ")");
        }
      } else {
        // nominal
        double index =
          m_structure.attribute(i).indexOfValue(Utils.unquote(val.toString()));
        if (index < 0) {
          throw new IOException("Read unknown nominal value " + val.toString()
            + "for attribute " + m_structure.attribute(i).name() + " (line: "
            + m_rowCount + ")");
        }
        vals[i] = index;
      }
    }

    DenseInstance inst = new DenseInstance(1.0, vals);
    inst.setDataset(m_structure);

    return inst;
  }
 
开发者ID:umple,项目名称:umple,代码行数:52,代码来源:CSVLoader.java


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