当前位置: 首页>>代码示例>>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;未经允许,请勿转载。