odow / SDDP.jl

Stochastic Dual Dynamic Programming in Julia

Home Page:https://sddp.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add multi-dimensional random variables

SerenaZwww opened this issue · comments

In my problem, I have a series of random variables $d_{i,j,k}$ , where $i\in{1,\dots,10}$, $j\in{0,\dots,2}$ and $k\in{0,\dots,2}$. $d_{i,j,k}$ has a discrete uniform distribution with support ${k\dots,2}$. How can I define such 90 random variables?

See https://sddp.dev/stable/guides/add_multidimensional_noise/

You must pass a single vector of the sample space, and an (optional) single vector of the associated probabilities.

There is no direct support for multi-variate random variables.

Given the size (there is something like 6^30 possibilities), you obviously can't add the every possible realization of d, so you'll have to sample.

Thank you for the reply! I'm reading the Sampling section on the page, and there's something I feel confused about.

distributions = Distributions.Product([
           Distributions.Binomial(100, 0.5),
           Distributions.Geometric(1 / 20),
           Distributions.Poisson(20),
       ]);

Does it mean this is a 3-d random variable, with the marginal distributions being Binomial, Geometric, and Poisson? So, if I have a 90-d random variable, do I have to add 90 lines between square brackets?

Thank you for the reply! I'm reading the Sampling section on the page, and there's something I feel confused about.

distributions = Distributions.Product([
           Distributions.Binomial(100, 0.5),
           Distributions.Geometric(1 / 20),
           Distributions.Poisson(20),
       ]);

Does it mean this is a 3-d random variable, with the marginal distributions being Binomial, Geometric, and Poisson? So, if I have a 90-d random variable, do I have to add 90 lines between square brackets?

Moreover, is it possible to generate them in a structured form as implied by the indices?

If you want to use the 0-indexed indices:

using JuMP
d = Containers.@container([i in 1:10, j in 0:2, k in 0:2], rand(k:2))

Create a list of samples:

N = 20
Ω = [
    Containers.@container([i in 1:10, j in 0:2, k in 0:2], rand(k:2))
    for _ in 1:N
]
P = fill(1 / N, N)

Thank you for the reply! I think I get it!

@variable(subproblem, d)
N = 20
Ω = [
    Containers.@container([i in 1:10, j in 0:2, k in 0:2], rand(k:2))
    for _ in 1:N
]
P = fill(1 / N, N)
SDDP.parameterize(subproblem, Ω, P) do ω
    return JuMP.fix(d, ω)
end

Here d is a scalar. The realizations ω are Containers.DenseAxisArray.

You probably want:

@variable(subproblem, d[i in 1:10, j in 0:2, k in 0:2])
N = 20
Ω = [
    Containers.@container([i in 1:10, j in 0:2, k in 0:2], rand(k:2))
    for _ in 1:N
]
P = fill(1 / N, N)
SDDP.parameterize(subproblem, Ω, P) do ω
    JuMP.fix.(d, ω)  # Note the fix.( 
    return
end

I have another series of random variables

This is not really another set of random variables, but a transformation. Perhaps something like:

@variable(subproblem, d[i in 1:10, j in 0:2, k in 0:2])
@variable(subproblem, r[i in 1:10, j in 0:2, k in 0:2, kp in 0:2])
N = 20
Ω = [
    Containers.@container([i in 1:10, j in 0:2, k in 0:2], rand(k:2))
    for _ in 1:N
]
P = fill(1 / N, N)
SDDP.parameterize(subproblem, Ω, P) do ω
    JuMP.fix.(d, ω)  # Note the fix.( 
    for i in 1:10, j in 0:2, k in 0:2, kp in 0:2
        r[i, j, k, kp] =  d[i, j, k] == k' ? 1 : 0
    end
    return
end