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))


 hess_inv: <2x2 LbfgsInvHessProduct with dtype=float64>
  success: True
   status: 0
      fun: 1398.7665571861055
     nfev: 87
  message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
        x: array([ 0.02567145,  0.98003015])
      nit: 13
      jac: array([ -2.20552465e-03,  -6.82121026e-05])

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]:
[<matplotlib.lines.Line2D at 0x7f7f0f393908>]

In [ ]: