當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。