use of org.apache.commons.math3.distribution.UniformRealDistribution in project vcell by virtualcell.
the class BrownianDynamics2DSolver method initializeUniform.
public void initializeUniform(boolean fluorescent) {
//
// initialize to a uniform distribution
//
UniformRealDistribution uniformX = new UniformRealDistribution(simulationRng, origin.getX(), origin.getX() + extent.getX());
UniformRealDistribution uniformY = new UniformRealDistribution(simulationRng, origin.getY(), origin.getY() + extent.getY());
for (int i = 0; i < numParticles; i++) {
particleX[i] = uniformX.sample();
particleY[i] = uniformY.sample();
bFluorescent[i] = fluorescent;
}
currTime = 0.0;
}
use of org.apache.commons.math3.distribution.UniformRealDistribution in project druid by druid-io.
the class BenchmarkColumnValueGenerator method initDistribution.
private void initDistribution() {
BenchmarkColumnSchema.ValueDistribution distributionType = schema.getDistributionType();
ValueType type = schema.getType();
List<Object> enumeratedValues = schema.getEnumeratedValues();
List<Double> enumeratedProbabilities = schema.getEnumeratedProbabilities();
List<Pair<Object, Double>> probabilities = new ArrayList<>();
switch(distributionType) {
case SEQUENTIAL:
// not random, just cycle through numbers from start to end, or cycle through enumerated values if provided
distribution = new SequentialDistribution(schema.getStartInt(), schema.getEndInt(), schema.getEnumeratedValues());
break;
case UNIFORM:
distribution = new UniformRealDistribution(schema.getStartDouble(), schema.getEndDouble());
break;
case DISCRETE_UNIFORM:
if (enumeratedValues == null) {
enumeratedValues = new ArrayList<>();
for (int i = schema.getStartInt(); i < schema.getEndInt(); i++) {
Object val = convertType(i, type);
enumeratedValues.add(val);
}
}
// give them all equal probability, the library will normalize probabilities to sum to 1.0
for (int i = 0; i < enumeratedValues.size(); i++) {
probabilities.add(new Pair<>(enumeratedValues.get(i), 0.1));
}
distribution = new EnumeratedTreeDistribution<>(probabilities);
break;
case NORMAL:
distribution = new NormalDistribution(schema.getMean(), schema.getStandardDeviation());
break;
case ROUNDED_NORMAL:
NormalDistribution normalDist = new NormalDistribution(schema.getMean(), schema.getStandardDeviation());
distribution = new RealRoundingDistribution(normalDist);
break;
case ZIPF:
int cardinality;
if (enumeratedValues == null) {
Integer startInt = schema.getStartInt();
cardinality = schema.getEndInt() - startInt;
ZipfDistribution zipf = new ZipfDistribution(cardinality, schema.getZipfExponent());
for (int i = 0; i < cardinality; i++) {
probabilities.add(new Pair<>((Object) (i + startInt), zipf.probability(i)));
}
} else {
cardinality = enumeratedValues.size();
ZipfDistribution zipf = new ZipfDistribution(enumeratedValues.size(), schema.getZipfExponent());
for (int i = 0; i < cardinality; i++) {
probabilities.add(new Pair<>(enumeratedValues.get(i), zipf.probability(i)));
}
}
distribution = new EnumeratedTreeDistribution<>(probabilities);
break;
case ENUMERATED:
for (int i = 0; i < enumeratedValues.size(); i++) {
probabilities.add(new Pair<>(enumeratedValues.get(i), enumeratedProbabilities.get(i)));
}
distribution = new EnumeratedTreeDistribution<>(probabilities);
break;
default:
throw new UnsupportedOperationException("Unknown distribution type: " + distributionType);
}
if (distribution instanceof AbstractIntegerDistribution) {
((AbstractIntegerDistribution) distribution).reseedRandomGenerator(seed);
} else if (distribution instanceof AbstractRealDistribution) {
((AbstractRealDistribution) distribution).reseedRandomGenerator(seed);
} else if (distribution instanceof EnumeratedDistribution) {
((EnumeratedDistribution) distribution).reseedRandomGenerator(seed);
}
}
use of org.apache.commons.math3.distribution.UniformRealDistribution in project GDSC-SMLM by aherbert.
the class CreateData method createPhotonDistribution.
/**
* Creates the photon distribution.
*
* @return A photon distribution loaded from a file of floating-point values with the specified
* population mean.
*/
private RealDistribution createPhotonDistribution() {
if (PHOTON_DISTRIBUTION[PHOTON_CUSTOM].equals(settings.getPhotonDistribution())) {
// Get the distribution file
final String filename = ImageJUtils.getFilename("Photon_distribution", settings.getPhotonDistributionFile());
if (filename != null) {
settings.setPhotonDistributionFile(filename);
try (BufferedReader in = new BufferedReader(new UnicodeReader(new FileInputStream(new File(settings.getPhotonDistributionFile())), null))) {
final StoredDataStatistics stats = new StoredDataStatistics();
String str = in.readLine();
double val = 0.0d;
while (str != null) {
val = Double.parseDouble(str);
stats.add(val);
str = in.readLine();
}
if (stats.getSum() > 0) {
// Update the statistics to the desired mean.
final double scale = settings.getPhotonsPerSecond() / stats.getMean();
final double[] values = stats.getValues();
for (int i = 0; i < values.length; i++) {
values[i] *= scale;
}
// TODO - Investigate the limits of this distribution.
// How far above and below the input data will values be generated.
// Create the distribution using the recommended number of bins
final int binCount = stats.getN() / 10;
final EmpiricalDistribution dist = new EmpiricalDistribution(binCount, new RandomGeneratorAdapter(createRandomGenerator()));
dist.load(values);
return dist;
}
} catch (final IOException | NullArgumentException | NumberFormatException ex) {
// Ignore
}
}
ImageJUtils.log("Failed to load custom photon distribution from file: %s. Default to fixed.", settings.getPhotonDistributionFile());
} else if (PHOTON_DISTRIBUTION[PHOTON_UNIFORM].equals(settings.getPhotonDistribution())) {
if (settings.getPhotonsPerSecond() < settings.getPhotonsPerSecondMaximum()) {
return new UniformRealDistribution(new RandomGeneratorAdapter(createRandomGenerator()), settings.getPhotonsPerSecond(), settings.getPhotonsPerSecondMaximum());
}
} else if (PHOTON_DISTRIBUTION[PHOTON_GAMMA].equals(settings.getPhotonDistribution())) {
final double scaleParameter = settings.getPhotonsPerSecond() / settings.getPhotonShape();
return new GammaDistribution(new RandomGeneratorAdapter(createRandomGenerator()), settings.getPhotonShape(), scaleParameter, ExponentialDistribution.DEFAULT_INVERSE_ABSOLUTE_ACCURACY);
} else if (PHOTON_DISTRIBUTION[PHOTON_CORRELATED].equals(settings.getPhotonDistribution())) {
// No distribution required
return null;
}
settings.setPhotonDistribution(PHOTON_DISTRIBUTION[PHOTON_FIXED]);
return null;
}
Aggregations