## How do I model this problem efficiently?

Problems with modeling
Saku45
User Posts: 4
Joined: 10 months ago

### How do I model this problem efficiently?

Here is the simple problem. A, B, C, D are random variables with known expected value and standard deviation.

I'd like to represent these variables discretely by finding a 6-dimensional vector (only one vector!) of probabilities and 6-dimensional vectors (one per random variable) of outcomes such that the probabilities sum to 1 and the probabilities combined with each outcome vector matches the EV and SD of the corresponding random variable.

So, the variables we wish to determine are (p1, ...., p6) and (A1, ..., A6) and (C1, ..., C6) and so on.

The constraints are p1 + ... + p6 = 1.

The objective is to minimize the deviations of the means and standard deviations of our variables from the known parameters. So, for example, as you can see below, the known mean of A is 4.3, and therefore, we ought to minimize the square of the difference between 4.3 and p1A1 + ... p6A6.

The code is below. Please critique it, as it does not give the correct answer. All the solutions have distributions with zero standard deviation.

----------------------------------------------------------------------------------------

Sets

state / 1*6 /
randomvar / A, B, C, D/

alias(state, states);

Parameters

mean(randomvar) / A 4.33, B 5.91, C 7.61, D 8.09/
sd(randomvar) /A 0.94, B 0.82, C -0.75, D -0.74/;

Variables

prob(state)
valueofRV(randomvar, state)
z
;

Positive variables
prob;

Equations
cost
SumToOne;

SumToOne .. sum(state, prob(state)) =e= 1;
cost .. z =e= sum(randomvar, power(sum(state, prob(state)*valueofRV(randomvar, state)) - mean(randomvar),2)) + sum(randomvar, power(sqrt(sum(state, power(valueofRV(randomvar, state) - sum(states, valueofRV(randomvar, states)*prob(states)),2))) - sd(randomvar),2) );

Model moodel /all/;

Solve moodel using nlp minimizing z;