In [1]:
import numpy as np
import tensorflow as tf
import edward as ed
# specific modules
from edward.models import Normal
from edward.models import Categorical, Mixture
# visualization
import matplotlib.pyplot as plt
import sys
import os
# Don't require pip install to test out
sys.path.append(os.getcwd() + '/../../src')
from dfgmark import edwardbench as edbench
In [2]:
help(edbench.sample_model)
In [3]:
help(edbench.fit_model)
In [4]:
N = 10000
mean1 = tf.Variable(0., name='mean1')
mean2 = tf.Variable(3., name='mean2')
Gaus1 = Normal(loc=mean1, scale=1.)
Gaus2 = Normal(loc=mean2, scale=1.)
frac_1 = 0.4
frac_2 = 1 - frac_1
cat = Categorical(probs=[frac_1, frac_2])
components = [Gaus1, Gaus2]
# Gaussian mixture model
model_template = Mixture(cat=cat, components=components)
model, samples = edbench.sample_model(model_template, N)
POI = {'mean1':mean1,
'mean2':mean2}
fit_result = edbench.fit_model(model, samples, POI)
print(fit_result)
plt.hist(samples, bins=50, range=(-3.0, 9.0))
plt.show()