Search in sources :

Example 1 with PoissonGaussianLikelihoodWrapper

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

the class MaximumLikelihoodFitter method createLikelihoodWrapper.

private LikelihoodWrapper createLikelihoodWrapper(NonLinearFunction f, 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(f, 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(f, a, y, n, myAlpha, sigma);
                break;
            }
        case POISSON:
        default:
    }
    // 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];
        }
        PoissonLikelihoodWrapper function = new PoissonLikelihoodWrapper(f, a, y2, n, myAlpha);
        // This will allow Powell searches. The effect on the gradient search algorithms may be weird so leave alone.
        if (!searchMethod.usesGradient)
            function.setAllowNegativeExpectedValues(true);
        maximumLikelihoodFunction = function;
    }
    return maximumLikelihoodFunction;
}
Also used : PoissonGammaGaussianLikelihoodWrapper(gdsc.smlm.function.PoissonGammaGaussianLikelihoodWrapper) PoissonGaussianLikelihoodWrapper(gdsc.smlm.function.PoissonGaussianLikelihoodWrapper) PoissonLikelihoodWrapper(gdsc.smlm.function.PoissonLikelihoodWrapper) PoissonGammaGaussianLikelihoodWrapper(gdsc.smlm.function.PoissonGammaGaussianLikelihoodWrapper) PoissonGaussianLikelihoodWrapper(gdsc.smlm.function.PoissonGaussianLikelihoodWrapper) PoissonLikelihoodWrapper(gdsc.smlm.function.PoissonLikelihoodWrapper) LikelihoodWrapper(gdsc.smlm.function.LikelihoodWrapper)

Aggregations

LikelihoodWrapper (gdsc.smlm.function.LikelihoodWrapper)1 PoissonGammaGaussianLikelihoodWrapper (gdsc.smlm.function.PoissonGammaGaussianLikelihoodWrapper)1 PoissonGaussianLikelihoodWrapper (gdsc.smlm.function.PoissonGaussianLikelihoodWrapper)1 PoissonLikelihoodWrapper (gdsc.smlm.function.PoissonLikelihoodWrapper)1