Search in sources :

Example 1 with InterpolatedPoissonFisherInformation

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

the class CameraModelFisherInformationAnalysis method loadFunction.

/**
 * Load the Poisson Fisher information for the camera type from the cache.
 *
 * @param type the type
 * @param gain the gain
 * @param noise the noise
 * @param relativeError the relative error (used to compare the gain and noise)
 * @return the poisson fisher information (or null)
 */
public static InterpolatedPoissonFisherInformation loadFunction(CameraType type, double gain, double noise, double relativeError) {
    if (type == null || type.isFast()) {
        return null;
    }
    final FiKey key = new FiKey(type, gain, noise);
    PoissonFisherInformationData data = load(key);
    if (data == null && relativeError > 0 && relativeError < 0.1) {
        // Fuzzy matching
        double error = 1;
        for (final PoissonFisherInformationData d : cache.values()) {
            final double e1 = DoubleEquality.relativeError(gain, d.getGain());
            if (e1 < relativeError) {
                final double e2 = DoubleEquality.relativeError(noise, d.getNoise());
                if (e2 < relativeError) {
                    // Combined error - Euclidean distance
                    final double e = e1 * e1 + e2 * e2;
                    if (error > e) {
                        error = e;
                        data = d;
                    }
                }
            }
        }
    }
    if (data == null) {
        return null;
    }
    // Dump the samples. Convert to base e.
    final double scale = Math.log(10);
    final TDoubleArrayList meanList = new TDoubleArrayList(data.getAlphaSampleCount());
    final TDoubleArrayList alphalist = new TDoubleArrayList(data.getAlphaSampleCount());
    for (final AlphaSample sample : data.getAlphaSampleList()) {
        meanList.add(sample.getLog10Mean() * scale);
        alphalist.add(sample.getAlpha());
    }
    final double[] means = meanList.toArray();
    final double[] alphas = alphalist.toArray();
    SortUtils.sortData(alphas, means, true, false);
    final BasePoissonFisherInformation upperf = (type == CameraType.EM_CCD) ? new HalfPoissonFisherInformation() : createPoissonGaussianApproximationFisherInformation(noise / gain);
    return new InterpolatedPoissonFisherInformation(means, alphas, type.isLowerFixedI(), upperf);
}
Also used : TDoubleArrayList(gnu.trove.list.array.TDoubleArrayList) BasePoissonFisherInformation(uk.ac.sussex.gdsc.smlm.function.BasePoissonFisherInformation) AlphaSample(uk.ac.sussex.gdsc.smlm.data.config.FisherProtos.AlphaSample) InterpolatedPoissonFisherInformation(uk.ac.sussex.gdsc.smlm.function.InterpolatedPoissonFisherInformation) PoissonFisherInformationData(uk.ac.sussex.gdsc.smlm.data.config.FisherProtos.PoissonFisherInformationData) HalfPoissonFisherInformation(uk.ac.sussex.gdsc.smlm.function.HalfPoissonFisherInformation)

Example 2 with InterpolatedPoissonFisherInformation

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

the class CreateData method createLikelihoodFunction.

/**
 * Creates the likelihood function. This is used for CRLB computation.
 */
private void createLikelihoodFunction() {
    final CameraType cameraType = settings.getCameraType();
    final boolean isCcd = CalibrationProtosHelper.isCcdCameraType(cameraType);
    fiFunction = new BasePoissonFisherInformation[settings.getSize() * settings.getSize()];
    if (isCcd) {
        BasePoissonFisherInformation fi;
        final CreateDataSettingsHelper helper = new CreateDataSettingsHelper(settings);
        final double readNoise = helper.getReadNoiseInCounts();
        if (cameraType == CameraType.EMCCD) {
            // We only want the amplification (without QE applied)
            final double amp = helper.getAmplification();
            // This should be interpolated from a stored curve
            final InterpolatedPoissonFisherInformation i = CameraModelFisherInformationAnalysis.loadFunction(CameraModelFisherInformationAnalysis.CameraType.EM_CCD, amp, readNoise);
            if (i == null) {
                throw new IllegalStateException("No stored Fisher information for EM-CCD camera with gain " + amp + " and noise " + readNoise + "\n \nPlease generate using the " + CameraModelFisherInformationAnalysis.TITLE);
            }
            fi = i;
        } else {
            // This is fast enough to compute dynamically.
            // Read noise is in electrons so use directly.
            fi = new PoissonGaussianFisherInformation(settings.getReadNoise());
        }
        Arrays.fill(fiFunction, fi);
    } else if (cameraType == CameraType.SCMOS) {
        // Build per-pixel likelihood function.
        // Get the normalised variance per pixel.
        final float[] v = cameraModel.getNormalisedVariance(cameraModel.getBounds());
        // Build the function
        for (int i = 0; i < fiFunction.length; i++) {
            fiFunction[i] = new PoissonGaussianFisherInformation(Math.sqrt(v[i]));
        }
    } else {
        throw new IllegalArgumentException("Unsupported camera type: " + CalibrationProtosHelper.getName(cameraType));
    }
}
Also used : CreateDataSettingsHelper(uk.ac.sussex.gdsc.smlm.ij.settings.CreateDataSettingsHelper) BasePoissonFisherInformation(uk.ac.sussex.gdsc.smlm.function.BasePoissonFisherInformation) PoissonGaussianFisherInformation(uk.ac.sussex.gdsc.smlm.function.PoissonGaussianFisherInformation) CameraType(uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType) InterpolatedPoissonFisherInformation(uk.ac.sussex.gdsc.smlm.function.InterpolatedPoissonFisherInformation)

Aggregations

BasePoissonFisherInformation (uk.ac.sussex.gdsc.smlm.function.BasePoissonFisherInformation)2 InterpolatedPoissonFisherInformation (uk.ac.sussex.gdsc.smlm.function.InterpolatedPoissonFisherInformation)2 TDoubleArrayList (gnu.trove.list.array.TDoubleArrayList)1 CameraType (uk.ac.sussex.gdsc.smlm.data.config.CalibrationProtos.CameraType)1 AlphaSample (uk.ac.sussex.gdsc.smlm.data.config.FisherProtos.AlphaSample)1 PoissonFisherInformationData (uk.ac.sussex.gdsc.smlm.data.config.FisherProtos.PoissonFisherInformationData)1 HalfPoissonFisherInformation (uk.ac.sussex.gdsc.smlm.function.HalfPoissonFisherInformation)1 PoissonGaussianFisherInformation (uk.ac.sussex.gdsc.smlm.function.PoissonGaussianFisherInformation)1 CreateDataSettingsHelper (uk.ac.sussex.gdsc.smlm.ij.settings.CreateDataSettingsHelper)1