in reply to Need technique for generating constrained random data sets
When a trial set is bad, either you need to toss it entirely and start over, or you bring the "bad" value into range by taking from values that are in range. This gets more interesting if more than one value is out of range. If you need four values, and the third can't satisfy it's constraints, the fourth won't have any of the pie left for it.
Hmmm... I'm visualizing a pie divider that has n cutters, with the spacing between each cutter constrained to x +/- y.
I'm too lazy right now to work up any code fragments.
I'm not visualizing an approach that will reliably produce valid values without some sort of iteration, either by tossing entire sets that fail, or by adjusting the values. If you pick values for each component without regard to the total and then normalize them so the sum is 100, you will get fewer bad sets, but I can see how normalizing could push a value near the limit out of bounds.
20.0 +- 15.0: 22.7 30.0 +- 25.0: 40.1 50.0 +- 10.0: 37.2 - bad
Yeah, it's iterative, but so long as the constraints allow a result, it will converge. It's that mechanical pie divider thingy. Sometimes, one of the dividers runs up against its stops and becomes pinned.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need technique for generating constrained random data sets
by GrandFather (Saint) on Feb 08, 2007 at 09:31 UTC |