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


Java PearsonsCorrelation类代码示例

本文整理汇总了Java中org.apache.commons.math3.stat.correlation.PearsonsCorrelation的典型用法代码示例。如果您正苦于以下问题:Java PearsonsCorrelation类的具体用法?Java PearsonsCorrelation怎么用?Java PearsonsCorrelation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PearsonsCorrelation类属于org.apache.commons.math3.stat.correlation包,在下文中一共展示了PearsonsCorrelation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCorrelation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
/**
 * Creates two random double arrays, calculates covariance and different correlation coefficients from it
 * @throws Exception
 */
@Test
public void testCorrelation() throws Exception {
    double[] x = new double[10];
    double[] y = new double[10];
    for (int i = 0; i < x.length; i++) {
        x[i] = Math.random()*100;
        y[i] = Math.random()*100;
    }
    System.out.println("x: " + Arrays.toString(x));
    System.out.println("y: " + Arrays.toString(y));
    System.out.println("Covariance: " + new Covariance().covariance(x,y));
    System.out.println("Pearson's Correlation: " + new PearsonsCorrelation().correlation(x,y));
    System.out.println("Spearman's Correlation: " + new SpearmansCorrelation().correlation(x,y));
    System.out.println("Kendall's Correlation: " + new KendallsCorrelation().correlation(x,y));
}
 
开发者ID:jmueller95,项目名称:CORNETTO,代码行数:20,代码来源:ApacheMathTest.java

示例2: calculateAndOutputCorrelations

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
/**
 * Calculates pearson correlation between pair of columns in the in the matrix, assuming that there is a strict
 * one to one relationship between the matrix columns and the field specifications in the list.
 *
 * Writes the correlation, pValue and standard error to a file using JSON format.
 *
 * @param matrix the input matrix where fields are represented by as columns and subjects by rows
 * @param fields a list of field specifications for which the correlations are to be calculated
 * @param correlationAnalysisOutputPath is the file to which the results are written
 * @throws Exception
 */
public static void calculateAndOutputCorrelations(RealMatrix matrix, List<FieldRecipe> fields,
                                                   String correlationAnalysisOutputPath) throws Exception {
    PearsonsCorrelation correlation = new PearsonsCorrelation(matrix);
    RealMatrix correlationMatrix = correlation.getCorrelationMatrix();
    RealMatrix pValueMatrix = correlation.getCorrelationPValues();
    RealMatrix standardErrorMatrix = correlation.getCorrelationStandardErrors();

    // Output the correlation analysis
    JSONArray correlationArray = new JSONArray();
    for (int i=0; i<correlationMatrix.getRowDimension(); i++){
        for (int j=0; j<correlationMatrix.getColumnDimension(); j++){
            JSONObject correlationObject = new JSONObject();
            correlationObject.put("xFieldLabel", fields.get(i).toField().getLabel());
            correlationObject.put("yFieldLabel", fields.get(j).toField().getLabel());
            correlationObject.put("correlationCoefficient", correlationMatrix.getEntry(i,j));
            correlationObject.put("pValue", pValueMatrix.getEntry(i,j));
            correlationObject.put("standardError", standardErrorMatrix.getEntry(i,j));
            correlationArray.add(correlationObject);
        }
    }
    Writer writer = new OutputStreamWriter(new FileOutputStream(correlationAnalysisOutputPath), "UTF-8");
    writer.write(correlationArray.toJSONString());
    writer.flush();
    writer.close();
}
 
开发者ID:FutureCitiesCatapult,项目名称:TomboloDigitalConnector,代码行数:37,代码来源:CorrelationAnalysisEngine.java

