1

I am working on a project right now and I need to map a variable amount of elements (say between 12 and 18 for this case) across 10 depth levels. Up until now, no worries here.

The thing that bothers me is this: We are currently looking at implementing a concentration point to this distribution but I have no idea how to do it cleanly.

In the above case, a total of 12-18 elements are distributed across 10 levels. But with the addition of the concentration, we need for the majority of the elements to be mapped around the depth of the concentration (let's say depth 4).

I realize this means we are creating a bell curve but I cannot find for the life of me a way to implement it cleanly, with as little risk of leftovers as possible. I am after all running this a few hundred times at game load.

EDIT: Here is an example of what is desired.

Quantity: 18

  • Level 1: 3
  • Level 2: 2
  • Level 3: 2
  • Level 4: 5
  • Level 5: 3
  • Level 6: 2
  • Level 7: 1
  • Level 8: 0
  • Level 9: 0
  • Level 10: 0
marli
  • 425
  • 9
  • 16
Volvary
  • 55
  • 7
  • I feel readers of this question would probably benefit from some visual aids indicating what you're trying to achieve, and potentially the current code attempt you have for distributing elements. As it stands, your question's probably a bit too vague to get helpful input from the community. – Serlite Oct 11 '16 at 18:30
  • So you basically want to sample a normal distribution with a given parameterization n times? Then [this question](http://stackoverflow.com/questions/218060/random-gaussian-variables) might be what you want. – Nico Schertler Oct 11 '16 at 19:15

1 Answers1

1

Well, one way to make it clear is to use discrete distribution with a peak, and Poisson might be a good choice

Sample Poisson up to 9, if it is above 9 reject and resample. Otherwise shift it by 1 and return.

Some pseudo-code based on MathDotNet

using MathNet.Numerics.Distributions;

int Sample(Random rng, double lambda) {
    for( ;; ) {
        int r = Poisson.Sample(rng, lambda);
        if (r < 10)
            return r+1;
    }
    return -1;
}

Checking Mode of the Poisson distribution, it is clear that for peak at 4 you'll have to have lambda between 3 and 4. For lambda=3, you'll get two equal peaks in your sampling at 3 and 4, for lambda=4 you'll get two peaks at 4 and 5 (remember shift by 1). Just play with it and try to set it to something in between which fits your requirements

Severin Pappadeux
  • 15,291
  • 3
  • 27
  • 51
  • That seems like the way to go. If we ever have to change our distribution, I think this is where we will go to. – Volvary Nov 15 '16 at 15:01