Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoiseProcess type hierarchy #209

Open
oameye opened this issue Oct 28, 2024 · 4 comments
Open

NoiseProcess type hierarchy #209

oameye opened this issue Oct 28, 2024 · 4 comments

Comments

@oameye
Copy link
Contributor

oameye commented Oct 28, 2024

To implement when which algorithm is compatible with which noise type we need to distinguish between them after creation. Would it be sensibele to make a type system on top of NoiseProcess? The CamelCase names seems already to suggest that we should think of them this way.

SciML/SciMLBase.jl#774

@ChrisRackauckas
Copy link
Member

It would be fine to add one if you have a sensible breakdown you're interested in.

@oameye
Copy link
Contributor Author

oameye commented Oct 28, 2024

I was thinking of making every NoiseProcess their own subtype with the same fields as NoiseProcess. That way, e,g., WienerProcess <: NoiseProcess , is distinguishable from GeometricBrownianMotionProcess. Essentialy upgrading the object from a function to a struct. However, under the hood it is still just the NoiseProcess struct.

Alternatively, we can just add another field with the name of the process.

@ChrisRackauckas
Copy link
Member

AbstractNoiseProcess, yes

@oameye
Copy link
Contributor Author

oameye commented Oct 31, 2024

I was trying some things out and came across the classic inheritance vs. composition dilemma. Initially, I envisioned an inheritance approach where WienerProcess would inherit all the fields of NoiseProcess. However, implementing inheritance in Julia would require adding a dependency or using an @inherit macro, as discussed here. I guess this is not really the Julian way.

The alternative is to use composition:

struct WienerProcess <: AbstractNoiseProcess
    process::NoiseProcess
end

With this approach, I would need to define functions like:

process(x::WienerProcess) = x.process
process(x::NoiseProcess) = x

This way, I can use process in any method that dispatches on AbstractNoiseProcess. Do you think this approach is preferable?

One drawback of using types is the additional need to define in-place versions, like WienerProcess!. Perhaps it might be simpler to add a field process::Symbol in NoiseProcess to store the process type information directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants