use of org.apache.commons.math3.stat.descriptive.rank.Min in project GDSC-SMLM by aherbert.
the class PoissonCalculatorTest method cumulativeProbabilityIsOneWithRealDataForCountAbove4.
@Test
public void cumulativeProbabilityIsOneWithRealDataForCountAbove4() {
for (double mu : photons) {
// Determine upper limit for a Poisson
double max = new PoissonDistribution(mu).inverseCumulativeProbability(P_LIMIT);
// Determine lower limit
double sd = Math.sqrt(mu);
double min = (int) Math.max(0, mu - 4 * sd);
cumulativeProbabilityIsOneWithRealData(mu, min, max, mu >= 4);
}
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project GDSC-SMLM by aherbert.
the class PulseActivationAnalysis method createShapes.
private Shape[] createShapes(RandomDataGenerator rdg, int c) {
RandomGenerator rand = rdg.getRandomGenerator();
Shape[] shapes;
double min = sim_size / 20;
double max = sim_size / 10;
double range = max - min;
switch(sim_distribution[c]) {
case CIRCLE:
shapes = new Shape[10];
for (int i = 0; i < shapes.length; i++) {
float x = nextCoordinate(rand);
float y = nextCoordinate(rand);
double radius = rand.nextDouble() * range + min;
shapes[i] = new Circle(x, y, radius);
}
break;
case LINE:
shapes = new Shape[10];
for (int i = 0; i < shapes.length; i++) {
float x = nextCoordinate(rand);
float y = nextCoordinate(rand);
double angle = rand.nextDouble() * Math.PI;
double radius = rand.nextDouble() * range + min;
shapes[i] = new Line(x, y, angle, radius);
}
break;
case POINT:
default:
shapes = new Shape[sim_nMolecules[c]];
for (int i = 0; i < shapes.length; i++) {
float x = nextCoordinate(rand);
float y = nextCoordinate(rand);
shapes[i] = new Point(x, y);
}
}
return shapes;
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project GDSC-SMLM by aherbert.
the class SearchSpace method sampleWithRounding.
/**
* Sample with rounding. The input dimensions are used purely for rounding. The limits of the range have been
* precomputed.
*
* @param samples
* the samples
* @param generator
* the generator
* @param indices
* the indices
* @param dimensions
* the dimensions
* @param size
* the size
* @param centre
* the centre
* @param lower
* the lower
* @param range
* the range
* @return the sample
*/
private static double[][] sampleWithRounding(int samples, RandomVectorGenerator[] generator, final int[] indices, final Dimension[] dimensions, int size, final double[] centre, final double[] lower, final double[] range) {
RandomVectorGenerator g = createGenerator(generator, size);
// Generate random points
final double[][] searchSpace = new double[samples][];
for (int i = 0; i < samples; i++) {
final double[] r = g.nextVector();
final double[] p = centre.clone();
for (int j = 0; j < size; j++) {
// Ensure the min interval is respected
p[indices[j]] = dimensions[j].round(lower[j] + r[j] * range[j]);
}
searchSpace[i] = p;
}
return searchSpace;
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project GDSC-SMLM by aherbert.
the class SCMOSLikelihoodWrapperTest method cumulativeProbabilityIsOneWithRealData.
private void cumulativeProbabilityIsOneWithRealData(final double mu, double min, double max, boolean test) {
double p = 0;
// Test using a standard Poisson-Gaussian convolution
//min = -max;
//final PoissonGaussianFunction pgf = PoissonGaussianFunction.createWithVariance(1, 1, VAR);
UnivariateIntegrator in = new SimpsonIntegrator();
p = in.integrate(20000, new UnivariateFunction() {
public double value(double x) {
double v;
v = SCMOSLikelihoodWrapper.likelihood(mu, VAR, G, O, x);
//System.out.printf("x=%f, v=%f\n", x, v);
return v;
}
}, min, max);
//System.out.printf("mu=%f, p=%f\n", mu, p);
if (test) {
Assert.assertEquals(String.format("mu=%f", mu), P_LIMIT, p, 0.02);
}
}
use of org.apache.commons.math3.stat.descriptive.rank.Min in project GDSC-SMLM by aherbert.
the class SCMOSLikelihoodWrapperTest method cumulativeProbabilityIsOneWithRealDataForCountAbove8.
@Test
public void cumulativeProbabilityIsOneWithRealDataForCountAbove8() {
for (double mu : photons) {
// Determine upper limit for a Poisson
double max = new PoissonDistribution(mu).inverseCumulativeProbability(P_LIMIT);
// Determine lower limit
double sd = Math.sqrt(mu);
double min = (int) Math.max(0, mu - 4 * sd);
// Map to observed values using the gain and offset
max = max * G + O;
min = min * G + O;
cumulativeProbabilityIsOneWithRealData(mu, min, max, mu > 8);
}
}
Aggregations