-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmixtureModel.py
executable file
·20 lines (18 loc) · 948 Bytes
/
mixtureModel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
# Generates multivariate Pareto type III random variables as gamma-weighted mixtures of independent Weibull random variables.
@author: Stefan Bucher ([email protected])
"""
import numpy as np
from scipy.special import gamma
# Draw samples using the gamma-weighted mixture of independent Weibull random variables (Proposition 3)
def randomParetoSample_mixtureModel(beta, mu, sigma, size=1):
n = len(mu)
S = np.empty([size, n]) # nSamples x n. Each row contains one random sample of the distribution.
for draw in range(size):
Z = np.random.gamma(shape=1.0, scale=1.0, size=1) # gamma-weighted weighting
U = np.random.exponential(scale=1.0, size=n) # vector of independent exponential random variables
for i in range(n):
S[draw,i] = mu[i] + sigma[i] * (U[i] / Z)**(1/beta) # S is a mixture of Weibull (transformed exponential) r.v.s
return S