dimanche 24 janvier 2016

How can I compute a random value with multimodal distribution?

I would like to compute a random value with a multimodal distribution composed of N normal distributions.

I have an array with N elements of normal distribution parameters (std deviation, mean).

My language (VHDL) and my library allow me to calculate the following basic distributions: - uniform distribution [-1.0; 1.0] - normal distribution (Box Muller transformation) - Poisson distribution

How can I calculate random values so that the histogram looks like N overlapping normal distributions?

two normal distributions

Types and helpers:

type T_NORMAL_DIST_PARAM is record
    StdDev : REAL;
    Mean   : REAL;
  end record;
  type T_JITTER_DIST is array(NATURAL range <>) of T_NORMAL_DIST_PARAM;
  constant JitterDistribution : T_JITTER_DIST := (
    0 => (0.2, -0.4),
    0 => (0.2,  0.4)
  );

The problems core:

procedure getMultiModalDistributedRandomNumber(Seed : T_SIM_SEED; Value : REAL; JitterDistribution : T_JITTER_DIST) is
  variable rand   : REAL;
  variable Result : REAL;
begin
  -- ...
  for i in JitterDistribution'range loop
    getNormalDistributedRandomValue(Seed, rand, JitterDistribution(i).StdDev,  JitterDistribution(i).Mean);
    -- how to accumulate rand?
  end loop;
  Value := Result;
end procedure;

It's used in:

procedure genClock(signal Clock : out STD_LOGIC; Period : TIME) is
  constant TimeHigh : TIME := Period / 2;
  constant TimeLow : TIME := Period - TimeHigh;
  variable rand : REAL;
begin
  initializeSeed(Seed);
  while (not isStopped) loop
    getMultiModalDistributedRandomNumber(Seed, rand, JitterDistribution);
    Clock <= '1';
    wait for TimeHigh + (Period * rand);
    Clock <= '0';
    wait for TimeLow;
  end loop;
end procedure;




Aucun commentaire:

Enregistrer un commentaire