Fitxer:Dirichlet process draws.svg

Fitxer original(fitxer SVG, nominalment 900 × 900 píxels, mida del fitxer: 588 Ko)

Descripció a Commons

Resum

Descripció
English: Draws from the Dirichlet process DP(N(0,1), alpha). Each row uses a different alpha: 1, 10, 100 and 1000. A row contains 3 repetitions of the same experiment.

Python source code:

import matplotlib.pyplot as plt 
import numpy as np
from scipy.stats import beta
from scipy.stats import norm   

def draw_stick_breaking(ax, alpha, base_distribution):
    beta_prime_ks = []
    theta_ks = []
    
    beta_distribution = beta(1, alpha)
    
    rest = 1
    for k in range(500):
        theta_k = base_distribution.rvs()
        beta_k = beta_distribution.rvs()
        
        theta_ks.append(theta_k)
        beta_prime_k = beta_k*rest
        beta_prime_ks.append(beta_prime_k)
        
        rest *= 1-beta_k
        if rest < 1e-4:
            break
                
    ax.stem(theta_ks, beta_prime_ks, markerfmt=' ')

def main():
    np.random.seed(1) #reproducibility
    
    alphas = [1, 10, 100, 1000]
    base_distribution = norm(0, 1)
    
    n_rows = len(alphas)
    n_cols = 3
    
    fig, axarr = plt.subplots(n_rows,n_cols, sharex=True, sharey="row", figsize=(10,10))

    for i_row in range(n_rows):
        for i_col in range(n_cols):
            draw_stick_breaking(axarr[i_row][i_col], alphas[i_row], base_distribution)
        
    # set 3 ticks on each axis   
    axarr[0][0].xaxis.set_major_locator(plt.MaxNLocator(3))
    for i_row in range(n_rows):
        axarr[i_row][0].yaxis.set_major_locator(plt.MaxNLocator(3))
    fig.tight_layout(pad=0.15)
    
    fig.savefig('dirichlet.svg')
    
    plt.show()

if __name__ == '__main__':
   main()
Data
Font Treball propi
Autor Qorilla

Llicència

Jo, el titular dels drets d'autor d'aquest treball, el public sota la següent llicència:
Creative Commons CC-Zero L'ús d'aquest fitxer és regulat sota les condicions de Creative Commons de CC0 1.0 lliurament al domini públic universal.
La persona que ha associat un treball amb aquest document ha dedicat l'obra domini públic, renunciant en tot el món a tots els seus drets de d'autor i a tots els drets legals relacionats que tenia en l'obra, en la mesura permesa per la llei. Podeu copiar, modificar, distribuir i modificar l'obra, fins i tot amb fins comercials, tot sense demanar permís.

Llegendes

Afegeix una explicació d'una línia del que representa aquest fitxer

Elements representats en aquest fitxer

representa l'entitat

Historial del fitxer

Cliqueu una data/hora per veure el fitxer tal com era aleshores.

Data/horaMiniaturaDimensionsUsuari/aComentari
actual18:10, 20 oct 2014Miniatura per a la versió del 18:10, 20 oct 2014900 × 900 (588 Ko)QorillaUser created page with UploadWizard

La pàgina següent utilitza aquest fitxer:

Ús global del fitxer

Utilització d'aquest fitxer en altres wikis:

Metadades