In GAMS models I often use the following simple algorithm to generate random variable:
- Generate u = Uniform(0,1)
- Solve F(x) = u
E.g. for the GAMMA distribution:
$ontext |
Using a numerical procedure is always dangerous, as we see here:
C O N O P T 3 version 3.14T Using default options. Reading Data Iter Phase Ninf Infeasibility RGmax NSB Step InItr MX OK ** An equation in the pre-triangular part of the model cannot |
The CDF of the Gamma distribution looks quite innocent:
Two simple ways of working around this. First PATH seems to handle this a little bit better (and CONOPT agrees with the solution). This can be done with:
option cns=path; solve m using cns; |
Indeed CONOPT new says:
C O N O P T 3 version 3.14T Using default options. Reading Data Iter Phase Ninf Infeasibility RGmax NSB Step InItr MX OK ** Feasible solution to a square system. |
Another solution would be to use a different starting point. We used the mean which is an obvious starting point, but with
x.l(i) = 1;
instead of
x.l(i) = m0;
CONOPT can also solve the equations directly.
This illustrates that, although we can work around things, it would be better to have a larger number of statistical functions in GAMS, including some inverse CDF’s.
Erwin, 2 questions:
ReplyDeletethis post seems to be similar to the Random Number Generator code you built back to 2005, but you added up a statement of the failure of the condition
abort$(abs(m0 - b0*c0) > 0.001) "calculation of c0 was not correct";
But since b0=m0/c0, m0-b0*c0 should always be 0, isn't it? how is it possible abs(m0 - b0*c0) > 0.001? I think i've missed some point... could you please help me with that?
2. it comes up to my mind another question that what if the parameter needed to generate the random number, say, mean or lambda, is a variable rather than a known parameter? can we still generat a random number through this? (in the sense that the random number generated is a function of the unknown parameter, rather than a specific number).Does the code above work?
The test was just to make sure I did not make a mistake in the expression to calculate the scale parameter from a known mean. Nothing to get excited about.
ReplyDeletePoint 2 does not make sense to me.