use of org.apache.commons.math3.stat.descriptive.moment.Variance in project vcell by virtualcell.
the class BrownianDynamics2DSolver method bleachGuassian0.
private long bleachGuassian0(double muX, double muY, double psfVar, double bleachFactor_K, double deltaT) {
//
// distribute each particle using a normalized Gaussian point spread function with variance psfVar.
// we add the fluorescence to the image (can be called multiple times to accumulate fluorescence).
//
long bleachCount = 0;
double DISTANCE_6_SIGMA = Math.sqrt(psfVar) * 6;
for (int p = 0; p < numParticles; p++) {
if (bFluorescent[p]) {
double pX = particleX[p] - muX;
double pY = particleY[p] - muY;
double radius2 = pX * pX + pY * pY;
if (radius2 < DISTANCE_6_SIGMA) {
double particleFluorRate = bleachFactor_K * deltaT * FastMath.exp(-radius2 / psfVar);
PoissonDistribution poisson = new PoissonDistribution(simulationRng, particleFluorRate, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS);
if (poisson.sample() >= 1) {
// if bleaching event happened
bFluorescent[p] = false;
bleachCount++;
}
}
}
}
return bleachCount;
}
use of org.apache.commons.math3.stat.descriptive.moment.Variance in project metron by apache.
the class StellarStatisticsFunctionsTest method run.
/**
* Runs a Stellar expression.
* @param expr The expression to run.
* @param variables The variables available to the expression.
*/
private static Object run(String expr, Map<String, Object> variables) {
StellarProcessor processor = new StellarProcessor();
Object ret = processor.parse(expr, new DefaultVariableResolver(x -> variables.get(x), x -> variables.containsKey(x)), StellarFunctions.FUNCTION_RESOLVER(), Context.EMPTY_CONTEXT());
byte[] raw = SerDeUtils.toBytes(ret);
Object actual = SerDeUtils.fromBytes(raw, Object.class);
if (ret instanceof StatisticsProvider) {
StatisticsProvider left = (StatisticsProvider) ret;
StatisticsProvider right = (StatisticsProvider) actual;
// N
tolerantAssertEquals(prov -> prov.getCount(), left, right);
// sum
tolerantAssertEquals(prov -> prov.getSum(), left, right, 1e-3);
// sum of squares
tolerantAssertEquals(prov -> prov.getSumSquares(), left, right, 1e-3);
// sum of squares
tolerantAssertEquals(prov -> prov.getSumLogs(), left, right, 1e-3);
// Mean
tolerantAssertEquals(prov -> prov.getMean(), left, right, 1e-3);
// Quadratic Mean
tolerantAssertEquals(prov -> prov.getQuadraticMean(), left, right, 1e-3);
// SD
tolerantAssertEquals(prov -> prov.getStandardDeviation(), left, right, 1e-3);
// Variance
tolerantAssertEquals(prov -> prov.getVariance(), left, right, 1e-3);
// Min
tolerantAssertEquals(prov -> prov.getMin(), left, right, 1e-3);
// Max
tolerantAssertEquals(prov -> prov.getMax(), left, right, 1e-3);
// Kurtosis
tolerantAssertEquals(prov -> prov.getKurtosis(), left, right, 1e-3);
// Skewness
tolerantAssertEquals(prov -> prov.getSkewness(), left, right, 1e-3);
for (double d = 10.0; d < 100.0; d += 10) {
final double pctile = d;
// This is a sketch, so we're a bit more forgiving here in our choice of \epsilon.
tolerantAssertEquals(prov -> prov.getPercentile(pctile), left, right, 1e-2);
}
}
return ret;
}
Aggregations