2016-06-16 10:12 GMT+02:00 Mosè Giordano: > Hi all, > > an update: I continued the development of this package, you can have a look > at the available features here: > https://github.com/giordano/Measurements.jl#features-list > > In addition, I implemented support for correlation between variables, so > that x - x == zero(x), x/x == one(x), tan(x) == sin(x)/cos(x), and so on. > This is done in "correlation" branch, but currently performance is less than > suboptimal. According to @benchmark, a simple operation like addition > between two independent (uncorrelated) variables takes ~ 20 µs, against the > ~15 ns required by the implementation in "master" branch (without support > for correlation). > > You can see how the Measurement type is defined and constructed here: > https://github.com/giordano/Measurements.jl/blob/1fddcc848c807d3fb96b9b724c1039359597c14d/src/Measurements.jl#L31-L57 > In order to handle correlation between variables, I keep in each Measurement > object a list of all independent variables from which it's derived in the > form of a dictionary. Here you can see how this list is used to compute the > final uncertainty: > https://github.com/giordano/Measurements.jl/blob/1fddcc848c807d3fb96b9b724c1039359597c14d/src/math.jl#L26-L95 > The most relevant function is the second one, which is related to > mathematical operations with two or more operands, so the cases where > correlation may occur. This is all you need to understand how all this > works. > > Do you have suggestions on how to improve the performance? I feel that > dictionary is a very handy type but it isn't particularly efficient in this > case, only *creating* a Measurement object takes ~2 ns in "master" branch, > and ~800 ns in "correlation" branch and Julia 0.4.5 (it's something less in > Julia 0.5, but always of the order of hundreds of nanoseconds); source: > @benchmark 3.0 ± 1.0. I was thinking of creating a new type for handling > the list of derivatives of independent variables, but how this could be > defined in order to make it efficient?
Never mind, I sorted this out by myself. By digging into Julia's source code I found the Base.ImmutableDict type (by the way: why is this type not exported nor documented?), that is a lightweight, immutable dictionary, exactly what I was looking for. Now, thanks to the use of this type instead of Dict (and the reorganization of a loop in order to avoid memory allocations) the addition of two independent and uncorrelated variables takes just ~500 ns, this is a 40x improvement with respect to the use of Dict. Bye, Mosè
