From 842a45b33178bb51df4ac1651876dffaee7044f6 Mon Sep 17 00:00:00 2001 From: Nathanael Farley Date: Thu, 24 Aug 2017 12:33:07 +0100 Subject: [PATCH] Added method error_contribution_from. The function error_contribution_from allows developers to discover the complete contribution from a set of tags specified by a predicate function. --- uncertainties/core.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/uncertainties/core.py b/uncertainties/core.py index 314c1f5a..d37df721 100644 --- a/uncertainties/core.py +++ b/uncertainties/core.py @@ -1755,6 +1755,24 @@ def error_components(self): return error_components + def error_contribution_from(self, filter_tag): + """ + Provides contribution from given error components. + + Provides the error contribution from error components for + which filter_tag(tag) returns True. + """ + + errors_that_contribute = [] + for variable, derivative in self.error_components().iteritems(): + if filter_tag(variable.tag): + errors_that_contribute.append(derivative**2) + + # Since error components already does the heavy lifting of separating + # errors into a linear combination, we select only the ones we are + # interested in. + return sqrt(sum(errors_that_contribute)) + @property def std_dev(self): """