Comments (6)
Thank you! I am glad that my package is being put to good use!
Since your two kinds of errors are completely uncorrelated, you can simply do:
>>> from uncertainties import ufloat
>>> stat_error = ufloat((0, 0.1))
>>> syst_error = ufloat((0, 0.05))
>>> value = 1 + stat_error + syst_error
>>> print value
1.0+/-0.111803398875
or more concisely:
>>> value = ufloat((1, 0.1)) + ufloat((0, 0.05)) # Statistical measurement + systematic error
The main idea is that the errors are independent random variables with average value 0: you just create two independent random variables with ufloat()
.
Multiple measurements can even share the same statistical or systematic error, in which case their uncertainties will automatically be correlated by the uncertainties
package.
from uncertainties.
I'm going to interject here with some extra thoughts.
lebigot, you wrote that these errors are "independent random variables with average value 0" -- which I think is a key distinction from the situation that's being asked about here. Statistical error will be "independent random variables with average value of 0" -- while systematic errors are NOT, in general, correctly described in that way. Specifically, one of the nastier features is that they can have an average value != 0.
So, to address the initial question -- you are right to address them separately, as the correct way of handling any particular systematic error depends very much on the particulars of the situation. Although I don't have any clever ideas on how to handle this situation within the uncertainties
package.
from uncertainties.
True. I was just interpreting the initial post as meaning that there was a value 1 plus two errors centered in 0.
The uncertainties
package handles a systematic error which is not centered in zero by just giving it a non-zero nominal value:
>>> from uncertainties import ufloat
>>> stat_error = ufloat((0, 0.1))
>>> syst_error = ufloat((0.5, 0.05)) # Systematic error not centered in zero
>>> value = 1 + stat_error + syst_error
from uncertainties.
Ok,
my question was more how to propagate them keeping them separated. So that when adding, multiplying etc. two numbers i get the correct propagation for the two errors separately.
Talking to some colleagues I got the suggestion to do like this:
number1 = central_value1*ufloat((1,relative_stat_err),'stat_err')*ufloat((1,relative_sys_err),'sys_err')
…
…
result_central = result.nominal_value
result_stat = quad(
*[ j for i, j in result.error_components().iteritems() if 'stat' in i.tag]
)
result_sys = quad(
*[ j for i, j in result.error_components().iteritems() if 'sys' in i.tag]
)
where quad is a simple function to sum in quadrature
from uncertainties.
That's almost perfect. :) Note that it would be more robust and faster to have the non-systematic uncertainty be calculated as result_stat = math.sqrt(result.std_dev()**2 - result_sys**2)
, so that you are guaranteed to never miss any uncertainty contribution: otherwise, the code might be updated one day with tags that do not fall in the 'stat'/'sys' dichotomy (maybe one of the variables will have no tag) and the corresponding uncertainties might be forgotten.
This is a very good use of the tag
optional argument to ufloat()
!
PS: I added details in the documentation about the possibility of using the same tag for different variables. Thank you for your input! Here is the page: http://pythonhosted.org/uncertainties/user_guide.html#access-to-the-individual-sources-of-uncertainty
from uncertainties.
That is a very slick implementation! I suspect I'll be using this in the very near future myself.
from uncertainties.
Related Issues (20)
- Type Annotation Checker Problems with UFloat HOT 6
- uncompatibility with Python3.12 HOT 4
- package maintanence HOT 65
- [3.1.7] SyntaxWarning: invalid escape sequence '\<something>' with Python 3.12 HOT 2
- Unintuitive class behaviour HOT 1
- Pandas sort_values with multiple columns does not work for AffineScalarFunc HOT 1
- Add uploading code coverage to codecov to github action HOT 3
- code coverage not uploading for master branch HOT 6
- Lacks basic VSCode settings for running pytest tests with VSCode. HOT 6
- Replace documentation references from nose unit tests to pytest unit tests.
- Remove unused imports in tests. HOT 1
- Add CITATION.cff file HOT 6
- Changelog maintenance plan HOT 2
- Review numpy API coverage
- `tests/helpers.py` is missing in 3.2.0 PyPI sdist HOT 2
- Import error in autopkgtests -missing unumpy HOT 1
- readthedocs docs not building HOT 6
- Trailing decimal symbol test failing HOT 3
- Strange behavior on copying
- Rewriting to remove monkey patching ? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from uncertainties.