In [1]:
import numpy as np
from tensorprob import Model, Parameter, Normal
In [2]:
with Model() as model:
mu = Parameter()
sigma = Parameter(lower=0)
X = Normal(mu, sigma)
# Declare variables for which we have data
model.observed(X)
# Set the initial values
model.initialize({
mu: 10,
sigma: 10,
})
In [3]:
# Create dataset with Numpy
data = np.random.normal(0, 1, 1000)
# Perform the fit
print(model.fit(data))
In [4]:
%matplotlib inline
import matplotlib.pyplot as plt
In [5]:
xs = np.linspace(-5, 5, 200)
plt.hist(data, bins=20, histtype='step', color='k', normed=True)
plt.plot(xs, model.pdf(xs), 'b-')
Out[5]:
In [ ]: