Search in sources :

Example 1 with PoissonGaussianLikelihoodWrapper

use of uk.ac.sussex.gdsc.smlm.function.PoissonGaussianLikelihoodWrapper in project GDSC-SMLM by aherbert.

the class MaximumLikelihoodFitter method createLikelihoodWrapper.

private LikelihoodWrapper createLikelihoodWrapper(NonLinearFunction function, int n, double[] y, double[] a) {
    LikelihoodWrapper maximumLikelihoodFunction = null;
    final double myAlpha = (this.alpha > 0) ? this.alpha : 1;
    // We can use different likelihood wrapper functions:
    switch(likelihoodFunction) {
        case POISSON_GAMMA_GAUSSIAN:
            // Poisson-Gamma-Gaussian - EM-CCD data
            maximumLikelihoodFunction = new PoissonGammaGaussianLikelihoodWrapper(function, a, y, n, myAlpha, sigma);
            break;
        case POISSON_GAUSSIAN:
            // Sigma must be positive, otherwise fall back to a Poisson likelihood function
            if (sigma > 0) {
                maximumLikelihoodFunction = new PoissonGaussianLikelihoodWrapper(function, a, y, n, myAlpha, sigma);
            }
            break;
        default:
            // Poisson - most counting data
            break;
    }
    // Check if the method requires the gradient but it cannot be computed
    if (maximumLikelihoodFunction == null || (searchMethod.usesGradient && !maximumLikelihoodFunction.canComputeGradient())) {
        // Ensure no negative data for the Poisson likelihood method.
        // Just truncate the counts for now. These are from noise in the count estimates that we do
        // not model.
        final double[] y2 = new double[n];
        for (int i = 0; i < n; i++) {
            if (y[i] < 0) {
                y2[i] = 0;
            } else {
                y2[i] = y[i];
            }
        }
        final PoissonLikelihoodWrapper mlFunction = new PoissonLikelihoodWrapper(function, a, y2, n, myAlpha);
        // so leave alone.
        if (!searchMethod.usesGradient) {
            mlFunction.setAllowNegativeExpectedValues(true);
        }
        maximumLikelihoodFunction = mlFunction;
    }
    return maximumLikelihoodFunction;
}
Also used : PoissonGammaGaussianLikelihoodWrapper(uk.ac.sussex.gdsc.smlm.function.PoissonGammaGaussianLikelihoodWrapper) PoissonGaussianLikelihoodWrapper(uk.ac.sussex.gdsc.smlm.function.PoissonGaussianLikelihoodWrapper) PoissonLikelihoodWrapper(uk.ac.sussex.gdsc.smlm.function.PoissonLikelihoodWrapper) LikelihoodWrapper(uk.ac.sussex.gdsc.smlm.function.LikelihoodWrapper) PoissonLikelihoodWrapper(uk.ac.sussex.gdsc.smlm.function.PoissonLikelihoodWrapper) PoissonGammaGaussianLikelihoodWrapper(uk.ac.sussex.gdsc.smlm.function.PoissonGammaGaussianLikelihoodWrapper) PoissonGaussianLikelihoodWrapper(uk.ac.sussex.gdsc.smlm.function.PoissonGaussianLikelihoodWrapper)

Aggregations

LikelihoodWrapper (uk.ac.sussex.gdsc.smlm.function.LikelihoodWrapper)1 PoissonGammaGaussianLikelihoodWrapper (uk.ac.sussex.gdsc.smlm.function.PoissonGammaGaussianLikelihoodWrapper)1 PoissonGaussianLikelihoodWrapper (uk.ac.sussex.gdsc.smlm.function.PoissonGaussianLikelihoodWrapper)1 PoissonLikelihoodWrapper (uk.ac.sussex.gdsc.smlm.function.PoissonLikelihoodWrapper)1