google-research / torchsde

Differentiable SDE solvers with GPU support and efficient sensitivity analysis.
Apache License 2.0
1.51k stars 194 forks source link

Misunderstandig of default Brownian Motion/Wiener process #111

Closed acubed3 closed 2 years ago

acubed3 commented 2 years ago

I have a set of coupled SDE with white noise. I would like to solve it using torchsde but I completely do not understand what is exactly W(t) from documentation.

Is it Wiener process with zero mean and unit volatility? How can I add Wiener process with sigma != 1 into each equation of my set?

Our naive guess was:

    def g(self, t, number_of_equations):
        noise = np.sqrt(2*A)* torch.ones_like(number_of_equations).unsqueeze(-1)
        return noise

where 2*A is the volatility of Wiener process.

However, it seems that it does not work.

Next, consider the object BrownianInterval. We have a hope that this can help. We initialize:

bm = BrownianInterval(t0=ts[0]., t1=ts[-1]., size=(1,1), device='cuda')

and next try to solve SDE by using sdeint.

What is exactly batch_size? What is exactly brownian_size? For brownian_size I can not find any definition or any other documentation.

Finally, from documentation:

size (tuple of int): The shape of each Brownian sample. If zero dimensional represents a scalar Brownian motion. If one dimensional represents a batch of scalar Brownian motions. If >two dimensional the last dimension represents the size of a a multidimensional Brownian motion, and all previous dimensions represent batch dimensions.

but if we set size=1, we see TypeError: int object is no iterable

Could you please clarify these points?

lxuechen commented 2 years ago

Hi, thanks for the note.

Is it Wiener process with zero mean and unit volatility?

That's loosely true up to the fact that W(t) may be multidimensional.

What is exactly batch_size?

You may interpret this as the number of particles that's being simulated which evolves as according to the SDE.

What is exactly brownian_size?

This is the dimension of the Brownian motion (it is not necessarily the size of the state). In most classic texts, the state dimension is denoted by d, and the dimension of the Brownian motion is denoted by m.

but if we set size=1, we see TypeError: int object is no iterable

We made it clear in the documentation that the input should be a tuple of int, as opposed to a single integer. If you set size=(1,), it should work, since (1,) is a tuple of one integer 1.

acubed3 commented 2 years ago

@lxuechen , thank you so much for your reply!

I will test all the point about tuple of int and will comment it later. The clarification about batch_size is almost clear.

What about my question how to add the Wiener process with volatility != 1 to each equation of a set of coupled SDEs? Is the presented definition of g (it is given in my first comment) true or not?

lxuechen commented 2 years ago

Note g should return a matrix of size (batch_size, state_size, brownian_size) when the noise_type is general. Again, batch_size is the number of particles (note one particle can be multi-dimensional). state_size is the dimension of each particle, and brownian_size is the size of the Brownian motion. Mathematically, during simulation, a matmul is performed behind for this g term, e.g., with Euler solver, you get X_{t+dt} = X_t + f(X_t, t) dt + matmul(g(Xt, t), W{t + dt} - W_t).

Indirectly, this gives you a way to control for the volatility.

lxuechen commented 2 years ago

Closing the issue for now. Free feel to reopen/followup if further clarification is needed.