probability of sample of distribution

Viewed 65

I am trying to generate a sample of 100 scenarios (X, Y) where both X and Y are normally distributed X=N(50,5^2), Y=N(30,2^2) and X and Y are correlated Cov(X,Y)=0.4.

I have been able to generate 100 scenarios with the Cholesky decomposition:

# We do a Cholesky decomposition to generate correlated scenarios
nScenarios = 10

Σ = [25 0.4; 0.4 4]
μ = [50, 30]
L = cholesky(Σ)
v = [rand(Normal(0, 1), nScenarios), rand(Normal(0, 1), nScenarios)]

X = reshape(zeros(nScenarios),1,nScenarios)
Y = reshape(zeros(nScenarios),1,nScenarios)

for i = 1:nScenarios
    X[1, i] = sum(L.U[1, j] *v[j][i] for j = 1:nBreadTypes) + μ[1]
    Y[1, i] = sum(L.U[2, j] *v[j][i] for j = 1:nBreadTypes) + μ[2]
end

However I need the probability of each scenario, i.e P(X=k and Y=p). My question would be, how can we get a sample of a certain distribution with the probability of each scenario?

1 Answers

Following the BatWannaBe explanation, normally I would do it like this:

julia> using Distributions

julia> d = MvNormal([50.0, 30.0], [25.0 0.4; 0.4 4.0])
FullNormal(
dim: 2
μ: [50.0, 30.0]
Σ: [25.0 0.4; 0.4 4.0]
)


julia> point = rand(d)
2-element Vector{Float64}:
 52.807189619051485
 32.693811008760676

julia> pdf(d, point)
0.0056519503173830515
Related