StochasticAD.jl icon indicating copy to clipboard operation
StochasticAD.jl copied to clipboard

`propagate` to add two stochastic triples together

Open GuusAvis opened this issue 8 months ago • 5 comments

Hello!

I'm trying to use the propagate function to extract derivatives from some Monte Carlo simulations. However, I noticed that the function does not behave as I would expect in even some simple use cases. A minimal example is given by simply adding two stochastic triples together:

using StochasticAD

function add(x::Real, y)
    x + y
end

function add(x::StochasticAD.StochasticTriple, y)
    StochasticAD.propagate(add, x, y; keep_deltas=true)
end

# x = 1
x = stochastic_triple(1)
y = stochastic_triple(5)

add(x, y)  # 6 + 0ϵ
x + y  # 6 + 2ϵ
add(x, y) == x + y  # false

I expected that propagate would automatically ensure that this simple function would correctly propagate the perturbations but this does not seem to be the case. Am I doing something wrong or is this a bug?

Thanks!

GuusAvis avatar Jun 06 '24 20:06 GuusAvis