In the julia programming language I use StochasticPrograms.jl package to model a two stage stochastic problem. I use @sampler object to develop scenarios and random values. The random variable follows a normal distribution. The @sampler output should be a 3*3 matrix to match the random variable dimension ( d[1:J,1:T], J=3, T=3) defined in the problem.
I have used a few different techniques to get the output as a 3*3 matrix (one of them is below) but no luck.
using StochasticPrograms
@sampler SimpleSampler = begin
N::MvNormal
SimpleSampler(µ, Σ) = new(MvNormal(µ, Σ))
@sample Scenario begin
x = rand(sampler.N)
return @scenario d = reshape(x,3,3)
end
end
μ=[4,4,4,4,4,4,4,4,4]
Σ=[
1 0 0 0 0 0 0 0 0;
0 1 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0;
0 0 0 0 1 0 0 0 0;
0 0 0 0 0 1 0 0 0;
0 0 0 0 0 0 1 0 0;
0 0 0 0 0 0 0 1 0;
0 0 0 0 0 0 0 0 1;
]
s = SimpleSampler(μ,Σ)
s()
and the output is:
d: [3.2222636794881696 1.9732554309220443 3.0941572984285233; 3.421615040079402 3.145688781906985 2.856241404036557; 3.0571013553323985 4.24134467488927 5.800220182172864]