示例3: Correlation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
public Correlation(final double[] x, final double[] y) {
	arrays = new double[2][x.length];
	for (int i = 0; i < x.length; ++i) {
		arrays[0][i] = x[i];
		arrays[1][i] = y[i];
	}
	final DoubleLinkedList x2 = new DoubleLinkedList();
	final DoubleLinkedList y2 = new DoubleLinkedList();
	for (int i = 0; i < x.length; ++i) {
		if (!Double.isNaN(x[i]) && x[i] != Double.NEGATIVE_INFINITY) {
			x2.add(x[i]);
			y2.add(y[i]);
		}
	}
	final double[] x2arr = x2.toArray();
	final double[] y2arr = y2.toArray();
	covariance = new Covariance().covariance(x2arr, y2arr);
	pearson = new PearsonsCorrelation().correlation(x2arr, y2arr);
	spearman = new SpearmansCorrelation().correlation(x2arr, y2arr);
	mean = (Math.abs(pearson) + Math.abs(spearman)) / 2;
}
 
开发者ID:ProfilingIO,项目名称:insight-ml,代码行数:22,代码来源:Correlation.java

示例4: pearsonr

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
/**
 * Calculates a Pearson correlation coefficient.
 *
 * @param x X data
 * @param y Y data
 * @return Pearson correlation and p-value.
 */
public static double[] pearsonr(Array x, Array y) {
    int m = x.getShape()[0];
    int n = 1;
    double[][] aa = new double[m][n * 2];
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n * 2; j++) {
            if (j < n) {
                aa[i][j] = x.getDouble(i * n + j);
            } else {
                aa[i][j] = y.getDouble(i * n + j - n);
            }
        }
    }
    RealMatrix matrix = new Array2DRowRealMatrix(aa, false);
    PearsonsCorrelation pc = new PearsonsCorrelation(matrix);
    double r = pc.getCorrelationMatrix().getEntry(0, 1);
    double pvalue = pc.getCorrelationPValues().getEntry(0, 1);
    return new double[]{r, pvalue};
}
 
开发者ID:meteoinfo,项目名称:MeteoInfoLib,代码行数:27,代码来源:StatsUtil.java

示例5: getCorrelation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
/** Calculates the correlation between two double arrays
 * 
 * @param a first dobule array
 * @param b second double array
 * @return correlation Pearson't correlation between arrays a and b
 */
