OxfordIonTrapGroup / oitg

Python package of helper routines (result loading, fitting, etc) for the Oxford Ion-Trap Group (OITG).
https://oxfordiontrapgroup.github.io/oitg/
13 stars 9 forks source link

threshold: find optimal readout threshold and bin time #13

Closed pathfinder49 closed 5 years ago

pathfinder49 commented 5 years ago

Assumes Poisson distributed bright and dark state. Implents two ways of calculating larger poisson distribution. These allow accurate calculation of poisson probabilaties for n>10. A naive implementation of P(n) breakes down at n=10.

dnadlinger commented 5 years ago

Surely there is a suitable function already available somewhere (scipy.stats.poisson.pmf maybe)?

If not, to avoid issues with numerical precision without having to resort to numerical integration, you might want to calculate the logarithm of the PMF (using gammaln, xlog1py, etc.) and then only exponentiate if needed (which isn't the case for a maximum-likelihood fit).

dnadlinger commented 5 years ago

Also, note that for small errors, our readout schemes are not well-described by a sum of two Poissonians because of the limited shelf lifetime, so the usefulness of the extra precision afforded by p_bright/… is limited.

(Edit: In particular, this, depending on the system collection efficiency and 854/850 leakage, tends to bias the optimal collection time quite significantly towards shorter times.)

dnadlinger commented 5 years ago

See Alice Myerson (née Burrell)'s thesis for a discussion of time-resolved MLE methods, which you might also want to reference for the expression in calc_thresh_rate.

pathfinder49 commented 5 years ago

Surely there is a suitable function already available somewhere (scipy.stats.poisson.pmf maybe)?

If not, to avoid issues with numerical precision without having to resort to numerical integration, you might want to calculate the logarithm of the PMF (using gammaln, xlog1py, etc.) and then only exponentiate if needed (which isn't the case for a maximum-likelihood fit).

scipy.stats.poisson.pmf does what I need now. I originally thought I might want to integrate over the poisson distribution, which is why I cared about the non integer generalisation (scipy.stats.poisson.pmf returns zero for non integer n).

pathfinder49 commented 5 years ago

Also, note that for small errors, our readout schemes are not well-described by a sum of two Poissonians because of the limited shelf lifetime, so the usefulness of the extra precision afforded by p_bright/… is limited.

(Edit: In particular, this, depending on the system collection efficiency and 854/850 leakage, tends to bias the optimal collection time quite significantly towards shorter times.)

I'm aware of this, but thought this would be a good starting point. Lab3 will need this in future, though we're not worried about it yet.

pathfinder49 commented 5 years ago

See Alice Myerson (née Burrell)'s thesis for a discussion of time-resolved MLE methods, which you might also want to reference for the expression in calc_thresh_rate.

I'll take a look at it.

pathfinder49 commented 5 years ago

@dnadlinger are you happy for this to be merged?

dnadlinger commented 5 years ago

Sure (personally I think the usefulness is limited, but it's still good to have a documented place for that one threshold formula). Merged as 0dd1a86e8011419818db7bac0221b43658eaaebe without the Poisson reimplementation, as that currently isn't used by threshold. (What was the conclusion on the discrepancy you mentioned?)

dnadlinger commented 5 years ago

See also: https://github.com/OxfordIonTrapGroup/oitg/pull/18

dnadlinger commented 5 years ago

API docs now at: https://oxfordiontrapgroup.github.io/oitg/threshold.html

dnadlinger commented 5 years ago

Formatting could use some work – see https://oxfordiontrapgroup.github.io/oitg/circuits.html#module-oitg.circuits.protocols.gst for inspiration regarding how to make inline math work. I might get to this at some point later if you don't have time now.