-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
[FEAT]: Add NNStopping
#81
Conversation
Refactors old code from NeuralPDE
- adds test for a Bermudan max call example from paper - adds test for a Put Basket in Duprie's local volatility model
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #81 +/- ##
==========================================
+ Coverage 58.27% 63.06% +4.78%
==========================================
Files 7 8 +1
Lines 580 647 +67
==========================================
+ Hits 338 408 +70
+ Misses 242 239 -3 ☔ View full report in Codecov by Sentry. |
Missing docs |
docs/src/tutorials/nnstopping.md
Outdated
``` | ||
We then define a `SDEProblem`: | ||
```julia | ||
prob = SDEProblem(f, sigma, u0, tspan; payoff = g) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
payoff
isn't a valid kwarg here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is valid. We pick the payoff and redefine the SDEProblem to simulate:
HighDimPDE.jl/src/NNStopping.jl
Lines 26 to 28 in 2c516a3
g = prob.kwargs[:payoff] | |
sde_prob = SDEProblem(prob.f, prob.u0, prob.tspan) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, that does not match the interface. We should throw an error in SciMLBase if that's done. I'll add that error soon to catch this better, but that means we need to make sure this satisfies a real interface. But since it's a package about solving PDEs, we should have the description in the PDE form.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, I ll pick up the dispatch from the NNKolmogorov PR and put it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, we can't simulate the SDE with this kwarg. But we can still construct it. The check should be at the construction level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
Similar to DeepSplitting and DeepBSDE, NNStopping evaluates the PDE as a Stochastic Differential Equation. Consider an Obstacle PDE of the form: | ||
```math | ||
max\lbrace\partial_t u(t,x) + \mu(t, x) \nabla_x u(t,x) + \frac{1}{2} \sigma^2(t, x) \Delta_x u(t,x) , g(t,x) - u(t,x)\rbrace |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a PIDE?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I see a difference? It just requires f = 0. That can be checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I have a dispatch for f = 0
in the NNKolmogorov PR
:
HighDimPDE.jl/src/HighDimPDE.jl
Lines 126 to 134 in a158d47
function PIDEProblem(g, | |
μ, | |
σ, | |
tspan, | |
xspan; | |
p = nothing, | |
x0_sample = NoSampling(), | |
noise_rate_prototype = nothing, | |
kwargs...) |
We can use that, with a kwarg for g
. How does that sound?
This dipatch will cater to defining optimal stopping problems and kolmogorov PDE problems
src/HighDimPDE.jl
Outdated
* `xspan`: The domain of system state. This can be a tuple of floats for single dimension, and a vector of tuples for multiple dimensions. Where each tuple corresponds to a dimension of state vector. | ||
* `noise_rate_prototype` : Incase of a non diagonal noise, the prototype of `dx` in `σ` | ||
""" | ||
function PIDEProblem(μ, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just use nothing
for f
? I don't see why this would need another dispatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -62,14 +62,14 @@ In `HighDimPDE.jl` the right parameter combination $\theta$ is found by iterativ | |||
`DeepSplitting` allows obtaining $u(t,x)$ on a single point $x \in \Omega$ with the keyword $x$. | |||
|
|||
```julia | |||
prob = PIDEProblem(g, f, μ, σ, x, tspan) | |||
prob = PIDEProblem(μ, σ, x, tspan, g, f,) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. We will need a breaking release. I'd suggest we do that after NNKolmogorov is in
src/HighDimPDE.jl
Outdated
* f -> f(x, y, u(x, t), u(y, t), ∇u(x, t), ∇u(y, t), p, t) | ||
- Semilinear Parabolic Partial Differential Equation | ||
* f -> f(X, u, σᵀ∇u, p, t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should really just have one form?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can consider naming them different. i.e. the integrated one f
and the other one h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I added a new problem : 518a2f1
* f -> `nothing` | ||
* x0 -> nothing, xspan must be provided. | ||
- Obstacle Partial Differential Equation | ||
* f -> `nothing` | ||
* g -> `nothing` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If these can be nothing, make them kwargs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are now kwargs for ParabolicPDEProblem
src/HighDimPDE.jl
Outdated
* `x`: point where `u(x,t)` is approximated. Is required even in the case where `x0_sample` is provided. Determines the dimensionality of the PDE. | ||
* `tspan`: timespan of the problem. | ||
* `g` : initial condition, of the form `g(x, p, t)`. | ||
* `f` : when defining PIDE : nonlinear function, of the form `f(x, y, u(x, t), u(y, t), ∇u(x, t), ∇u(y, t), p, t)`. When defining Semilinear PDE: `f(X, u, σᵀ∇u, p, t)` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, only one form. Multi-forms never work well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is resolved with the introduction of ParabolicPDEProblem
* f -> `nothing` | ||
* x0 -> nothing, xspan must be provided. | ||
- Obstacle Partial Differential Equation | ||
* f -> `nothing` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's tests for f = nothing
on the other methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are f
is nothing
for Kolmogorov :
HighDimPDE.jl/test/PIDEProblem.jl
Line 142 in 32a66cc
@test prob.f == nothing |
Updating for ParabolicPDEProblem:518a2f1 : This separates # g(x) = u(T,x)
ParabolicPDEProblem(μ, σ, x0, tspan, g, f)
## When f = 0 for Kolmogorov Eqn , instead of x0 we have xspan where we sample multiple initial values.
ParabolicPDEProblem(μ, σ, nothing, tspan, f; xspan)
## When f = 0 and instead of `g` we have `payoff`
ParabolicPDEProblem(μ, σ, x0, tspan; payoff = payoff_func)
PIDEProblem: PIDEProblem(μ, σ, x0, tspan, g, f) |
g, f = prob.g, prob.f | ||
g= prob.g | ||
f = if isa(prob, ParabolicPDEProblem) | ||
(y, z, v_y, v_z, ∇v_y, ∇v_z, p, t) -> prob.f(y, v_y, ∇v_y, p, t ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a direct translation like that though, since the interpretation of f
is different?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, since here (for ParabolicPDEProblem) we are interested in non - integrating
variables only. The integrating variables are z
, v_z
and ∇v_z
.
Here's an example : Consider Earlier HighDimPDE.jl MLP
- For Allen Cahn we had:
Lines 143 to 146 in e44771b
X0 = fill(0.0f0, d) # initial point g(X) = 1.0f0 ./ (2.0f0 .+ 4.0f-1 * sum(X .^ 2)) # initial condition a(u) = u - u^3 f(y, z, v_y, v_z, ∇v_y, ∇v_z, p, t) = -a.(v_y)
Notice that onlyv_y
has been passed. That is how it is written for MLP. When the function is not integrated, pass only non-integrating values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But how do you handle the local nonlinearity of the parabolic problem in a PIDEProblem?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If its a PIDEProblem : we mean to integrate f
and we pass in the integrating vars, if its a PIDEProblem we donot integrate f
we just pass in the non integrating vars. The anonymous function was added so as to not break things in MLP and DeepSplitting as much, since they already pass in variables as mentioned above. The always expect f
to be (y, z, v_y, v_z, ∇v_y, ∇v_z, p, t)
and expected the user to only pass non integrating vars incase of a ParabolicPDE. Which is not the case anymore since, the f
for ParabolicPDEProblem has only non integrating vars
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are the two forms written down?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are the docstrings specifying different forms:
For PIDEProblem :
https://github.com/ashutosh-b-b/HighDimPDE.jl/blob/9ba145589fa6766522f0d142686d2ac491fdb030/src/HighDimPDE.jl#L63
For ParabolicPDEProblem:
https://github.com/ashutosh-b-b/HighDimPDE.jl/blob/9ba145589fa6766522f0d142686d2ac491fdb030/src/HighDimPDE.jl#L151
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the MLP tutorial for reference: https://github.com/ashutosh-b-b/HighDimPDE.jl/blob/bb/nn_stopping/docs/src/tutorials/mlp.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't write the PDE for the second one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As in the docstring?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The solvers should list which problems they support somewhere. |
Checklist
contributor guidelines, in particular the SciML Style Guide and
COLPRAC.
Additional context
Add any other context about the problem here.