Search in sources :

Example 41 with Gaussian

use of org.apache.commons.math3.analysis.function.Gaussian 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;
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution)

Example 42 with Gaussian

use of org.apache.commons.math3.analysis.function.Gaussian in project metron by apache.

the class OnlineStatisticsProviderTest method testNormallyDistributedRandomDataSkewed.

@Test
public void testNormallyDistributedRandomDataSkewed() {
    List<Double> values = new ArrayList<>();
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    for (int i = 0; i < 1000000; ++i) {
        double d = (gaussian.nextNormalizedDouble() + 10000) / 1000;
        values.add(d);
    }
    validateEquality(values);
}
Also used : GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.jupiter.api.Test)

Example 43 with Gaussian

use of org.apache.commons.math3.analysis.function.Gaussian in project metron by apache.

the class OnlineStatisticsProviderTest method testNormallyDistributedRandomData.

@Test
public void testNormallyDistributedRandomData() {
    List<Double> values = new ArrayList<>();
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    for (int i = 0; i < 1000000; ++i) {
        double d = gaussian.nextNormalizedDouble();
        values.add(d);
    }
    validateEquality(values);
}
Also used : GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.jupiter.api.Test)

Example 44 with Gaussian

use of org.apache.commons.math3.analysis.function.Gaussian in project metron by apache.

the class OnlineStatisticsProviderTest method testNormallyDistributedRandomDataAllNegative.

@Test
public void testNormallyDistributedRandomDataAllNegative() {
    List<Double> values = new ArrayList<>();
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    for (int i = 0; i < 1000000; ++i) {
        double d = -1 * gaussian.nextNormalizedDouble();
        values.add(d);
    }
    validateEquality(values);
}
Also used : GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.jupiter.api.Test)

Example 45 with Gaussian

use of org.apache.commons.math3.analysis.function.Gaussian in project metron by apache.

the class MedianAbsoluteDeviationTest method test.

@Test
public void test() {
    GaussianRandomGenerator gaussian = new GaussianRandomGenerator(new MersenneTwister(0L));
    DescriptiveStatistics stats = new DescriptiveStatistics();
    List<MedianAbsoluteDeviationFunctions.State> states = new ArrayList<>();
    MedianAbsoluteDeviationFunctions.State currentState = null;
    // initialize the state
    currentState = (MedianAbsoluteDeviationFunctions.State) run("OUTLIER_MAD_STATE_MERGE(states, NULL)", ImmutableMap.of("states", states));
    for (int i = 0, j = 0; i < 10000; ++i, ++j) {
        Double d = gaussian.nextNormalizedDouble();
        stats.addValue(d);
        run("OUTLIER_MAD_ADD(currentState, data)", ImmutableMap.of("currentState", currentState, "data", d));
        if (j >= 1000) {
            j = 0;
            List<MedianAbsoluteDeviationFunctions.State> stateWindow = new ArrayList<>();
            for (int stateIndex = Math.max(0, states.size() - 5); stateIndex < states.size(); ++stateIndex) {
                stateWindow.add(states.get(stateIndex));
            }
            currentState = (MedianAbsoluteDeviationFunctions.State) run("OUTLIER_MAD_STATE_MERGE(states, currentState)", ImmutableMap.of("states", stateWindow, "currentState", currentState));
        }
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)", ImmutableMap.of("currentState", currentState, "value", stats.getMin()));
        assertTrue(score > 3.5, "Score: " + score + " is not an outlier despite being a minimum.");
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)", ImmutableMap.of("currentState", currentState, "value", stats.getMax()));
        assertTrue(score > 3.5, "Score: " + score + " is not an outlier despite being a maximum");
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)", ImmutableMap.of("currentState", currentState, "value", stats.getMean() + 4 * stats.getStandardDeviation()));
        assertTrue(score > 3.5, "Score: " + score + " is not an outlier despite being 4 std deviations away from the mean");
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)", ImmutableMap.of("currentState", currentState, "value", stats.getMean() - 4 * stats.getStandardDeviation()));
        assertTrue(score > 3.5, "Score: " + score + " is not an outlier despite being 4 std deviations away from the mean");
    }
    {
        Double score = (Double) run("OUTLIER_MAD_SCORE(currentState, value)", ImmutableMap.of("currentState", currentState, "value", stats.getMean()));
        assertFalse(score > 3.5, "Score: " + score + " is an outlier despite being the mean");
    }
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) GaussianRandomGenerator(org.apache.commons.math3.random.GaussianRandomGenerator) ArrayList(java.util.ArrayList) MersenneTwister(org.apache.commons.math3.random.MersenneTwister) Test(org.junit.jupiter.api.Test)

Aggregations

ArrayList (java.util.ArrayList)14 WeightedObservedPoint (org.apache.commons.math3.fitting.WeightedObservedPoint)12 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)10 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)8 Plot (ij.gui.Plot)8 List (java.util.List)8 TooManyEvaluationsException (org.apache.commons.math3.exception.TooManyEvaluationsException)8 PointValuePair (org.apache.commons.math3.optim.PointValuePair)8 GaussianRandomGenerator (org.apache.commons.math3.random.GaussianRandomGenerator)8 MersenneTwister (org.apache.commons.math3.random.MersenneTwister)8 RandomGenerator (org.apache.commons.math3.random.RandomGenerator)8 Test (org.junit.jupiter.api.Test)8 ImagePlus (ij.ImagePlus)6 DataException (uk.ac.sussex.gdsc.core.data.DataException)6 ExtendedGenericDialog (uk.ac.sussex.gdsc.core.ij.gui.ExtendedGenericDialog)6 IJ (ij.IJ)5 WindowManager (ij.WindowManager)5 GenericDialog (ij.gui.GenericDialog)5 PlugIn (ij.plugin.PlugIn)5 MaxEval (org.apache.commons.math3.optim.MaxEval)5