Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chinese restaurant processes #11

Open
yebai opened this issue Sep 21, 2018 · 2 comments
Open

Chinese restaurant processes #11

yebai opened this issue Sep 21, 2018 · 2 comments
Assignees

Comments

@yebai
Copy link
Member

yebai commented Sep 21, 2018

CRP Demo

@trappmartin
Copy link
Member

I think we should wait with this issue until the BNP PR is merged. I integrated CRP representations into the PR and learning an IMM with a CRP prior will be straightforward with the PR.

@trappmartin
Copy link
Member

Chinese restaurant process example.

# Some data points.
data = [-2,2,-1.5,1.5]

# Parameters of the base distribution of the Dirichlet process.
mu_0 = mean(data)
sigma_0 = 4

# Hyper-parameter of the Dirichlet process, i.e. concentration parameter.
alpha = 0.25

@model infiniteMixtureModel(y, rpm) = begin

    # Definition of the base distribution.
    H = Normal(mu_0, sigma_0)

    # Latent assignments.
    N = length(y)
    z = tzeros(Int, N)

    # Cluster counts.
    cluster_counts = tzeros(Int, N)

    # Cluster locations.
    x = tzeros(Float64, N)

    for i in 1:N
        # Draw assignments using a Chinese restaurant process.
        z[i] ~ ChineseRestaurantProcess(rpm, cluster_counts)

        if cluster_counts[z[i]] == 0
            # Cluster is new, therefore, draw new location.
            l ~ H
            x[z[i]] ~ H
        end

        cluster_counts[z[i]] += 1
        # Draw observation.
        y[i] ~ Normal(x[z[i]], sigma_1)
    end
end

# We use a Dirichlet process as the random probability measure.
rpm = DirichletProcess(alpha)

# Use a sequential Monte Carlo sampler.
sampler = SMC(5000)

# Inference.
mf = infiniteMixtureModel(data, rpm)
samples = sample(mf, sampler)

@trappmartin trappmartin self-assigned this Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants