use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.
the class AstigmatismModelManager method getImageList.
private static String[] getImageList() {
final LocalList<String> newImageList = new LocalList<>();
for (final int id : ImageJUtils.getIdList()) {
final ImagePlus imp = WindowManager.getImage(id);
if (imp == null) {
continue;
}
if (imp.getNDimensions() != 3) {
continue;
}
if (imp.getBitDepth() == 24) {
continue;
}
final Roi roi = imp.getRoi();
if (roi == null || roi.getType() != Roi.POINT) {
continue;
}
final FloatPolygon p = roi.getFloatPolygon();
if (p.npoints != 1) {
continue;
}
newImageList.add(imp.getTitle());
}
return newImageList.toArray(new String[0]);
}
use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.
the class BenchmarkSpotFilter method runAnalysis.
private BenchmarkSpotFilterResult runAnalysis(FitEngineConfiguration config, boolean batchSummary) {
if (ImageJUtils.isInterrupted()) {
return null;
}
final MaximaSpotFilter spotFilter = config.createSpotFilter();
if (!batchMode) {
IJ.showStatus("Computing results ...");
}
final ImageStack stack = imp.getImageStack();
float background = 0;
if (spotFilter.isAbsoluteIntensity()) {
if (Float.isNaN(resultsBackground)) {
// To allow the signal factor to be computed we need to lower the image by the background so
// that the intensities correspond to the results amplitude.
// Just assume the simulation background is uniform.
final StandardResultProcedure s = new StandardResultProcedure(results, IntensityUnit.PHOTON);
s.getB();
resultsBackground = (float) (MathUtils.sum(s.background) / results.size());
}
background = this.resultsBackground;
}
// Create the weights if needed
if (cameraModel.isPerPixelModel() && spotFilter.isWeighted() && weights == null) {
bounds = cameraModel.getBounds();
weights = cameraModel.getNormalisedWeights(bounds);
}
// Create a pool of workers
final int nThreads = Prefs.getThreads();
final BlockingQueue<Integer> jobs = new ArrayBlockingQueue<>(nThreads * 2);
final List<Worker> workers = new LocalList<>(nThreads);
final List<Thread> threads = new LocalList<>(nThreads);
for (int i = 0; i < nThreads; i++) {
final Worker worker = new Worker(jobs, stack, spotFilter, background, simulationCoords);
final Thread t = new Thread(worker);
workers.add(worker);
threads.add(t);
t.start();
}
// Fit the frames
for (int i = 1; i <= stack.getSize(); i++) {
put(jobs, i);
}
// 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 (final InterruptedException ex) {
Thread.currentThread().interrupt();
throw new ConcurrentRuntimeException("Unexpected interrupt", ex);
}
}
threads.clear();
if (ImageJUtils.isInterrupted()) {
return null;
}
if (!batchMode) {
IJ.showProgress(-1);
IJ.showStatus("Collecting results ...");
}
TIntObjectHashMap<FilterResult> filterResults = null;
time = 0;
for (int i = 0; i < workers.size(); i++) {
final Worker w = workers.get(i);
time += w.time;
if (filterResults == null) {
filterResults = w.results;
} else {
filterResults.putAll(w.results);
w.results.clear();
w.results.compact();
}
}
if (filterResults == null) {
throw new NullPointerException();
}
filterResults.compact();
if (!batchMode) {
IJ.showStatus("Summarising results ...");
}
// Show a table of the results
final BenchmarkSpotFilterResult filterResult = summariseResults(filterResults, config, spotFilter, batchSummary);
if (!batchMode) {
IJ.showStatus("");
}
return filterResult;
}
use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.
the class CreateData method createPsfModel.
private PsfModel createPsfModel(double[] xyz) {
// Create a set with a single model
final List<LocalisationModelSet> localisationSets = new LocalList<>(1);
final LocalisationModelSet set = new LocalisationModelSet(0, 0);
final LocalisationModel m = new LocalisationModel(0, 0, xyz, 1, 0);
set.add(m);
localisationSets.add(set);
return createPsfModel(localisationSets);
}
use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.
the class EjmlLinearSolverTest method runSolverSpeedTest.
private void runSolverSpeedTest(RandomSeed seed, int flags) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final Gaussian2DFunction f0 = GaussianFunctionFactory.create2D(1, 10, 10, flags, null);
final int n = f0.size();
final double[] y = new double[n];
final LocalList<DenseMatrix64F> aList = new LocalList<>();
final LocalList<DenseMatrix64F> bList = new LocalList<>();
final double[] testbackground = new double[] { 0.2, 0.7 };
final double[] testsignal1 = new double[] { 30, 100, 300 };
final double[] testcx1 = new double[] { 4.9, 5.3 };
final double[] testcy1 = new double[] { 4.8, 5.2 };
final double[] testw1 = new double[] { 1.1, 1.2, 1.5 };
final int np = f0.getNumberOfGradients();
final GradientCalculator calc = GradientCalculatorUtils.newCalculator(np);
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
// double lambda = 10;
for (final double background : testbackground) {
// Peak 1
for (final double signal1 : testsignal1) {
for (final double cx1 : testcx1) {
for (final double cy1 : testcy1) {
for (final double w1 : testw1) {
final double[] p = new double[] { background, signal1, 0, cx1, cy1, w1, w1 };
f0.initialise(p);
f0.forEach(new ValueProcedure() {
int index = 0;
@Override
public void execute(double value) {
// Poisson data
y[index++] = GdscSmlmTestUtils.createPoissonSampler(rng, value).sample();
}
});
final double[][] alpha = new double[np][np];
final double[] beta = new double[np];
// double ss =
calc.findLinearised(n, y, p, alpha, beta, f0);
// TestLog.fine(logger,"SS = %f", ss);
// As per the LVM algorithm
// for (int i = 0; i < np; i++)
// alpha[i][i] *= lambda;
aList.add(EjmlLinearSolver.toA(alpha));
bList.add(EjmlLinearSolver.toB(beta));
}
}
}
}
}
final DenseMatrix64F[] a = aList.toArray(new DenseMatrix64F[0]);
final DenseMatrix64F[] b = bList.toArray(new DenseMatrix64F[0]);
final int runs = 100000 / a.length;
final TimingService ts = new TimingService(runs);
final LocalList<SolverTimingTask> tasks = new LocalList<>();
// Added in descending speed order
tasks.add(new PseudoInverseSolverTimingTask(a, b));
tasks.add(new LinearSolverTimingTask(a, b));
tasks.add(new CholeskySolverTimingTask(a, b));
tasks.add(new CholeskyLdltSolverTimingTask(a, b));
tasks.add(new DirectInversionSolverTimingTask(a, b));
for (final SolverTimingTask task : tasks) {
if (!task.badSolver) {
ts.execute(task);
}
}
final int size = ts.getSize();
ts.repeat();
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport(size));
}
// Just check the PseudoInverse is slowest
for (int i = 1; i < size; i++) {
logger.log(TestLogUtils.getTimingRecord(ts.get(-(size)), ts.get(-i)));
}
if (np > 2) {
// The Direct solver may not be faster at size=5
int i = (np == 5) ? 2 : 1;
final int size_1 = size - 1;
for (; i < size_1; i++) {
logger.log(TestLogUtils.getTimingRecord(ts.get(-(size_1)), ts.get(-i)));
}
}
}
use of uk.ac.sussex.gdsc.core.utils.LocalList in project GDSC-SMLM by aherbert.
the class EjmlLinearSolverTest method runInversionSpeedTest.
private void runInversionSpeedTest(RandomSeed seed, int flags) {
Assumptions.assumeTrue(TestSettings.allow(TestComplexity.MEDIUM));
final Gaussian2DFunction f0 = GaussianFunctionFactory.create2D(1, 10, 10, flags, null);
final int n = f0.size();
final double[] y = new double[n];
final LocalList<DenseMatrix64F> aList = new LocalList<>();
final double[] testbackground = new double[] { 0.2, 0.7 };
final double[] testsignal1 = new double[] { 30, 100, 300 };
final double[] testcx1 = new double[] { 4.9, 5.3 };
final double[] testcy1 = new double[] { 4.8, 5.2 };
final double[] testw1 = new double[] { 1.1, 1.2, 1.5 };
final int np = f0.getNumberOfGradients();
final GradientCalculator calc = GradientCalculatorUtils.newCalculator(np);
final UniformRandomProvider rng = RngUtils.create(seed.getSeed());
// double lambda = 10;
for (final double background : testbackground) {
// Peak 1
for (final double signal1 : testsignal1) {
for (final double cx1 : testcx1) {
for (final double cy1 : testcy1) {
for (final double w1 : testw1) {
final double[] p = new double[] { background, signal1, 0, cx1, cy1, w1, w1 };
f0.initialise(p);
f0.forEach(new ValueProcedure() {
int index = 0;
@Override
public void execute(double value) {
// Poisson data
y[index++] = GdscSmlmTestUtils.createPoissonSampler(rng, value).sample();
}
});
final double[][] alpha = new double[np][np];
final double[] beta = new double[np];
// double ss =
calc.findLinearised(n, y, p, alpha, beta, f0);
// TestLog.fine(logger,"SS = %f", ss);
// As per the LVM algorithm
// for (int i = 0; i < np; i++)
// alpha[i][i] *= lambda;
aList.add(EjmlLinearSolver.toA(alpha));
}
}
}
}
}
final DenseMatrix64F[] a = aList.toArray(new DenseMatrix64F[0]);
final boolean[] ignore = new boolean[a.length];
final double[][] answer = new double[a.length][];
final int runs = 100000 / a.length;
final TimingService ts = new TimingService(runs);
final LocalList<InversionTimingTask> tasks = new LocalList<>();
// Added in descending speed order
tasks.add(new PseudoInverseInversionTimingTask(a, ignore, answer));
tasks.add(new LinearInversionTimingTask(a, ignore, answer));
tasks.add(new CholeskyLdltInversionTimingTask(a, ignore, answer));
tasks.add(new CholeskyInversionTimingTask(a, ignore, answer));
tasks.add(new DirectInversionInversionTimingTask(a, ignore, answer));
tasks.add(new DiagonalDirectInversionInversionTimingTask(a, ignore, answer));
for (final InversionTimingTask task : tasks) {
if (!task.badSolver) {
ts.execute(task);
}
}
final int size = ts.getSize();
ts.repeat();
if (logger.isLoggable(Level.INFO)) {
logger.info(ts.getReport(size));
}
// When it is present the DiagonalDirect is fastest (n<=5)
if (np <= 5) {
for (int i = 2; i <= size; i++) {
logger.log(TestLogUtils.getTimingRecord(ts.get(-i), ts.get(-1)));
}
if (np < 5) {
// n < 5 Direct is fastest
for (int i = 3; i <= size; i++) {
logger.log(TestLogUtils.getTimingRecord(ts.get(-i), ts.get(-2)));
}
} else {
// and may not be faster than Direct at n=5 so that comparison is ignored.
for (int i = 4; i <= size; i++) {
logger.log(TestLogUtils.getTimingRecord(ts.get(-i), ts.get(-3)));
}
}
} else {
// Cholesky should be fastest.
for (int i = 2; i <= size; i++) {
logger.log(TestLogUtils.getTimingRecord(ts.get(-i), ts.get(-1)));
}
}
}
Aggregations