Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Add better explanation comments for the QV fitter module #481

Closed
HuangJunye opened this issue Aug 24, 2020 · 2 comments
Closed

Add better explanation comments for the QV fitter module #481

HuangJunye opened this issue Aug 24, 2020 · 2 comments
Labels
documentation Something is not clear or error in description

Comments

@HuangJunye
Copy link
Contributor

While attempting to solve issue #473, I try to read and understand the code in QV fitter module. I find the code difficult to understand. It assumes very good level of understanding of statistics.

For example, when calculating the confidence level, the equation cfd = 0.5 * (1 + math.erf((hmean - 2/3)/ (1e-10 + self._ydata[1][depth_ind])/2**0.5)) come out from nowhere. It should be great to add some comments to explain why the confidence level can be calculated using the equation. (see this comment #473 (comment))

Another example is in the calc_statistics method. In lines 243-250:

self._ydata[0][depthidx] = np.sum(exp_vals)/np.sum(exp_shots)
self._ydata[1][depthidx] = (self._ydata[0][depthidx] *
                                        (1.0-self._ydata[0][depthidx])
                                        / self._ntrials)**0.5
self._ydata[2][depthidx] = np.mean(ideal_vals)
self._ydata[3][depthidx] = (self._ydata[2][depthidx] *
                                        (1.0-self._ydata[2][depthidx])
                                        / self._ntrials)**0.5

It's not clear what each line does. If I understand it correctly, the first line self._ydata[0][depthidx] calculates hmean, the second line self._ydata[1][depthidx] calculates the standard deviation sigma, the third line self._ydata[2][depthidx] calculates the ideal hmean and the fourth line self._ydata[3][depthidx] calculate the ideal standard deviation sigma.

I don't understand how we can calculate sigma using only mean and ntrials:

self._ydata[1][depthidx] = (self._ydata[0][depthidx] *
                                        (1.0-self._ydata[0][depthidx])
                                        / self._ntrials)**0.5

image
($$\sigma = \sqrt{(\mu * (1-\mu))/n}$$). Is there any reference I can read to understand that?

@HuangJunye HuangJunye added the documentation Something is not clear or error in description label Aug 24, 2020
@HuangJunye
Copy link
Contributor Author

HuangJunye commented Aug 26, 2020

The equation for calculating standard deviation is based on the assumption of binomial distribution. Variance is npq or np(1-p). Success probability p in QV measurement is self._ydata[0][depthidx]/self._ntrials. Square root of np(1-p) gives the equation in the code.

@HuangJunye
Copy link
Contributor Author

Closed by #482

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Something is not clear or error in description
Projects
None yet
Development

No branches or pull requests

1 participant