All Downloads are FREE. Search and download functionalities are using the official Maven repository.

umcg.genetica.math.stats.concurrent.ConcurrentCorrelation Maven / Gradle / Ivy

There is a newer version: 1.0.7
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package umcg.genetica.math.stats.concurrent;

import cern.colt.matrix.tdouble.DoubleMatrix2D;
import cern.colt.matrix.tdouble.impl.DenseDoubleMatrix1D;
import cern.colt.matrix.tdouble.impl.DenseDoubleMatrix2D;
import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import umcg.genetica.console.ProgressBar;
import umcg.genetica.containers.Pair;
import umcg.genetica.math.stats.Descriptives;

/**
 *
 * @author harmjan
 */
public class ConcurrentCorrelation {

    private int nrThreads = Runtime.getRuntime().availableProcessors();

    public ConcurrentCorrelation() {
    }

    public ConcurrentCorrelation(int nrProcs) {
        nrThreads = nrProcs;
    }

    public double[][] pairwiseCorrelation(double[][] in) {
        ExecutorService threadPool = Executors.newFixedThreadPool(nrThreads);
        CompletionService> pool = new ExecutorCompletionService>(threadPool);
        double meanOfSamples[] = new double[in.length];
        
        for(int i=0; i result = pool.take().get();
                if (result != null) {
                    int rownr = result.getLeft(); //  < 0 when row is not to be included because of hashProbesToInclude.
                    if (rownr >= 0) {
                        double[] doubles = result.getRight();
                        correlationMatrix[rownr] = doubles;
                    }
                    result = null;
                    returned++;
                    pb.iterate();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        for(int r=1;r> pool = new ExecutorCompletionService>(threadPool);
        double meanOfSamples[] = new double[in.length];
        
        for(int i=0; i result = pool.take().get();
                if (result != null) {
                    int rownr = result.getLeft(); //  < 0 when row is not to be included because of hashProbesToInclude.
                    if (rownr >= 0) {
                        double[] doubles = result.getRight();
                        for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy