Skip to content

propagate to add two stochastic triples together #125

@GuusAvis

Description

@GuusAvis

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions