JuliaMath / MeasureTheory.jl

"Distributions" that might not add to one.
MIT License
386 stars 32 forks source link

sum of random variable and deterministic value? #251

Closed slwu89 closed 1 year ago

slwu89 commented 1 year ago

Hi, I'm curious if its possible to do something like the following (not valid code):

10 + Binomial(10, 0.5)

to get a measure assigning probability to the values between 10 and 20. I naively did Binomial(10, 0.5) + Dirac(10) but that generates a mixture/superposition.

Incidentally, the interest in this arose from using Chain to implement a time discretization of a competing counting processes representation of an SIR model. It would be nice if the state of the chain could be defined on the 2 increasing integers counting the total number of times each event has fired, right now it's simply defined on the number of events occurring each time step. The relevant code is here: https://github.com/epirecipes/sir-julia/blob/master/markdown/markov_measure/markov_measure.md#transitions (i.e. I wish I could write productmeasure([x[1] + si_rv, x[2] + ir_rv]) at the last line.

slwu89 commented 1 year ago

Ah, it's in the AffineTransform part of the API. I missed this when I was looking through the docs, closing!

slwu89 commented 1 year ago

If anyone else needs this in the future, it is done as something like:

f = AffineTransform((μ=10,))
rand(pushfwd(f, Binomial(10,0.5)))