smith-garrett / Uniformization.jl

A Julia package for solving continuous-time Markov chains using the uniformization/randomization method
MIT License
0 stars 0 forks source link

Make tests for automatic differentiation #21

Open smith-garrett opened 1 year ago

smith-garrett commented 1 year ago

Partially covered by #19 with Dual types, but probably need more. Look at tests for ExponentialAction for inspiration.

smith-garrett commented 1 year ago

Removing the dependence of uniformization() on the type TransitionRateMatrix seems to make AD with Forward/ReverseDiff.jl possible. Tests still needed.

smith-garrett commented 1 year ago

Trying to fit parameters with Turing, got an error about trying to convert a Float to a dual number. Seems to be coming from the call to uniformization(), so there might be a problem/type instability somewhere in there. This error itself should become a test.

Error:

MethodError: no method matching Float64(::ForwardDiff.Dual{ForwardDiff.Tag{Turing.TuringTag, Float64}, Float64, 6})

Line that caused the error:

pvec = fill(Categorical(p0), length(data))
pvec[2:end] = [Categorical(uniformize(T, probs(pvec[i-1]), 2^8, i * 0.001)) for i in 2:length(data)]