Skip to content

Conversation

@mberaha
Copy link
Contributor

@mberaha mberaha commented May 24, 2022

I split the Pybmix package into 2: pybmixlib and pybmix

The former one provides access to the AlgorithmWrapper, and is build with pybind11. It does not contain any pure python code.

The latter one contains the protobuf messages and the pure python code.

They must be installed separately:

cd pybmixlib
python3 -m pip install -e .
cd ..
python3 -m pip install -e .

I tested that things work by having this file in the main directory (I named it test_run.py):

import numpy as np
import matplotlib.pyplot as plt

from pybmix.core.mixing import DirichletProcessMixing, StickBreakMixing
from pybmix.core.hierarchy import UnivariateNormal
from pybmix.core.mixture_model import MixtureModel

np.random.seed(2021)


def sample_from_mixture(weigths, means, sds, n_data):
    n_comp = len(weigths)
    clus_alloc = np.random.choice(np.arange(n_comp), p=[0.5, 0.5], size=n_data)
    return np.random.normal(loc=means[clus_alloc], scale=sds[clus_alloc])

y = sample_from_mixture(
    np.array([0.5, 0.5]), np.array([-3, 3]), np.array([1, 1]), 200)

mixing = DirichletProcessMixing(total_mass=5)
hierarchy = UnivariateNormal()
hierarchy.make_default_fixed_params(y, 2)
mixture = MixtureModel(mixing, hierarchy)

mixture.run_mcmc(y, algorithm="Neal2", niter=2000, nburn=1000)

Then

python3 -m test_run

Initializing... Done
Running Neal2 algorithm with NNIG hierarchies, DP mixing...
[============================================================] 100% 0.457s
Done

@mberaha mberaha mentioned this pull request May 24, 2022
@mberaha mberaha requested a review from gbpollam May 24, 2022 15:46
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

Successfully merging this pull request may close these issues.

1 participant