當前位置: 首頁>>代碼示例>>Java>>正文


Java Utils.correlation方法代碼示例

本文整理匯總了Java中weka.core.Utils.correlation方法的典型用法代碼示例。如果您正苦於以下問題:Java Utils.correlation方法的具體用法?Java Utils.correlation怎麽用?Java Utils.correlation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在weka.core.Utils的用法示例。


在下文中一共展示了Utils.correlation方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import weka.core.Utils; //導入方法依賴的package包/類
/**
 * Main method for testing this class
 * 
 * @param args command line arguments
 */
public static void main(String[] args) {
  try {
    Instances orig = new Instances(new java.io.BufferedReader(
      new java.io.FileReader(args[0])));
    orig.setClassIndex(orig.numAttributes() - 1);

    java.util.List<String> attNames = new java.util.ArrayList<String>();
    for (int i = 0; i < orig.numAttributes(); i++) {
      attNames.add(orig.attribute(i).name());
    }

    CSVToARFFHeaderMapTask arffTask = new CSVToARFFHeaderMapTask();
    arffTask.setOptions(args);
    // arffTask.setComputeSummaryStats(true);
    for (int i = 0; i < orig.numInstances(); i++) {
      arffTask.processRow(orig.instance(i).toString(), attNames);
    }
    Instances withSummary = arffTask.getHeader();
    CSVToARFFHeaderReduceTask arffReduce = new CSVToARFFHeaderReduceTask();
    List<Instances> instList = new ArrayList<Instances>();
    instList.add(withSummary);
    withSummary = arffReduce.aggregate(instList);

    System.err.println(withSummary);
    withSummary.setClassIndex(orig.classIndex());

    CorrelationMatrixMapTask corrTask = new CorrelationMatrixMapTask();
    corrTask.setup(withSummary);

    for (int i = 0; i < orig.numInstances(); i++) {
      corrTask.processInstance(orig.instance(i));
    }

    double[][] matrix = corrTask.getMatrix();

    CorrelationMatrixRowReduceTask reduce =
      new CorrelationMatrixRowReduceTask();
    for (int i = 0; i < matrix.length; i++) {
      List<double[]> toAgg = new ArrayList<double[]>();
      toAgg.add(matrix[i]);
      double[] computed = reduce.aggregate(i, toAgg, null, withSummary, true,
        false, true);
      for (int j = 0; j < matrix[i].length; j++) {
        System.err.print(computed[j] + " ");
      }
      System.err.println();
    }
    System.err.println();

    for (int i = 0; i < orig.numAttributes(); i++) {
      double[] row = new double[i + 1];
      for (int j = 0; j <= i; j++) {
        if (i != orig.classIndex() && j != orig.classIndex()) {
          if (i == j) {
            row[j] = 1.0;
          } else {
            double[] ii = new double[orig.numInstances()];
            double[] jj = new double[orig.numInstances()];
            for (int k = 0; k < orig.numInstances(); k++) {
              ii[k] = orig.instance(k).value(i);
              jj[k] = orig.instance(k).value(j);
            }

            row[j] = Utils.correlation(ii, jj, orig.numInstances());
          }
          System.err.print(row[j] + " ");
        }
      }
      System.err.println();
    }
  } catch (Exception ex) {
    ex.printStackTrace();
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:80,代碼來源:CorrelationMatrixMapTask.java

示例2: checkAgainstUtilsCorr

import weka.core.Utils; //導入方法依賴的package包/類
protected void checkAgainstUtilsCorr(double[][] matrix, Instances orig,
  Instances withSummary, boolean deleteClassIfSet) throws Exception {
  CorrelationMatrixRowReduceTask reduce =
    new CorrelationMatrixRowReduceTask();
  double[][] finalM = new double[matrix.length][];
  for (int i = 0; i < matrix.length; i++) {
    List<double[]> toAgg = new ArrayList<double[]>();
    toAgg.add(matrix[i]);
    double[] computed = reduce.aggregate(i, toAgg, null, withSummary, true,
      false, deleteClassIfSet);
    // for (int j = 0; j < matrix[i].length; j++) {
    // System.err.print(computed[j] + " ");
    // }
    finalM[i] = computed;
    // System.err.println();
  }

  double[][] utilsC = new double[matrix.length][];
  for (int i = 0; i < orig.numAttributes(); i++) {
    double[] row = new double[i + 1];
    for (int j = 0; j <= i; j++) {
      if (i != orig.classIndex() && j != orig.classIndex()) {
        if (i == j) {
          row[j] = 1.0;
        } else {
          double[] ii = new double[orig.numInstances()];
          double[] jj = new double[orig.numInstances()];
          for (int k = 0; k < orig.numInstances(); k++) {
            ii[k] = orig.instance(k).value(i);
            jj[k] = orig.instance(k).value(j);
          }

          row[j] = Utils.correlation(ii, jj, orig.numInstances());
        }
        // System.err.print(row[j] + " ");
      }
    }
    if (i != orig.classIndex()) {
      utilsC[i] = row;
    }
    // System.err.println();
  }

  for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < finalM[i].length; j++) {
      double diff = Math.abs(finalM[i][j] - utilsC[i][j]);

      assertTrue(diff < TOL);
    }
  }
}
 
開發者ID:mydzigear,項目名稱:repo.kmeanspp.silhouette_score,代碼行數:52,代碼來源:CorrelationMatrixMapTaskTest.java


注:本文中的weka.core.Utils.correlation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。