Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fill diagonal elements of error_matrix from gradient estimators #85

Merged
merged 1 commit into from
May 29, 2023

Conversation

r-imai-quantum
Copy link
Contributor

In the current implementation, gradient estimators do not return error_matrix.
This PR contains changes that make estimators return a matrix where the diagonal elements are filled with its error.
Note that non-diagonal elements are filled with zeros without calculation.

@r-imai-quantum r-imai-quantum force-pushed the error-matirx-gradient-estimator branch 2 times, most recently from 74237b9 to 2b1f55f Compare May 18, 2023 07:56
Comment on lines 86 to 89
var = (
(estimates[2 * i].error ** 2) + (estimates[2 * i + 1].error ** 2)
) / delta
err_diag.append(np.sqrt(var))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be $\sqrt{(e_1^2+e_2^2)/\delta}$, but isn't $\sqrt{(e_1^2+e_2^2)}/\delta$ correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing this out!
I misremembered the propagation rule of error.
The latter one is correct.

@@ -62,7 +64,7 @@ def numerical_gradient_estimates(
Returns:
The estimated values (can be accessed with :attr:`.values`) with errors
of estimation (can be accessed with :attr:`.error_matrix`). Currently,
:attr:`.error_matrix` returns `None`.
non-diagonal elements of :attr:`.error_matrix` are filled with zeros.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saying "are filled with zeros" sounds to me like "we don't know the exact values but we put zeros at the moment", but I guess the covariances are exactly zero in this case since each element is estimated indepedently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit confused but, as you guessed, the covariance are exactly zero.
So I've removed the sentence.

for p, c in params_and_coefs:
g += estimates_dict[p].value * c
var += (estimates_dict[p].error ** 2) * abs(c)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess $|c|$ should also be squared:

Suggested change
var += (estimates_dict[p].error ** 2) * abs(c)
var += (estimates_dict[p].error ** 2) * abs(c) ** 2

@r-imai-quantum r-imai-quantum force-pushed the error-matirx-gradient-estimator branch from 2b1f55f to e4d3868 Compare May 29, 2023 08:23
@kwkbtr kwkbtr merged commit ecc6553 into QunaSys:main May 29, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 29, 2023
@r-imai-quantum
Copy link
Contributor Author

@kwkbtr
Thank you for reviewing!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants