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

update and improve error_budget_pie function #249

Merged
merged 3 commits into from
Jan 5, 2024

Conversation

peterstangl
Copy link
Collaborator

Previously, the error_budget_pie function was representing the individual errors as fractions of a linearly summed total error. Such a representation can be rather misleading since the actual total error corresponds to the individual errors summed in quadrature, not linearly.

This PR updates the error_budget_pie function to improve the visual representation of the individual error contributions. In the new version

  • the wedges are labelled with the actual relative error contributions (not as the fractions of the linearly summed total error as before),
  • the area of each wedge is proportional to the squared error contribution such that the total area of the pie corresponds to the actual squared total error.

So the new version gives an accurate graphical representation of the individual errors summed in quadrature and the sizes of the wedges have an intuitive interpretation in terms of the individual variance contributions that can be summed linearly. Furthermore, the numbers on the labels now exactly correspond to the results of flavio.sm_error_budget, also when small contributions are grouped together under "other" (this was not the case before since "other" always corresponded to small errors summed in quadrature), and summing all the numbers on the labels in quadrature now exactly yields the actual total error.

"""
err_tot = sum(err_dict.values()) # linear sum of individual errors
var_tot = np.sum(np.array(list(err_dict.values()))**2) # total variance from sum of squared individual errors
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not np.array(err_dict.values())? Perhaps even sum(v**2 for v in err_dict.values())?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

err_dict.values() is a dict_values object and np.array(err_dict.values()) is an array with dtype=object containing a single element. So for using numpy, one needs to convert the dict_values into a list first. But it's true that in this case, maybe using numpy is not the best option and the simple sum(v**2 for v in err_dict.values()) might be more clear. And it is actually faster than the numpy version.

@peterstangl peterstangl merged commit 1276360 into flav-io:master Jan 5, 2024
4 checks passed
@peterstangl peterstangl deleted the error_pie branch January 5, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants