Howdy!

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
  1. pick values, say (22.7, 40.1, 57.3) - sum = 120.1
  2. normalize by multiplying by 100/120.1 -> (18.9, 33.4, 47.7) - sum = 100 -> happiness
  3. pick values, say (32.7, 54.3, 42.9) -> sum = 129.9
  4. normalize by multiplying by 100/129.9 -> (25.2, 41.8, 33.0) - sum = 100 but third number too small -> not happiness
  5. pin out of range value to lower limit -> (25.2, 41.8, 40) - sum = 117
  6. renormalize by multiplying values in range by 60/67 (their share/their sum) -> (22.6, 37.4, 40) - sum = 100 -> happiness

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.

yours,
Michael

In reply to Re: Need technique for generating constrained random data sets by herveus
in thread Need technique for generating constrained random data sets by GrandFather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.