Lots of code reuse between solvers, and between adjoint SDEs
See original GitHub issueTo be clear, not raising this because I feel like being nitpicky - read on!
Other than very minor differences (e.g. order), the code for each Euler–Maruyama/Milstein/SRK method is essentially the same across noise types. Instead one can have e.g. a single Euler
that accepts order
as an argument, and four different wrappers that set that argument.
Similarly, the adjoint SDE definitions have lots of code reuse; it’d easier to write down a single adjoint SDE for the general noise case. (And any unnecessary computation can be masked out with if statements checking the noise type.)
I think the latter in particular offers an easy opportunity to unify Ito and Stratonovich: it’d just be another if statement checking if the correction term should be applied.
As for why I’m raising this - I’m interested in:
- Defining custom SDE solvers.
- Solving the adjoint SDE with
general
noise. (And I’m happy to do so with Euler–Maruyama, knowing the strong order is 0.5. It should still work, right?) - Solving Stratonovich SDEs.
The first is aided by tidying up the existing code for solvers (I don’t want to define MyCustomSolverAdditive
, MyCustomSolverGeneral
,…), the second is made possible by improving the adjoint SDE, and the third is a stretch goal that’ll probably be easier if it can just be implemented with if sde_type=
corrections in the right places.
Tidying up the solvers at least is probably something I can offer a PR on, but I wanted to check if this fit your general vision, or if you think there’s anything that might go wrong, as it pretty much involves removing the whole methods
directory structure.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
@mtsokol Hello there. So I’m not completely sure that I’m the one you should be asking - this is really @lxuechen’s repository, not mine!
That said - we’re currently in the process of rewriting large portions of the internals - see the dev branch. In particular we should now have support for Stratonovich SDEs via the midpoint method, so you could look at formatting your work on Heun’s method in the same manner, and then submit a PR there?
Glancing at what you’ve already done so far - I see you’ve done a diagonal-only version of Heun’s method. I think this should be applicable to any noise type, so you could also look at generalising that (again, c.f. how midpoint is implemented).
@patrick-kidger Hi! I’ve recently started learning this repository and while implementing Heun’s method in #4 I’ve also noticed some parts where logic can be unified to avoid some duplication, especially right now in the process of introducing support for Stratonovich. I’d love to continue contributing, I’ve tried to follow up with your discussion in #15 regarding this general refactor - If you have spare task that I could try please let me know.