use of org.apache.commons.math3.random.RandomGenerator in project GDSC-SMLM by aherbert.
the class PoissonGradientProcedureTest method createFakeData.
private double[] createFakeData(double[] params) {
int n = blockWidth * blockWidth;
RandomGenerator r = rdg.getRandomGenerator();
for (int i = 0; i < params.length; i++) {
params[i] = r.nextDouble();
}
double[] y = new double[n];
for (int i = 0; i < y.length; i++) {
y[i] = r.nextDouble();
}
return y;
}
use of org.apache.commons.math3.random.RandomGenerator in project GDSC-SMLM by aherbert.
the class BaseFunctionSolverTest method computeSCMOSWeights.
private static void computeSCMOSWeights(double[] weights, double[] noise) {
// Per observation read noise.
weights = new double[size * size];
RandomGenerator randomGenerator = new Well19937c(42);
ExponentialDistribution ed = new ExponentialDistribution(randomGenerator, variance, ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
for (int i = 0; i < weights.length; i++) {
double pixelVariance = ed.sample();
double pixelGain = Math.max(0.1, gain + randomGenerator.nextGaussian() * gainSD);
// weights = var / g^2
weights[i] = pixelVariance / (pixelGain * pixelGain);
}
// Convert to standard deviation for simulation
noise = new double[weights.length];
for (int i = 0; i < weights.length; i++) noise[i] = Math.sqrt(weights[i]);
}
use of org.apache.commons.math3.random.RandomGenerator in project GDSC-SMLM by aherbert.
the class BaseFunctionSolverTest method drawGaussian.
/**
* Draw a Gaussian with Poisson shot noise and Gaussian read noise.
*
* @param params
* The Gaussian parameters
* @param noise
* The read noise
* @param noiseModel
* the noise model
* @return The data
*/
double[] drawGaussian(double[] params, double[] noise, NoiseModel noiseModel) {
double[] data = new double[size * size];
int n = params.length / 6;
Gaussian2DFunction f = GaussianFunctionFactory.create2D(n, size, size, flags, null);
f.initialise(params);
// Poisson noise
for (int i = 0; i < data.length; i++) {
CustomPoissonDistribution dist = new CustomPoissonDistribution(randomGenerator, 1);
double e = f.eval(i);
if (e > 0) {
dist.setMeanUnsafe(e);
data[i] = dist.sample();
}
}
// Simulate EM-gain
if (noiseModel == NoiseModel.EMCCD) {
// Use a gamma distribution
// Since the call random.nextGamma(...) creates a Gamma distribution
// which pre-calculates factors only using the scale parameter we
// create a custom gamma distribution where the shape can be set as a property.
CustomGammaDistribution dist = new CustomGammaDistribution(randomGenerator, 1, emGain);
for (int i = 0; i < data.length; i++) {
if (data[i] > 0) {
dist.setShapeUnsafe(data[i]);
// The sample will amplify the signal so we remap to the original scale
data[i] = dist.sample() / emGain;
}
}
}
// Read-noise
if (noise != null) {
for (int i = 0; i < data.length; i++) {
data[i] += randomGenerator.nextGaussian() * noise[i];
}
}
//gdsc.core.ij.Utils.display("Spot", data, size, size);
return data;
}
use of org.apache.commons.math3.random.RandomGenerator in project GDSC-SMLM by aherbert.
the class LSQLVMGradientProcedureTest method createFakeData.
private double[] createFakeData(double[] params) {
int n = blockWidth * blockWidth;
RandomGenerator r = rdg.getRandomGenerator();
for (int i = 0; i < params.length; i++) {
params[i] = r.nextDouble();
}
double[] y = new double[n];
for (int i = 0; i < y.length; i++) {
y[i] = r.nextDouble();
}
return y;
}
use of org.apache.commons.math3.random.RandomGenerator 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;
}
Aggregations