Input:
- List of component distributions: D1, D2, ..., Dk
(Each D represents a different distribution, like normal, exponential, or uniform. These are the components of the mixture.)
- List of corresponding weights: w1, w2, ..., wk
(The weights determine how likely each component is to be selected. They must sum to 1 so that they form a valid probability distribution.)
Output:
- Sampled value from the mixture distribution
(This is the final value sampled from one of the component distributions, determined by the weights.)
1. Generate a random number u from U(0, 1)
(Generate a uniform random number between 0 and 1. This number will be used to select a component distribution based on the weights. The value of `u` will help simulate the probability of selecting each component.)
2. Use the weights to determine which component distribution to sample from:
- Set cumulative_weight = 0
(This is an accumulator that will store the running sum of weights. It helps track when the random number `u` falls into a range corresponding to a specific component.)
- For each component i from 1 to k:
(Iterate through each of the k component distributions.)
a. cumulative_weight += wi
(Add the weight of the current component `wi` to the cumulative total. This step accumulates the probability mass for each component.)
b. If u <= cumulative_weight:
(Check if the random number `u` falls within the cumulative probability range for the current component.)
- Select component Di
(If the condition is met, the current component `Di` is selected for sampling, since the random number `u` fell within its weight range.)
- Break the loop
(Exit the loop once a component is selected, as there's no need to check the remaining components.)
3. Sample a value from the selected component distribution
(After a component is selected, sample a value from that specific distribution. Each distribution has its own sampling method, such as using the Box-Muller transform for a normal distribution, or inverse transform sampling for an exponential distribution.)
4. Return the sampled value
(The function ends by returning the value sampled from the selected component distribution, which represents the final sample from the mixture distribution.)
Consider a mixture distribution with two components:
You are given a mixture of two uniform distributions:
Consider a mixture of three normal distributions with the following parameters: