Search in sources :

Example 6 with TIntProcedure

use of gnu.trove.procedure.TIntProcedure in project GDSC-SMLM by aherbert.

the class DoubletAnalysis method run.

/**
	 * Run.
	 */
private void run() {
    doubletResults = null;
    final ImageStack stack = imp.getImageStack();
    // Get the coordinates per frame
    TIntObjectHashMap<ArrayList<Coordinate>> actualCoordinates = ResultsMatchCalculator.getCoordinates(results.getResults(), false);
    final long[] sumCount = new long[1];
    actualCoordinates.forEachValue(new TObjectProcedure<ArrayList<Coordinate>>() {

        public boolean execute(ArrayList<Coordinate> list) {
            sumCount[0] += list.size();
            return true;
        }
    });
    final double density = 1e6 * sumCount[0] / (simulationParameters.a * simulationParameters.a * results.getBounds().getWidth() * results.getBounds().getHeight() * actualCoordinates.size());
    // Create a pool of workers
    final int nThreads = Prefs.getThreads();
    final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<Integer>(nThreads * 2);
    List<Worker> workers = new LinkedList<Worker>();
    List<Thread> threads = new LinkedList<Thread>();
    Overlay overlay = (showOverlay) ? new Overlay() : null;
    for (int i = 0; i < nThreads; i++) {
        Worker worker = new Worker(jobs, stack, actualCoordinates, fitConfig, overlay);
        Thread t = new Thread(worker);
        workers.add(worker);
        threads.add(t);
        t.start();
    }
    // Fit the frames
    long runTime = System.nanoTime();
    totalProgress = actualCoordinates.size();
    stepProgress = Utils.getProgressInterval(totalProgress);
    progress = 0;
    actualCoordinates.forEachKey(new TIntProcedure() {

        public boolean execute(int frame) {
            put(jobs, frame);
            return true;
        }
    });
    // Finish all the worker threads by passing in a null job
    for (int i = 0; i < threads.size(); i++) {
        put(jobs, -1);
    }
    // Wait for all to finish
    for (int i = 0; i < threads.size(); i++) {
        try {
            threads.get(i).join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    threads.clear();
    threads = null;
    IJ.showProgress(1);
    IJ.showStatus("Collecting results ...");
    runTime = System.nanoTime() - runTime;
    // Collect the results
    int cic = 0, daic = 0, dbic = 0;
    ArrayList<DoubletResult> results = null;
    int maxH = 0, maxH2 = 0, maxH3 = 0;
    for (Worker worker : workers) {
        if (results == null)
            results = worker.results;
        else
            results.addAll(worker.results);
        cic += worker.cic;
        daic += worker.daic;
        dbic += worker.dbic;
        maxH = Maths.max(maxH, worker.spotHistogram.length);
        for (int k = 0; k < 3; k++) {
            maxH2 = Maths.max(maxH2, worker.neighbourHistogram[k].length);
            maxH3 = Maths.max(maxH3, worker.almostNeighbourHistogram[k].length);
        }
    }
    if (cic > 0)
        System.out.printf("Difference AIC %d, BIC %d, Total %d\n", daic, dbic, cic);
    if (showHistograms) {
        double[] spotHistogram = new double[maxH];
        double[] resultHistogram = new double[maxH];
        double[][] neighbourHistogram = new double[3][maxH2];
        double[][] almostNeighbourHistogram = new double[3][maxH3];
        for (Worker worker : workers) {
            final int[] h1a = worker.spotHistogram;
            final int[] h1b = worker.resultHistogram;
            for (int j = 0; j < h1a.length; j++) {
                spotHistogram[j] += h1a[j];
                resultHistogram[j] += h1b[j];
            }
            final int[][] h2 = worker.neighbourHistogram;
            final int[][] h3 = worker.almostNeighbourHistogram;
            for (int k = 0; k < 3; k++) {
                for (int j = 0; j < h2[k].length; j++) neighbourHistogram[k][j] += h2[k][j];
                for (int j = 0; j < h3[k].length; j++) almostNeighbourHistogram[k][j] += h3[k][j];
            }
        }
        showHistogram(0, spotHistogram);
        showHistogram(1, resultHistogram);
        showHistogram(2, neighbourHistogram[0]);
        showHistogram(3, neighbourHistogram[1]);
        showHistogram(4, neighbourHistogram[2]);
        showHistogram(5, almostNeighbourHistogram[0]);
        showHistogram(6, almostNeighbourHistogram[1]);
        showHistogram(7, almostNeighbourHistogram[2]);
    }
    workers.clear();
    workers = null;
    if (overlay != null)
        imp.setOverlay(overlay);
    MemoryPeakResults.freeMemory();
    Collections.sort(results);
    summariseResults(results, density, runTime);
    windowOrganiser.tile();
    IJ.showStatus("");
}
Also used : TIntProcedure(gnu.trove.procedure.TIntProcedure) ArrayList(java.util.ArrayList) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) FitWorker(gdsc.smlm.engine.FitWorker) Overlay(ij.gui.Overlay) ImageStack(ij.ImageStack) PeakResultPoint(gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint) BasePoint(gdsc.core.match.BasePoint) LinkedList(java.util.LinkedList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Coordinate(gdsc.core.match.Coordinate)

Example 7 with TIntProcedure

use of gnu.trove.procedure.TIntProcedure in project ProPPR by TeamCohen.

the class PosNegRWExample method toString.

public String toString() {
    final StringBuilder sb = new StringBuilder("PosNegRWExample[");
    sb.append(this.name).append(" ");
    sb.append(graph.nodeSize()).append("/").append(graph.edgeSize()).append("; [");
    queryVec.forEachKey(new TIntProcedure() {

        @Override
        public boolean execute(int q) {
            sb.append(q).append(",");
            return true;
        }
    });
    if (sb.length() > 0)
        sb.deleteCharAt(sb.length() - 1);
    sb.append("] -> +[");
    if (posList.length > 0) {
        Dictionary.buildString(posList, sb, ",", true);
    }
    ;
    sb.append("]; -[");
    if (negList.length > 0) {
        Dictionary.buildString(negList, sb, ",", true);
    }
    ;
    sb.append("]]");
    return sb.toString();
}
Also used : TIntProcedure(gnu.trove.procedure.TIntProcedure)

Example 8 with TIntProcedure

use of gnu.trove.procedure.TIntProcedure in project ProPPR by TeamCohen.

the class LightweightStateGraph method near.

public List<State> near(State u) {
    int ui = this.nodeTab.getId(u);
    if (!near.containsKey(ui))
        return DEFAULT_NEAR;
    TIntArrayList vs = near.get(ui);
    final ArrayList<State> ret = new ArrayList<State>(vs.size());
    vs.forEach(new TIntProcedure() {

        @Override
        public boolean execute(int vi) {
            ret.add(nodeTab.getSymbol(vi));
            return true;
        }
    });
    return ret;
}
Also used : TIntProcedure(gnu.trove.procedure.TIntProcedure) State(edu.cmu.ml.proppr.prove.wam.State) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TIntArrayList(gnu.trove.list.array.TIntArrayList)

Aggregations

TIntProcedure (gnu.trove.procedure.TIntProcedure)8 PeakResultPoint (gdsc.smlm.ij.plugins.ResultsMatchCalculator.PeakResultPoint)3 ImageStack (ij.ImageStack)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)3 BasePoint (gdsc.core.match.BasePoint)2 FitWorker (gdsc.smlm.engine.FitWorker)2 TIntHashSet (gnu.trove.set.hash.TIntHashSet)2 State (edu.cmu.ml.proppr.prove.wam.State)1 Coordinate (gdsc.core.match.Coordinate)1 MaximaSpotFilter (gdsc.smlm.filters.MaximaSpotFilter)1 PeakResult (gdsc.smlm.results.PeakResult)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 TIntObjectHashMap (gnu.trove.map.hash.TIntObjectHashMap)1 Overlay (ij.gui.Overlay)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1