Comments (3)
Ciao Mauro,
I think this is not working because you're using relative errors, and therefore saying that one error has a larger impact breaks the 100% correlation. I think you may need to use a summed error
Therefore, for the second consideration, you probably need to use absolute errors (this is a simple example, but I think it may be the proper way to attack the problem):
>>> sys = ufloat(0.0, 0.2)
>>> val_y = 10
>>> y = ufloat(val_y, 0.0) + val_y * sys
>>> val_z = 10
>>> z = ufloat(val_z, 0.0) + val_z * sys * 2 # Two times larger
>>> y + z
20.0+/-0.6
Or something like this...
Albert
from uncertainties.
Sorry, I forgot the x part
>>> val_x = 5
>>> x = ufloat(val_x, 0.0) + val_x * sys
>>> x + y
15.0+/-0.3
>>> x/y
0.5+/-0
>>> y/x
2.0+/-0
Albert
from uncertainties.
Mauro, the behavior that you observe is perfectly correct, since each number created with ufloat()
is an independent random variable (I updated https://pythonhosted.org/uncertainties/user_guide.html#creating-numbers-with-uncertainties so as to make this clearer).
Albert's approach is a good idea: since you need a single independent variable, there should be a single ufloat()
with a non-zero uncertainty. Albert's solution can be made simpler, though: there is no need to use ufloat(val_x, 0.0)
, as it can be written directly as val_x
.
If I were to code what you want, I would do:
>>> from uncertainties import ufloat
>>> percent_error = ufloat(0, 0.01) # Error of 1 percentage point
>>> x = 5*(1+2*percent_error) # 2 % error
>>> x
5.0+/-0.1
>>> y = 10*(1+2*percent_error) # 2 % correlated error
>>> y/x
2.0+/-0
>>> x+y
15.0+/-0.3
>>> z = 10*(1+4*percent_error) # 4 % correlated error
>>> y+z
20.0+/-0.6
In general, you can create correlated random variables with the correlated_values()
function (http://pythonhosted.org/uncertainties/user_guide.html#index-9).
from uncertainties.
Related Issues (20)
- TypeError: can't convert an affine function (<class 'uncertainties.core.AffineScalarFunc'>) to float; use x.nominal_value HOT 2
- 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
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.