in reply to Re^2: Need technique for generating constrained random data sets
in thread Need technique for generating constrained random data sets

I just tried it and it works fine:

50.0 +- 50.0: 43.1 50.0 +- 50.0: 18.8 50.0 +- 50.0: 38.2 50.0 +- 50.0: 32.8 50.0 +- 50.0: 13.4 50.0 +- 50.0: 53.8 50.0 +- 50.0: 67.6 50.0 +- 50.0: 25.2 50.0 +- 50.0: 7.2 50.0 +- 50.0: 76.4 50.0 +- 50.0: 10.9 50.0 +- 50.0: 12.7 50.0 +- 50.0: 89.9 50.0 +- 50.0: 3.1 50.0 +- 50.0: 7.0

There is risk of getting trapped and not converging on an answer. E.g. if the first number is 99, then the second number will still be randomly generated between 0 and 100 and will be thrown out repeatedly unless it's less than 1. Ditto for the third number but in an even tighter range.

However, I think that can be avoided by constraining each random number to be in the range from (mid - sd) to min(mid + sd, remainder). In the example above, the second number would be chosen between 0 and 1. Assuming that was 0.6, then the third number would be chosen between 0 and 0.4. That would be guaranteed to converge quickly.

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Replies are listed 'Best First'.
Re^4: Need technique for generating constrained random data sets
by GrandFather (Saint) on Feb 08, 2007 at 20:28 UTC

    Getting trapped was my concern. Now you just need to convince me that the additional constraint on later calculated values doesn't bias the result. I realise that where constraints are the same you can randomise the value calculation order to distribute the bias among the values from set to set. I presume however bias would still be a problem if the constraints were similar, but different? If randomising the value calculation order were used, would that generate bias in the generated sets?

    It may be that I need to change technique depending on the disposition of the constraints. Use the original technique where the probability of choosing a good set randomly is high and switch to this technique (or kyle's code?) for troublesome constraint sets.


    DWIM is Perl's answer to Gödel