lmfit / uncertainties

Transparent calculations with uncertainties on the quantities involved (aka "error propagation"); calculation of derivatives.
http://uncertainties.readthedocs.io/
Other
581 stars 74 forks source link

add complex numbers capabilties #82

Open rjrich opened 6 years ago

rjrich commented 6 years ago

It would be great if you could add the capability of using complex numbers in uncertainties. This is available in the Julia package, Measurements, but I would prefer to have this capability available in Python. Thank you for considering.

lebigot commented 6 years ago

This is something that would nicely fit within the current scope of the package: UComplex numbers with uncertainty could be added to the existing UFloat numbers. This has also been requested by a few people in the past.

I don't expect major difficulties (only some complications due to the interaction between floats and complex numbers with uncertainty), but this does requires more work than I can give right now (I am trying to release my second CD!).

That said, we can prepare the near future right now: do you have recommendations on what a good support for complex numbers would look like in uncertainties? I am thinking about how they should be created (especially if there are correlations between the real and imaginary parts) and how they should be displayed.

rjrich commented 6 years ago

Eric,

Thank you for your reply.

I think that incorporation of complex numbers could be patterned after the implementation in the GUM Tree Calculator from the New Zealand Measurements Standards Laboratory: http://www.measurement.govt.nz/resources/#collapse-control-3-1

Scroll down to the GTC link. After clicking the link, you need to enter your email address in order to download, but then download is immediate.

GTC is one of the few propagation of uncertainty programs that can handle complex numbers. It is based on Python, so I anticipate that it should be relatively straightforward to execute for a Python expert such as yourself. GTC is a Windows program, but I was able to run it in Linux by using Wine.

It might also be useful to add an option for including second-order terms in propagation of error. Second-order code is available in the R package "propagate" and the Python package "soerp", but I found these packages harder to use and more difficult to understand the output than was the case with your uncertainties package.

Thank you.

Rudy

lebigot commented 6 years ago

Unless I'm mistaken, the link is for downloading the GUM Tree Calculator for Windows. I do not have access to either Windows or Wine. So if you can point to some things about complex numbers and uncertainties that you like in the Calculator (or elsewhere), that could ultimately help have nicer features in the Uncertainties package (maybe things like: how to display of complex number with uncertainties, how to enter complex numbers with correlated uncertainties between the real and the imaginary part, etc.).

rjrich commented 6 years ago

Yes, this is correct. GTC is a Windows program, although it runs in Linux by using Wine.

An alternative is the "Measurements" package in Julia: https://github.com/JuliaPhysics/Measurements.jl Here is an example from the Julia documentation on handling of complex numbers: julia> u = complex(32.7 ± 1.1, -3.1 ± 0.2) julia> v = complex(7.6 ± 0.9, 53.2 ± 3.4) julia> 2u + v (73.0 ± 2.3769728648009427) + (47.0 ± 3.4234485537247377)im julia> sqrt(u * v) (33.004702573592 ± 1.0831254428098636) + (25.997507418428984 ± 1.1082833691607152)im

To answer your questions more fully, I will need to spend some time. This week and next are filled with other obligations. It might be a few weeks before I can get back to you with more information.

Thank you.

rjrich commented 6 years ago

Please find attached an excerpt from the GTC documentation on complex numbers. I hope this is helpful.

GTC_Complex_Numbers.txt