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

Add multi-dimensional random variables #732

Closed
SerenaZwww opened this issue Feb 10, 2024 · 6 comments
Closed

Add multi-dimensional random variables #732

SerenaZwww opened this issue Feb 10, 2024 · 6 comments

Comments

@SerenaZwww
Copy link

SerenaZwww commented Feb 10, 2024

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?

@odow
Copy link
Owner

odow commented Feb 10, 2024

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.

@SerenaZwww
Copy link
Author

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?

@SerenaZwww
Copy link
Author

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?

@odow
Copy link
Owner

odow commented Feb 11, 2024

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)

@SerenaZwww
Copy link
Author

SerenaZwww commented Feb 12, 2024

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

@odow
Copy link
Owner

odow commented Feb 12, 2024

@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

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

No branches or pull requests

2 participants