Giter VIP home page Giter VIP logo

Comments (2)

patrick-kidger avatar patrick-kidger commented on August 17, 2024

Thanks for the positive review!

So I wouldn't try to create two different BrownianIntervals as you seem to be doing (self, w1). It's enough to create a single multidimensional BrownianInterval, and then apply the appropriate correlation. For example:

class CorrelatedBrownianInterval(BrownianInterval):
    def __init__(self, corr, **kwargs):
        super().__init__(**kwargs) 
        self.corr = corr

    def __call__(self, ta, tb):
        dW = super().__call__(ta, tb)
        # trick for computing batch matrix-vector product
        # matrix `corr` has shape (channels, channels)
        # batch of vectors `dW` has shape (batch, channels)
        return dW @ self.corr.t()

rho = ...
corr = torch.tensor([[1, 0], [rho, (1 - rho.pow(2)).sqrt()]])
CorrelatedBrownianInterval(corr=corr, size=(batch_size, 2), ...)

I would however note that the SDE solvers are generally written assuming that you're using Brownian motion -- off the top of my head I'm not sure if some of the higher-order solvers like SRK will necessarily produce the right numerics given an arbitrary noise process. (The simpler ones like Euler will no doubt still be fine.)

The safer/more general option is to put any desired correlation into the diffusion matrix of the SDE you want to solve. That is, instead of having g(Y_t) (corr dW) you have (g(Y_t) corr) dW.

class SDE:
    def __init__(self, corr, ...):
        ...
        self.corr = corr

    def _g(self, t, y):
        ...

    def g(self, t, y):
        return self._g(t, y) @ self.corr

And moreover the efficiency of this can be improved for most solvers by also providing

def g_prod(self, t, y, dW):
    return self._g(t, y) @ (dW @ self.corr.t())

so that one evaluates a matrix-(matrix-vector) product rather than a (matrix-matrix)-vector product.

Does that answer your question?


(All code untested.)

from torchsde.

mdiamore avatar mdiamore commented on August 17, 2024

Yes, it does! I figured there was a better way to do it than creating two Brownian instances, and the more general form of adding the correlation directly to the diffusion makes a lot of sense. So I'll go with that approach. Thanks for your help, really great work!

from torchsde.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.