GithubHelp home page GithubHelp logo

Dealing with correlations about uncertainties HOT 3 CLOSED

lmfit avatar lmfit commented on August 23, 2024
Dealing with correlations

from uncertainties.

Comments (3)

apuignav avatar apuignav commented on August 23, 2024

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.

apuignav avatar apuignav commented on August 23, 2024

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.

lebigot avatar lebigot commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.