francescoalemanno / KissABC.jl

Pure julia implementation of Multiple Affine Invariant Sampling for efficient Approximate Bayesian Computation
MIT License
29 stars 8 forks source link

Possible to combine simulate and loss functions? #10

Closed pcjentsch closed 4 years ago

pcjentsch commented 4 years ago

Hi,

Thanks for the great package. Is it possible to create an interface that combines the simulate and distance functions into one function that is evaluating at inputs and returns real numbers? Is there a workaround I can use for this?

My loss function is quite complex and separating the simulation from the distance, while possible, just makes my code more complex.

Before the most recent patch, I was able to work around this as the distance always used the second argument for tdata, but that seems to have changed.

Thanks!

francescoalemanno commented 4 years ago

edited:

This issue can be worked around :) you can use this function in your code:

function ABCplan(prior,costfunction;params=())
    fakedist(x,y)=x+y
    ABCplan(prior, costfunction, 0.0, fakedist; params=params)
end

example:

prior = Normal(0,1)
sim(x,other) = abs(x-1.5) #it returns a distance value
plan=ABCplan(prior, sim)
@show mean(ABCDE(plan,0.01,verbose=false)[1])
# mean((ABCDE(plan, 0.01, verbose = false))[1]) = 1.4993631135745822
francescoalemanno commented 4 years ago

as soon as the whole code stabilizes, i will maybe incorporate a function similar to that one inside the package, for now i added a test to make sure i don't accidentally prevent a use of my package via distance values only :)

pcjentsch commented 4 years ago

thank you!