private double getCorrelation(double[] a, double[] b) {
    double correlation;
    if (a.length >= 2) {
        correlation = new PearsonsCorrelation().correlation(a, b);
    } else {
        correlation = 1;
    }

    if (Double.isNaN(correlation)) {
        // No correlation defined mathematically means variables have zero std. For discussion about implications:
        // http://stats.stackexchange.com/questions/18333/what-is-the-correlation-if-the-standard-deviation-of-one-variable-is-0
        correlation = 0;
    }
    return correlation;
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:22,代码来源:CorrelationFeatureExtractor.java

示例6: getPearsonCorrelation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
public static double getPearsonCorrelation(ArrayList<Integer> scores1,
		ArrayList<Integer> scores2) {
	PearsonsCorrelation pc = new PearsonsCorrelation();
	double[] sc1 = new double[scores1.size()];
	double[] sc2 = new double[scores2.size()];

	for (int i = 0; i < scores1.size(); i++)
		sc1[i] = scores1.get(i);

	for (int i = 0; i < scores2.size(); i++)
		sc2[i] = scores2.get(i);

	try {
		return pc.correlation(sc1, sc2);
	} catch (Exception ex) {
		return 0;
	}
}
 
开发者ID:transducens,项目名称:forecat,代码行数:19,代码来源:TestOutput.java

示例7: addSummary

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
private void addSummary(String title, double[] sum1, double[] sum2)
{
	BlockRealMatrix rm = new BlockRealMatrix(sum1.length, 2);
	rm.setColumn(0, sum1);
	rm.setColumn(1, sum2);

	SpearmansCorrelation sr = new SpearmansCorrelation(rm);
	PearsonsCorrelation p1 = sr.getRankCorrelation();
	PearsonsCorrelation p2 = new PearsonsCorrelation(rm);

	StringBuilder sb = new StringBuilder(title);
	sb.append(sum1.length).append('\t');
	sb.append(Utils.rounded(p1.getCorrelationMatrix().getEntry(0, 1))).append('\t');
	sb.append(Utils.rounded(p1.getCorrelationPValues().getEntry(0, 1))).append('\t');
	sb.append(Utils.rounded(p2.getCorrelationMatrix().getEntry(0, 1))).append('\t');
	sb.append(Utils.rounded(p2.getCorrelationPValues().getEntry(0, 1)));
	twSummary.append(sb.toString());
}
 
开发者ID:aherbert,项目名称:GDSC,代码行数:19,代码来源:ParticleCorrelation.java

示例8: giveMeCorrelation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
/**
 * esta funcion devuelve en una lista de valores, la correlación entre las variables accel-x accel - y | accel - x accel - z | accel - y accel - z
 * Es importante que en el dataframe este ordenado, ya que el acceso se realiza de manera manual
 * 2ºAccels (x, y, z)
 * 1ºGyros (a , b , g)
 *
 * @param df
 * @return
 */
//PASAR SOLO EL DF DE LOS ACCEL
private List giveMeCorrelation(DataFrame df){
    List retList = new ArrayList();

    double[][] miMatrix = (double[][]) df.toArray(double[][].class);
    RealMatrix rm = new PearsonsCorrelation(miMatrix).getCorrelationMatrix();
    double [][] matrixDebug = rm.getData();

    retList.add(matrixDebug[3][4]);
    retList.add(matrixDebug[3][5]);
    retList.add(matrixDebug[4][5]);

    return retList;
}
 
开发者ID:TfgReconocimientoPulseras,项目名称:TrainAppTFG,代码行数:24,代码来源:SegmentacionDeDatosThread.java

示例9: correlation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
/**
 * Méthode de calcul de corrélation sur un set de points.
 * @param polygon : polygone
 * @param i : indice de départ
 * @param f : indice de fin
 * @return : coefficient de corrélation
 */
private static double correlation(GM_Polygon polygon, int i, int f) {
  PearsonsCorrelation pc = new PearsonsCorrelation();

  double[] X = new double[f-i+1];
  double[] Y = new double[f-i+1];

  for (int id=i; id<=f; id++) {
    X[id-i] = polygon.coord().get(id).getX();
    Y[id-i] = polygon.coord().get(id).getY();
  }

  return Math.abs(pc.correlation(X, Y));
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:21,代码来源:ArcDetection.java

示例10: calculateCorrelations

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
private void calculateCorrelations() {
	double[][] denaned = removeNaNs(x, y);
	if (denaned[0].length > 0) {
		pearsonsCorrelation = new PearsonsCorrelation().correlation(denaned[0], denaned[1]);
		spearmansCorrelation = new SpearmansCorrelation().correlation(denaned[0], denaned[1]);
	}
	correlationsCalculated = true;
}
 
开发者ID:qupath,项目名称:qupath,代码行数:9,代码来源:ScatterPlot.java

示例11: componize

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
public void componize(double [][] covariate){
	
	// replace the initial data set the same values minus the means from each variable-column
	
for (int j=0; j < covariate[0].length; j++ ) {
	
	DescriptiveStatistics stats = new DescriptiveStatistics();	
			
  	 for  (int k=0 ; k < covariate.length ; k++){
  	 stats.addValue(covariate[k][j]);}
	
	double mean=stats.getMean();

	for  (int k=0 ; k < covariate.length ; k++){
	   covariate[k][j]= covariate[k][j]-mean;}

// here ends the iteration that replaces all values with the value minus the mean of the respective column		
}	

// We get the Covariance matrix for the "adjusted by mean" data set
RealMatrix covariance_matrix=  new PearsonsCorrelation(covariate).getCorrelationMatrix();		

// we get the Eigen values and the Eigen Vectors Via Eigen Value Decomposition.

EigenDecomposition Eig = new EigenDecomposition(covariance_matrix, 1);	
// get the Eigen Values	
double Eigenvaluess [] =Eig.getRealEigenvalues();	
// Get the Eigen vectors	
RealMatrix Eigenvec = Eig.getV();	
double [][] EigenVecors=Eigenvec.getData();    
//Sort everything to get the Vectors with the highest significance	
SortTableDouble sort = new SortTableDouble();   
 sort.sorting (Eigenvaluess,EigenVecors );    
 EigenVecor =sort.value_matrix();	
 Eigenvalues=sort.scanned_values();
 Perchentages= new double[Eigenvalues.length];
	 for  (int k=0 ; k < Eigenvalues.length ; k++){
		Perchentages[k]= Eigenvalues[k]/Eigenvalues.length	;} 
}
 
开发者ID:SOCR,项目名称:HTML5_WebSite,代码行数:40,代码来源:pca_analysis.java

示例12: getExpectedValue

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
@Override
public Object getExpectedValue(int start, int length)
{
    if (length <= 1) {
        return null;
    }
    PearsonsCorrelation corr = new PearsonsCorrelation();
    return corr.correlation(constructDoublePrimitiveArray(start + 2, length), constructDoublePrimitiveArray(start, length));
}
 
开发者ID:y-lan,项目名称:presto,代码行数:10,代码来源:TestCorrelationAggregation.java

示例13: testNonTrivialAggregation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
private void testNonTrivialAggregation(double[] y, double[] x)
{
    PearsonsCorrelation corr = new PearsonsCorrelation();
    double expected = corr.correlation(x, y);
    checkArgument(Double.isFinite(expected) && expected != 0.0 && expected != 1.0, "Expected result is trivial");
    testAggregation(expected, createDoublesBlock(box(y)), createDoublesBlock(box(x)));
}
 
开发者ID:y-lan,项目名称:presto,代码行数:8,代码来源:TestCorrelationAggregation.java

示例14: computePearson

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
/**
 * @return Pearson's product-moment correlation coefficients for the measured data
 */
private double[] computePearson() {
    if(freqLeqStats.size() < 3) {
        return null;
    }
    // Frequency count, one dataset by frequency
    int dataSetCount = freqLeqStats.get(freqLeqStats.size() - 1).whiteNoiseLevel.getdBaLevels().length;
    double[] pearsonCoefficient = new double[dataSetCount];

    StringBuilder log = new StringBuilder();
    for(int freqId = 0; freqId < dataSetCount; freqId++) {
        double[] xValues = new double[freqLeqStats.size()];
        double[] yValues = new double[freqLeqStats.size()];
        int idStep = 0;
        for(LinearCalibrationResult result : freqLeqStats) {
            double dbLevel = result.measure[freqId].getLeqMean();
            double whiteNoise = result.whiteNoiseLevel.getdBaLevels()[freqId];
            xValues[idStep] = whiteNoise;
            yValues[idStep] = dbLevel;
            if(freqId == 0) {
                LOGGER.info("100 hZ white noise " + whiteNoise + " dB spl: " + dbLevel+ " dB");
            }
            idStep++;
        }
        pearsonCoefficient[freqId] = new PearsonsCorrelation().correlation(xValues, yValues);
        if(log.length() == 0) {
            log.append("[");
        } else {
            log.append(", ");
        }
        log.append(String.format(Locale.getDefault(), "%.2f %%",pearsonCoefficient[freqId] * 100 ));
    }
    log.append("]");
    LOGGER.info("Pearson's values : "+log.toString());
    return pearsonCoefficient;
}
 
开发者ID:Ifsttar,项目名称:NoiseCapture,代码行数:39,代码来源:CalibrationLinearityActivity.java

示例15: getCorrelation

import org.apache.commons.math3.stat.correlation.PearsonsCorrelation; //导入依赖的package包/类
private double getCorrelation(DoubleMatrix inputRow, DoubleMatrix sine) {
    if (inputRow.length < 2) {
        return 0;
    }
    double correlation = new PearsonsCorrelation().correlation(inputRow.toArray(), sine.toArray());
    return Double.isNaN(correlation) ? 0 : correlation;
}
 
开发者ID:NLeSC,项目名称:eEcology-Classification,代码行数:8,代码来源:FundFreqCorrelationExtractor.java


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