from __future__ import (division)

from pomegranate import *
from pomegranate.io import DataGenerator
from pomegranate.io import DataFrameGenerator

from nose.tools import with_setup
from nose.tools import assert_almost_equal
from nose.tools import assert_equal
from nose.tools import assert_not_equal
from nose.tools import assert_less_equal
from nose.tools import assert_raises
from nose.tools import assert_true
from numpy.testing import assert_array_almost_equal

import pandas
import random
import pickle
import numpy as np

nan = numpy.nan

def setup_multivariate_gaussian():
	mu, cov = [0, 0, 0], numpy.eye(3)
	d1 = MultivariateGaussianDistribution(mu, cov)

	mu, cov = [2, 2, 2], numpy.eye(3)
	d2 = MultivariateGaussianDistribution(mu, cov)

	global model
	model = BayesClassifier([d1, d2])

	global X
	X = numpy.array([[ 0.3,  0.5,  0.1],
					 [ 0.8,  1.4,  0.5],
					 [ 1.4,  2.6,  1.8],
					 [ 4.2,  3.3,  3.7],
					 [ 2.6,  3.6,  3.3],
					 [ 3.1,  2.2,  1.7],
					 [ 1.8,  2.2,  1.8],
					 [-1.2, -1.8, -1.5],
					 [-1.8,  0.3,  0.5],
					 [ 0.7, -1.3, -0.1]])

	global y
	y = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]

	global X_nan
	X_nan = numpy.array([[ 0.3,  nan,  0.1],
		     			 [ nan,  1.4,  nan],
			     		 [ 1.4,  2.6,  nan],
				    	 [ nan,  nan,  nan],
					     [ nan,  3.6,  3.3],
					     [ 3.1,  nan,  1.7],
						 [ nan,  nan,  1.8],
						 [-1.2, -1.8, -1.5],
						 [ nan,  0.3,  0.5],
						 [ nan, -1.3,  nan]])


def setup_multivariate_mixed():
	mu, cov = [0, 0, 0], numpy.eye(3)
	d1 = MultivariateGaussianDistribution(mu, cov)

	d21 = ExponentialDistribution(5)
	d22 = LogNormalDistribution(0.2, 0.8)
	d23 = PoissonDistribution(3)
	d2 = IndependentComponentsDistribution([d21, d22, d23])

	global model
	model = BayesClassifier([d1, d2])

	global X
	X = numpy.array([[ 0.3,  0.5,  0.1],
					 [ 0.8,  1.4,  0.5],
					 [ 1.4,  2.6,  1.8],
					 [ 4.2,  3.3,  3.7],
					 [ 2.6,  3.6,  3.3],
					 [ 3.1,  2.2,  1.7],
					 [ 1.8,  2.2,  1.8],
					 [ 1.2,  1.8,  1.5],
					 [ 1.8,  0.3,  0.5],
					 [ 0.7,  1.3,  0.1]])

	global y
	y = [0, 0, 0, 1, 1, 1, 1, 0, 0, 0]

	global X_nan
	X_nan = numpy.array([[ 0.3,  nan,  0.1],
		     			 [ nan,  1.4,  nan],
			     		 [ 1.4,  2.6,  nan],
				    	 [ nan,  nan,  nan],
					     [ nan,  3.6,  3.3],
					     [ 3.1,  nan,  1.7],
						 [ nan,  nan,  1.8],
						 [ 1.2,  1.8,  1.5],
						 [ nan,  0.3,  0.5],
						 [ nan,  1.3,  nan]])


def setup_hmm():
	global model
	global hmm1
	global hmm2
	global hmm3

	rigged = State( DiscreteDistribution({ 'H': 0.8, 'T': 0.2 }) )
	unrigged = State( DiscreteDistribution({ 'H': 0.5, 'T':0.5 }) )

	hmm1 = HiddenMarkovModel()
	hmm1.start = rigged
	hmm1.add_transition(rigged, rigged, 1)
	hmm1.bake()

	hmm2 = HiddenMarkovModel()
	hmm2.start = unrigged
	hmm2.add_transition(unrigged, unrigged, 1)
	hmm2.bake()

	hmm3 = HiddenMarkovModel()
	hmm3.add_transition(hmm3.start, unrigged, 0.5)
	hmm3.add_transition(hmm3.start, rigged, 0.5)
	hmm3.add_transition(rigged, rigged, 0.5)
	hmm3.add_transition(rigged, unrigged, 0.5)
	hmm3.add_transition(unrigged, rigged, 0.5)
	hmm3.add_transition(unrigged, unrigged, 0.5)
	hmm3.bake()

	model = BayesClassifier([hmm1, hmm2, hmm3])


def setup_multivariate():
	pass


def teardown():
	pass


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_initialization():
	assert_equal(model.d, 3)
	assert_equal(model.n, 2)
	assert_equal(model.is_vl_, False)

@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_initialization():
	assert_equal(model.d, 3)
	assert_equal(model.n, 2)
	assert_equal(model.is_vl_, False)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_predict_log_proba():
	y_hat = model.predict_log_proba(X)
	y = [[ -1.48842547e-02,  -4.21488425e+00],
		 [ -4.37487950e-01,  -1.03748795e+00],
		 [ -5.60369104e+00,  -3.69104343e-03],
		 [ -1.64000001e+01,  -7.54345812e-08],
		 [ -1.30000023e+01,  -2.26032685e-06],
		 [ -8.00033541e+00,  -3.35406373e-04],
		 [ -5.60369104e+00,  -3.69104343e-03],
		 [ -3.05902274e-07,  -1.50000003e+01],
		 [ -3.35406373e-04,  -8.00033541e+00],
		 [ -6.11066022e-04,  -7.40061107e+00]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_predict_log_proba():
	y_hat = model.predict_log_proba(X)
	y = [[ -5.03107596e-01,  -9.27980626e-01],
		 [ -1.86355320e-01,  -1.77183117e+00],
		 [ -5.58542088e-01,  -8.48731256e-01],
		 [ -7.67315597e-01,  -6.24101927e-01],
		 [ -2.32860808e+00,  -1.02510436e-01],
		 [ -3.06641866e-03,  -5.78877778e+00],
		 [ -9.85292840e-02,  -2.36626165e+00],
		 [ -2.61764180e-01,  -1.46833995e+00],
		 [ -2.01640009e-03,  -6.20744952e+00],
		 [ -1.47371167e-01,  -1.98758175e+00]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_nan_predict_log_proba():
	y_hat = model.predict_log_proba(X_nan)
	y = [[ -3.99533332e-02,  -3.23995333e+00],
		 [ -1.17110067e+00,  -3.71100666e-01],
		 [ -4.01814993e+00,  -1.81499279e-02],
		 [ -6.93147181e-01,  -6.93147181e-01],
		 [ -9.80005545e+00,  -5.54500620e-05],
		 [ -5.60369104e+00,  -3.69104343e-03],
		 [ -1.78390074e+00,  -1.83900741e-01],
		 [ -3.05902274e-07,  -1.50000003e+01],
		 [ -8.68361522e-02,  -2.48683615e+00],
		 [ -1.00016521e-02,  -4.61000165e+00]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_nan_predict_log_proba():
	y_hat = model.predict_log_proba(X_nan)
	y = [[ -3.57980882e-01,  -1.20093223e+00],
		 [ -1.20735130e+00,  -3.55230506e-01],
		 [ -2.43174286e-01,  -1.53310132e+00],
		 [ -6.93147181e-01,  -6.93147181e-01],
		 [ -9.31781101e+00,  -8.98143220e-05],
		 [ -6.29755079e-04,  -7.37049444e+00],
		 [ -1.31307006e+00,  -3.13332194e-01],
		 [ -2.61764180e-01,  -1.46833995e+00],
		 [ -2.29725479e-01,  -1.58353505e+00],
		 [ -1.17299253e+00,  -3.70251760e-01]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_predict_log_proba_parallel():
	y_hat = model.predict_log_proba(X, n_jobs=2)
	y = [[ -1.48842547e-02,  -4.21488425e+00],
		 [ -4.37487950e-01,  -1.03748795e+00],
		 [ -5.60369104e+00,  -3.69104343e-03],
		 [ -1.64000001e+01,  -7.54345812e-08],
		 [ -1.30000023e+01,  -2.26032685e-06],
		 [ -8.00033541e+00,  -3.35406373e-04],
		 [ -5.60369104e+00,  -3.69104343e-03],
		 [ -3.05902274e-07,  -1.50000003e+01],
		 [ -3.35406373e-04,  -8.00033541e+00],
		 [ -6.11066022e-04,  -7.40061107e+00]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_predict_log_proba_parallel():
	y_hat = model.predict_log_proba(X, n_jobs=2)
	y = [[ -5.03107596e-01,  -9.27980626e-01],
		 [ -1.86355320e-01,  -1.77183117e+00],
		 [ -5.58542088e-01,  -8.48731256e-01],
		 [ -7.67315597e-01,  -6.24101927e-01],
		 [ -2.32860808e+00,  -1.02510436e-01],
		 [ -3.06641866e-03,  -5.78877778e+00],
		 [ -9.85292840e-02,  -2.36626165e+00],
		 [ -2.61764180e-01,  -1.46833995e+00],
		 [ -2.01640009e-03,  -6.20744952e+00],
		 [ -1.47371167e-01,  -1.98758175e+00]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_predict_proba():
	y_hat = model.predict_proba(X)
	y =	[[  9.85225968e-01,   1.47740317e-02],
		 [  6.45656306e-01,   3.54343694e-01],
		 [  3.68423990e-03,   9.96315760e-01],
		 [  7.54345778e-08,   9.99999925e-01],
		 [  2.26032430e-06,   9.99997740e-01],
		 [  3.35350130e-04,   9.99664650e-01],
		 [  3.68423990e-03,   9.96315760e-01],
		 [  9.99999694e-01,   3.05902227e-07],
		 [  9.99664650e-01,   3.35350130e-04],
		 [  9.99389121e-01,   6.10879359e-04]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_predict_proba():
	y_hat = model.predict_proba(X)
	y = [[ 0.60464873,  0.39535127],
		 [ 0.82997863,  0.17002137],
		 [ 0.57204244,  0.42795756],
		 [ 0.46425765,  0.53574235],
		 [ 0.09743127,  0.90256873],
		 [ 0.99693828,  0.00306172],
		 [ 0.90616916,  0.09383084],
		 [ 0.76969251,  0.23030749],
		 [ 0.99798563,  0.00201437],
		 [ 0.86297361,  0.13702639]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_nan_predict_proba():
	y_hat = model.predict_proba(X_nan)
	y = [[  9.60834277e-01,   3.91657228e-02],
		 [  3.10025519e-01,   6.89974481e-01],
		 [  1.79862100e-02,   9.82013790e-01],
		 [  5.00000000e-01,   5.00000000e-01],
		 [  5.54485247e-05,   9.99944551e-01],
		 [  3.68423990e-03,   9.96315760e-01],
		 [  1.67981615e-01,   8.32018385e-01],
		 [  9.99999694e-01,   3.05902227e-07],
		 [  9.16827304e-01,   8.31726965e-02],
		 [  9.90048198e-01,   9.95180187e-03]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_nan_predict_proba():
	y_hat = model.predict_proba(X_nan)
	y = [[  6.99086440e-01,   3.00913560e-01],
		 [  2.98988163e-01,   7.01011837e-01],
		 [  7.84134838e-01,   2.15865162e-01],
		 [  5.00000000e-01,   5.00000000e-01],
		 [  8.98102888e-05,   9.99910190e-01],
		 [  9.99370443e-01,   6.29556825e-04],
		 [  2.68992964e-01,   7.31007036e-01],
		 [  7.69692511e-01,   2.30307489e-01],
		 [  7.94751748e-01,   2.05248252e-01],
		 [  3.09439547e-01,   6.90560453e-01]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_predict_proba_parallel():
	y_hat = model.predict_proba(X, n_jobs=2)
	y = [[  9.85225968e-01,   1.47740317e-02],
		 [  6.45656306e-01,   3.54343694e-01],
		 [  3.68423990e-03,   9.96315760e-01],
		 [  7.54345778e-08,   9.99999925e-01],
		 [  2.26032430e-06,   9.99997740e-01],
		 [  3.35350130e-04,   9.99664650e-01],
		 [  3.68423990e-03,   9.96315760e-01],
		 [  9.99999694e-01,   3.05902227e-07],
		 [  9.99664650e-01,   3.35350130e-04],
		 [  9.99389121e-01,   6.10879359e-04]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_predict_proba_parallel():
	y_hat = model.predict_proba(X, n_jobs=2)
	y = [[ 0.60464873,  0.39535127],
		 [ 0.82997863,  0.17002137],
		 [ 0.57204244,  0.42795756],
		 [ 0.46425765,  0.53574235],
		 [ 0.09743127,  0.90256873],
		 [ 0.99693828,  0.00306172],
		 [ 0.90616916,  0.09383084],
		 [ 0.76969251,  0.23030749],
		 [ 0.99798563,  0.00201437],
		 [ 0.86297361,  0.13702639]]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_predict():
	y_hat = model.predict(X)
	y = [0, 0, 1, 1, 1, 1, 1, 0, 0, 0]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_predict():
	y_hat = model.predict(X)
	y = [0, 0, 0, 1, 1, 0, 0, 0, 0, 0]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_nan_predict():
	y_hat = model.predict(X_nan)
	y = [0, 1, 1, 0, 1, 1, 1, 0, 0, 0]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_nan_predict():
	y_hat = model.predict(X_nan)
	y = [0, 1, 0, 0, 1, 0, 1, 0, 0, 1]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_predict_parallel():
	y_hat = model.predict(X, n_jobs=2)
	y = [0, 0, 1, 1, 1, 1, 1, 0, 0, 0]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_predict_parallel():
	y_hat = model.predict(X, n_jobs=2)
	y = [0, 0, 0, 1, 1, 0, 0, 0, 0, 0]

	assert_array_almost_equal(y, y_hat)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_fit_parallel():
	model.fit(X, y, n_jobs=2)

	mu1 = model.distributions[0].parameters[0]
	cov1 = model.distributions[0].parameters[1]
	mu1_t = [0.03333333, 0.28333333, 0.21666666]
	cov1_t = [[1.3088888, 0.9272222, 0.6227777],
			  [0.9272222, 2.2513888, 1.3402777],
			  [0.6227777, 1.3402777, 0.9547222]]

	mu2 = model.distributions[1].parameters[0]
	cov2 = model.distributions[1].parameters[1]
	mu2_t = [2.925, 2.825, 2.625]
	cov2_t = [[0.75687499, 0.23687499, 0.4793750],
			  [0.23687499, 0.40187499, 0.5318749],
			  [0.47937500, 0.53187499, 0.7868750]]


	assert_array_almost_equal(mu1, mu1_t)
	assert_array_almost_equal(cov1, cov1_t)
	assert_array_almost_equal(mu2, mu2_t)
	assert_array_almost_equal(cov2, cov2_t)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_fit_parallel():
	model.fit(X, y, n_jobs=2)

	mu1 = model.distributions[0].parameters[0]
	cov1 = model.distributions[0].parameters[1]
	mu1_t = [1.033333, 1.3166667, 0.75]
	cov1_t = [[0.242222, 0.0594444, 0.178333],
			  [0.059444, 0.5980555, 0.414166],
			  [0.178333, 0.4141666, 0.439166]]

	d21 = model.distributions[1].distributions[0]
	d22 = model.distributions[1].distributions[1]
	d23 = model.distributions[1].distributions[2]

	assert_array_almost_equal(mu1, mu1_t)
	assert_array_almost_equal(cov1, cov1_t)
	assert_array_almost_equal(d21.parameters, [0.34188034])
	assert_array_almost_equal(d22.parameters, [1.01294275, 0.22658346])
	assert_array_almost_equal(d23.parameters, [2.625])


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_from_samples():
	model = BayesClassifier.from_samples(MultivariateGaussianDistribution, X, y)

	mu1 = model.distributions[0].parameters[0]
	cov1 = model.distributions[0].parameters[1]
	mu1_t = [0.03333333, 0.2833333, 0.21666666]
	cov1_t = [[1.308888888, 0.9272222222, 0.6227777777],
			  [0.927222222, 2.251388888, 1.340277777],
			  [0.622777777, 1.340277777, 0.9547222222]]

	mu2 = model.distributions[1].parameters[0]
	cov2 = model.distributions[1].parameters[1]
	mu2_t = [2.925, 2.825, 2.625]
	cov2_t = [[0.75687500, 0.23687499, 0.47937500],
			  [0.23687499, 0.40187499, 0.53187499],
			  [0.47937500, 0.53187499, 0.78687500]]

	assert_array_almost_equal(mu1, mu1_t)
	assert_array_almost_equal(cov1, cov1_t)
	assert_array_almost_equal(mu2, mu2_t)
	assert_array_almost_equal(cov2, cov2_t)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_pickle():
	model2 = pickle.loads(pickle.dumps(model))

	assert_true(isinstance(model2, BayesClassifier))
	assert_true(isinstance(model2.distributions[0], MultivariateGaussianDistribution))
	assert_true(isinstance(model2.distributions[1], MultivariateGaussianDistribution))
	assert_array_almost_equal(model.weights, model2.weights)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_pickle():
	model2 = pickle.loads(pickle.dumps(model))

	assert_true(isinstance(model2, BayesClassifier))
	assert_true(isinstance(model2.distributions[0], MultivariateGaussianDistribution))
	assert_true(isinstance(model2.distributions[1], IndependentComponentsDistribution))
	assert_array_almost_equal(model.weights, model2.weights)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_to_json():
	model2 = BayesClassifier.from_json(model.to_json())

	assert_true(isinstance(model2, BayesClassifier))
	assert_true(isinstance(model2.distributions[0], MultivariateGaussianDistribution))
	assert_true(isinstance(model2.distributions[1], MultivariateGaussianDistribution))
	assert_array_almost_equal(model.weights, model2.weights)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_to_json():
	model2 = BayesClassifier.from_json(model.to_json())

	assert_true(isinstance(model2, BayesClassifier))
	assert_true(isinstance(model2.distributions[0], MultivariateGaussianDistribution))
	assert_true(isinstance(model2.distributions[1], IndependentComponentsDistribution))
	assert_array_almost_equal(model.weights, model2.weights)


@with_setup(setup_multivariate_gaussian, teardown)
def test_bc_multivariate_gaussian_robust_from_json():
	model2 = from_json(model.to_json())

	assert_true(isinstance(model2, BayesClassifier))
	assert_true(isinstance(model2.distributions[0], MultivariateGaussianDistribution))
	assert_true(isinstance(model2.distributions[1], MultivariateGaussianDistribution))
	assert_array_almost_equal(model.weights, model2.weights)


@with_setup(setup_multivariate_mixed, teardown)
def test_bc_multivariate_mixed_robust_from_json():
	model2 = from_json(model.to_json())

	assert_true(isinstance(model2, BayesClassifier))
	assert_true(isinstance(model2.distributions[0], MultivariateGaussianDistribution))
	assert_true(isinstance(model2.distributions[1], IndependentComponentsDistribution))
	assert_array_almost_equal(model.weights, model2.weights)


@with_setup(setup_hmm, teardown)
def test_model():
	assert_almost_equal(hmm1.log_probability(list('H')), -0.2231435513142097 )
	assert_almost_equal(hmm1.log_probability(list('T')), -1.6094379124341003 )
	assert_almost_equal(hmm1.log_probability(list('HHHH')), -0.8925742052568388 )
	assert_almost_equal(hmm1.log_probability(list('THHH')), -2.2788685663767296 )
	assert_almost_equal(hmm1.log_probability(list('TTTT')), -6.437751649736401 )

	assert_almost_equal(hmm2.log_probability(list('H')), -0.6931471805599453 )
	assert_almost_equal(hmm2.log_probability(list('T')), -0.6931471805599453 )
	assert_almost_equal(hmm2.log_probability(list('HHHH')), -2.772588722239781 )
	assert_almost_equal(hmm2.log_probability(list('THHH')), -2.772588722239781 )
	assert_almost_equal(hmm2.log_probability(list('TTTT')), -2.772588722239781 )

	assert_almost_equal(hmm3.log_probability(list('H')), -0.43078291609245417)
	assert_almost_equal(hmm3.log_probability(list('T')), -1.0498221244986776)
	assert_almost_equal(hmm3.log_probability(list('HHHH')), -1.7231316643698167)
	assert_almost_equal(hmm3.log_probability(list('THHH')), -2.3421708727760397)
	assert_almost_equal(hmm3.log_probability(list('TTTT')), -4.1992884979947105)
	assert_almost_equal(hmm3.log_probability(list('THTHTHTHTHTH')), -8.883630243546788)
	assert_almost_equal(hmm3.log_probability(list('THTHHHHHTHTH')), -7.645551826734343)

	assert_equal(model.d, 1)


@with_setup(setup_hmm, teardown)
def test_hmm_log_proba():
	logs = model.predict_log_proba(np.array([list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'), list('THTHHHHHTHTH')]))

	assert_almost_equal(logs[0][0], -0.89097292388986515)
	assert_almost_equal(logs[0][1], -1.3609765531356006)
	assert_almost_equal(logs[0][2], -1.0986122886681096)

	assert_almost_equal(logs[1][0], -0.93570553121744293)
	assert_almost_equal(logs[1][1], -1.429425687080494)
	assert_almost_equal(logs[1][2], -0.9990078376167526)

	assert_almost_equal(logs[2][0], -3.9007882563128864)
	assert_almost_equal(logs[2][1], -0.23562532881626597)
	assert_almost_equal(logs[2][2], -1.6623251045711958)

	assert_almost_equal(logs[3][0], -3.1703366478831185)
	assert_almost_equal(logs[3][1], -0.49261403211260379)
	assert_almost_equal(logs[3][2], -1.058478108940049)

	assert_almost_equal(logs[4][0], -1.3058441172130273)
	assert_almost_equal(logs[4][1], -1.4007102236822906)
	assert_almost_equal(logs[4][2], -0.7284958836972919)


@with_setup(setup_hmm, teardown)
def test_hmm_proba():
	probs = model.predict_proba(np.array([list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'), list('THTHHHHHTHTH')]))

	assert_almost_equal(probs[0][0], 0.41025641025641024)
	assert_almost_equal(probs[0][1], 0.25641025641025639)
	assert_almost_equal(probs[0][2], 0.33333333333333331)

	assert_almost_equal(probs[1][0], 0.39230898163446098)
	assert_almost_equal(probs[1][1], 0.23944639992337707)
	assert_almost_equal(probs[1][2], 0.36824461844216183)

	assert_almost_equal(probs[2][0], 0.020225961918306088)
	assert_almost_equal(probs[2][1], 0.79007663743383105)
	assert_almost_equal(probs[2][2], 0.18969740064786292)

	assert_almost_equal(probs[3][0], 0.041989459861032523)
	assert_almost_equal(probs[3][1], 0.61102706038265642)
	assert_almost_equal(probs[3][2], 0.346983479756311)

	assert_almost_equal(probs[4][0], 0.27094373022369794)
	assert_almost_equal(probs[4][1], 0.24642188711704707)
	assert_almost_equal(probs[4][2], 0.48263438265925512)


@with_setup(setup_hmm, teardown)
def test_hmm_prediction():
	predicts = model.predict(np.array([list('H'), list('THHH'), list('TTTT'), list('THTHTHTHTHTH'), list('THTHHHHHTHTH')]))

	assert_equal(predicts[0], 0)
	assert_equal(predicts[1], 0)
	assert_equal(predicts[2], 1)
	assert_equal(predicts[3], 1)
	assert_equal(predicts[4], 2)

@with_setup(setup_multivariate_gaussian, teardown)
def test_io_log_probability():
	X2 = DataGenerator(X)
	X3 = DataFrameGenerator(pandas.DataFrame(X))

	logp1 = model.log_probability(X)
	logp2 = model.log_probability(X2)
	logp3 = model.log_probability(X3)

	assert_array_almost_equal(logp1, logp2)
	assert_array_almost_equal(logp1, logp3)

@with_setup(setup_multivariate_gaussian, teardown)
def test_io_predict():
	X2 = DataGenerator(X)
	X3 = DataFrameGenerator(pandas.DataFrame(X))

	y_hat1 = model.predict(X)
	y_hat2 = model.predict(X2)
	y_hat3 = model.predict(X3)

	assert_array_almost_equal(y_hat1, y_hat2)
	assert_array_almost_equal(y_hat1, y_hat3)

@with_setup(setup_multivariate_gaussian, teardown)
def test_io_predict_proba():
	X2 = DataGenerator(X)
	X3 = DataFrameGenerator(pandas.DataFrame(X))

	y_hat1 = model.predict_proba(X)
	y_hat2 = model.predict_proba(X2)
	y_hat3 = model.predict_proba(X3)

	assert_array_almost_equal(y_hat1, y_hat2)
	assert_array_almost_equal(y_hat1, y_hat3)

@with_setup(setup_multivariate_gaussian, teardown)
def test_io_predict_log_proba():
	X2 = DataGenerator(X)
	X3 = DataFrameGenerator(pandas.DataFrame(X))

	y_hat1 = model.predict_log_proba(X)
	y_hat2 = model.predict_log_proba(X2)
	y_hat3 = model.predict_log_proba(X3)

	assert_array_almost_equal(y_hat1, y_hat2)
	assert_array_almost_equal(y_hat1, y_hat3)

def test_io_fit():
	X = numpy.random.randn(100, 5) + 0.5
	weights = numpy.abs(numpy.random.randn(100))
	y = numpy.random.randint(2, size=100)
	data_generator = DataGenerator(X, weights, y)

	mu1 = numpy.array([0, 0, 0, 0, 0])
	mu2 = numpy.array([1, 1, 1, 1, 1])
	cov = numpy.eye(5)

	d1 = MultivariateGaussianDistribution(mu1, cov)
	d2 = MultivariateGaussianDistribution(mu2, cov)
	bc1 = BayesClassifier([d1, d2])
	bc1.fit(X, y, weights)

	d1 = MultivariateGaussianDistribution(mu1, cov)
	d2 = MultivariateGaussianDistribution(mu2, cov)
	bc2 = BayesClassifier([d1, d2])
	bc2.fit(data_generator)

	logp1 = bc1.log_probability(X)
	logp2 = bc2.log_probability(X)

	assert_array_almost_equal(logp1, logp2)

def test_io_from_samples():
	X = numpy.random.randn(100, 5) + 0.5
	weights = numpy.abs(numpy.random.randn(100))
	y = numpy.random.randint(2, size=100)
	data_generator = DataGenerator(X, weights, y)

	d = MultivariateGaussianDistribution

	bc1 = BayesClassifier.from_samples(d, X=X, y=y, weights=weights)
	bc2 = BayesClassifier.from_samples(d, X=data_generator)

	logp1 = bc1.log_probability(X)
	logp2 = bc2.log_probability(X)

	assert_array_almost_equal(logp1, logp2)
[((140, 1, 140, 50), 'nose.tools.with_setup', 'with_setup', ({(140, 12, 140, 39): 'setup_multivariate_gaussian', (140, 41, 140, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((146, 1, 146, 47), 'nose.tools.with_setup', 'with_setup', ({(146, 12, 146, 36): 'setup_multivariate_mixed', (146, 38, 146, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((153, 1, 153, 50), 'nose.tools.with_setup', 'with_setup', ({(153, 12, 153, 39): 'setup_multivariate_gaussian', (153, 41, 153, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((170, 1, 170, 47), 'nose.tools.with_setup', 'with_setup', ({(170, 12, 170, 36): 'setup_multivariate_mixed', (170, 38, 170, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((187, 1, 187, 50), 'nose.tools.with_setup', 'with_setup', ({(187, 12, 187, 39): 'setup_multivariate_gaussian', (187, 41, 187, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((204, 1, 204, 47), 'nose.tools.with_setup', 'with_setup', ({(204, 12, 204, 36): 'setup_multivariate_mixed', (204, 38, 204, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((221, 1, 221, 50), 'nose.tools.with_setup', 'with_setup', ({(221, 12, 221, 39): 'setup_multivariate_gaussian', (221, 41, 221, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((238, 1, 238, 47), 'nose.tools.with_setup', 'with_setup', ({(238, 12, 238, 36): 'setup_multivariate_mixed', (238, 38, 238, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((255, 1, 255, 50), 'nose.tools.with_setup', 'with_setup', ({(255, 12, 255, 39): 'setup_multivariate_gaussian', (255, 41, 255, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((272, 1, 272, 47), 'nose.tools.with_setup', 'with_setup', ({(272, 12, 272, 36): 'setup_multivariate_mixed', (272, 38, 272, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((289, 1, 289, 50), 'nose.tools.with_setup', 'with_setup', ({(289, 12, 289, 39): 'setup_multivariate_gaussian', (289, 41, 289, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((306, 1, 306, 47), 'nose.tools.with_setup', 'with_setup', ({(306, 12, 306, 36): 'setup_multivariate_mixed', (306, 38, 306, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((323, 1, 323, 50), 'nose.tools.with_setup', 'with_setup', ({(323, 12, 323, 39): 'setup_multivariate_gaussian', (323, 41, 323, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((340, 1, 340, 47), 'nose.tools.with_setup', 'with_setup', ({(340, 12, 340, 36): 'setup_multivariate_mixed', (340, 38, 340, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((357, 1, 357, 50), 'nose.tools.with_setup', 'with_setup', ({(357, 12, 357, 39): 'setup_multivariate_gaussian', (357, 41, 357, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((365, 1, 365, 47), 'nose.tools.with_setup', 'with_setup', ({(365, 12, 365, 36): 'setup_multivariate_mixed', (365, 38, 365, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((373, 1, 373, 50), 'nose.tools.with_setup', 'with_setup', ({(373, 12, 373, 39): 'setup_multivariate_gaussian', (373, 41, 373, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((381, 1, 381, 47), 'nose.tools.with_setup', 'with_setup', ({(381, 12, 381, 36): 'setup_multivariate_mixed', (381, 38, 381, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((389, 1, 389, 50), 'nose.tools.with_setup', 'with_setup', ({(389, 12, 389, 39): 'setup_multivariate_gaussian', (389, 41, 389, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((397, 1, 397, 47), 'nose.tools.with_setup', 'with_setup', ({(397, 12, 397, 36): 'setup_multivariate_mixed', (397, 38, 397, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((405, 1, 405, 50), 'nose.tools.with_setup', 'with_setup', ({(405, 12, 405, 39): 'setup_multivariate_gaussian', (405, 41, 405, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((430, 1, 430, 47), 'nose.tools.with_setup', 'with_setup', ({(430, 12, 430, 36): 'setup_multivariate_mixed', (430, 38, 430, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((452, 1, 452, 50), 'nose.tools.with_setup', 'with_setup', ({(452, 12, 452, 39): 'setup_multivariate_gaussian', (452, 41, 452, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((476, 1, 476, 50), 'nose.tools.with_setup', 'with_setup', ({(476, 12, 476, 39): 'setup_multivariate_gaussian', (476, 41, 476, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((486, 1, 486, 47), 'nose.tools.with_setup', 'with_setup', ({(486, 12, 486, 36): 'setup_multivariate_mixed', (486, 38, 486, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((496, 1, 496, 50), 'nose.tools.with_setup', 'with_setup', ({(496, 12, 496, 39): 'setup_multivariate_gaussian', (496, 41, 496, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((506, 1, 506, 47), 'nose.tools.with_setup', 'with_setup', ({(506, 12, 506, 36): 'setup_multivariate_mixed', (506, 38, 506, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((516, 1, 516, 50), 'nose.tools.with_setup', 'with_setup', ({(516, 12, 516, 39): 'setup_multivariate_gaussian', (516, 41, 516, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((526, 1, 526, 47), 'nose.tools.with_setup', 'with_setup', ({(526, 12, 526, 36): 'setup_multivariate_mixed', (526, 38, 526, 46): 'teardown'}, {}), '(setup_multivariate_mixed, teardown)', False, 'from nose.tools import with_setup\n'), ((536, 1, 536, 32), 'nose.tools.with_setup', 'with_setup', ({(536, 12, 536, 21): 'setup_hmm', (536, 23, 536, 31): 'teardown'}, {}), '(setup_hmm, teardown)', False, 'from nose.tools import with_setup\n'), ((561, 1, 561, 32), 'nose.tools.with_setup', 'with_setup', ({(561, 12, 561, 21): 'setup_hmm', (561, 23, 561, 31): 'teardown'}, {}), '(setup_hmm, teardown)', False, 'from nose.tools import with_setup\n'), ((586, 1, 586, 32), 'nose.tools.with_setup', 'with_setup', ({(586, 12, 586, 21): 'setup_hmm', (586, 23, 586, 31): 'teardown'}, {}), '(setup_hmm, teardown)', False, 'from nose.tools import with_setup\n'), ((611, 1, 611, 32), 'nose.tools.with_setup', 'with_setup', ({(611, 12, 611, 21): 'setup_hmm', (611, 23, 611, 31): 'teardown'}, {}), '(setup_hmm, teardown)', False, 'from nose.tools import with_setup\n'), ((621, 1, 621, 50), 'nose.tools.with_setup', 'with_setup', ({(621, 12, 621, 39): 'setup_multivariate_gaussian', (621, 41, 621, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((633, 1, 633, 50), 'nose.tools.with_setup', 'with_setup', ({(633, 12, 633, 39): 'setup_multivariate_gaussian', (633, 41, 633, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((645, 1, 645, 50), 'nose.tools.with_setup', 'with_setup', ({(645, 12, 645, 39): 'setup_multivariate_gaussian', (645, 41, 645, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((657, 1, 657, 50), 'nose.tools.with_setup', 'with_setup', ({(657, 12, 657, 39): 'setup_multivariate_gaussian', (657, 41, 657, 49): 'teardown'}, {}), '(setup_multivariate_gaussian, teardown)', False, 'from nose.tools import with_setup\n'), ((142, 1, 142, 25), 'nose.tools.assert_equal', 'assert_equal', ({(142, 14, 142, 21): 'model.d', (142, 23, 142, 24): '(3)'}, {}), '(model.d, 3)', False, 'from nose.tools import assert_equal\n'), ((143, 1, 143, 25), 'nose.tools.assert_equal', 'assert_equal', ({(143, 14, 143, 21): 'model.n', (143, 23, 143, 24): '(2)'}, {}), '(model.n, 2)', False, 'from nose.tools import assert_equal\n'), ((144, 1, 144, 34), 'nose.tools.assert_equal', 'assert_equal', ({(144, 14, 144, 26): 'model.is_vl_', (144, 28, 144, 33): '(False)'}, {}), '(model.is_vl_, False)', False, 'from nose.tools import assert_equal\n'), ((148, 1, 148, 25), 'nose.tools.assert_equal', 'assert_equal', ({(148, 14, 148, 21): 'model.d', (148, 23, 148, 24): '(3)'}, {}), '(model.d, 3)', False, 'from nose.tools import assert_equal\n'), ((149, 1, 149, 25), 'nose.tools.assert_equal', 'assert_equal', ({(149, 14, 149, 21): 'model.n', (149, 23, 149, 24): '(2)'}, {}), '(model.n, 2)', False, 'from nose.tools import assert_equal\n'), ((150, 1, 150, 34), 'nose.tools.assert_equal', 'assert_equal', ({(150, 14, 150, 26): 'model.is_vl_', (150, 28, 150, 33): '(False)'}, {}), '(model.is_vl_, False)', False, 'from nose.tools import assert_equal\n'), ((167, 1, 167, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(167, 27, 167, 28): 'y', (167, 30, 167, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((184, 1, 184, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(184, 27, 184, 28): 'y', (184, 30, 184, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((201, 1, 201, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(201, 27, 201, 28): 'y', (201, 30, 201, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((218, 1, 218, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(218, 27, 218, 28): 'y', (218, 30, 218, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((235, 1, 235, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(235, 27, 235, 28): 'y', (235, 30, 235, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((252, 1, 252, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(252, 27, 252, 28): 'y', (252, 30, 252, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((269, 1, 269, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(269, 27, 269, 28): 'y', (269, 30, 269, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((286, 1, 286, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(286, 27, 286, 28): 'y', (286, 30, 286, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((303, 1, 303, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(303, 27, 303, 28): 'y', (303, 30, 303, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((320, 1, 320, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(320, 27, 320, 28): 'y', (320, 30, 320, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((337, 1, 337, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(337, 27, 337, 28): 'y', (337, 30, 337, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((354, 1, 354, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(354, 27, 354, 28): 'y', (354, 30, 354, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((362, 1, 362, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(362, 27, 362, 28): 'y', (362, 30, 362, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((370, 1, 370, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(370, 27, 370, 28): 'y', (370, 30, 370, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((378, 1, 378, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(378, 27, 378, 28): 'y', (378, 30, 378, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((386, 1, 386, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(386, 27, 386, 28): 'y', (386, 30, 386, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((394, 1, 394, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(394, 27, 394, 28): 'y', (394, 30, 394, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((402, 1, 402, 36), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(402, 27, 402, 28): 'y', (402, 30, 402, 35): 'y_hat'}, {}), '(y, y_hat)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((424, 1, 424, 38), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(424, 27, 424, 30): 'mu1', (424, 32, 424, 37): 'mu1_t'}, {}), '(mu1, mu1_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((425, 1, 425, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(425, 27, 425, 31): 'cov1', (425, 33, 425, 39): 'cov1_t'}, {}), '(cov1, cov1_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((426, 1, 426, 38), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(426, 27, 426, 30): 'mu2', (426, 32, 426, 37): 'mu2_t'}, {}), '(mu2, mu2_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((427, 1, 427, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(427, 27, 427, 31): 'cov2', (427, 33, 427, 39): 'cov2_t'}, {}), '(cov2, cov2_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((445, 1, 445, 38), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(445, 27, 445, 30): 'mu1', (445, 32, 445, 37): 'mu1_t'}, {}), '(mu1, mu1_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((446, 1, 446, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(446, 27, 446, 31): 'cov1', (446, 33, 446, 39): 'cov1_t'}, {}), '(cov1, cov1_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((447, 1, 447, 56), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(447, 27, 447, 41): 'd21.parameters', (447, 43, 447, 55): '[0.34188034]'}, {}), '(d21.parameters, [0.34188034])', False, 'from numpy.testing import assert_array_almost_equal\n'), ((448, 1, 448, 68), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(448, 27, 448, 41): 'd22.parameters', (448, 43, 448, 67): '[1.01294275, 0.22658346]'}, {}), '(d22.parameters, [1.01294275, 0.22658346])', False, 'from numpy.testing import assert_array_almost_equal\n'), ((449, 1, 449, 51), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(449, 27, 449, 41): 'd23.parameters', (449, 43, 449, 50): '[2.625]'}, {}), '(d23.parameters, [2.625])', False, 'from numpy.testing import assert_array_almost_equal\n'), ((470, 1, 470, 38), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(470, 27, 470, 30): 'mu1', (470, 32, 470, 37): 'mu1_t'}, {}), '(mu1, mu1_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((471, 1, 471, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(471, 27, 471, 31): 'cov1', (471, 33, 471, 39): 'cov1_t'}, {}), '(cov1, cov1_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((472, 1, 472, 38), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(472, 27, 472, 30): 'mu2', (472, 32, 472, 37): 'mu2_t'}, {}), '(mu2, mu2_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((473, 1, 473, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(473, 27, 473, 31): 'cov2', (473, 33, 473, 39): 'cov2_t'}, {}), '(cov2, cov2_t)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((483, 1, 483, 57), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(483, 27, 483, 40): 'model.weights', (483, 42, 483, 56): 'model2.weights'}, {}), '(model.weights, model2.weights)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((493, 1, 493, 57), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(493, 27, 493, 40): 'model.weights', (493, 42, 493, 56): 'model2.weights'}, {}), '(model.weights, model2.weights)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((503, 1, 503, 57), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(503, 27, 503, 40): 'model.weights', (503, 42, 503, 56): 'model2.weights'}, {}), '(model.weights, model2.weights)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((513, 1, 513, 57), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(513, 27, 513, 40): 'model.weights', (513, 42, 513, 56): 'model2.weights'}, {}), '(model.weights, model2.weights)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((523, 1, 523, 57), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(523, 27, 523, 40): 'model.weights', (523, 42, 523, 56): 'model2.weights'}, {}), '(model.weights, model2.weights)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((533, 1, 533, 57), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(533, 27, 533, 40): 'model.weights', (533, 42, 533, 56): 'model2.weights'}, {}), '(model.weights, model2.weights)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((558, 1, 558, 25), 'nose.tools.assert_equal', 'assert_equal', ({(558, 14, 558, 21): 'model.d', (558, 23, 558, 24): '(1)'}, {}), '(model.d, 1)', False, 'from nose.tools import assert_equal\n'), ((565, 1, 565, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(565, 21, 565, 31): 'logs[0][0]', (565, 33, 565, 53): '(-0.8909729238898652)'}, {}), '(logs[0][0], -0.8909729238898652)', False, 'from nose.tools import assert_almost_equal\n'), ((566, 1, 566, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(566, 21, 566, 31): 'logs[0][1]', (566, 33, 566, 52): '(-1.3609765531356006)'}, {}), '(logs[0][1], -1.3609765531356006)', False, 'from nose.tools import assert_almost_equal\n'), ((567, 1, 567, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(567, 21, 567, 31): 'logs[0][2]', (567, 33, 567, 52): '(-1.0986122886681096)'}, {}), '(logs[0][2], -1.0986122886681096)', False, 'from nose.tools import assert_almost_equal\n'), ((569, 1, 569, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(569, 21, 569, 31): 'logs[1][0]', (569, 33, 569, 53): '(-0.9357055312174429)'}, {}), '(logs[1][0], -0.9357055312174429)', False, 'from nose.tools import assert_almost_equal\n'), ((570, 1, 570, 52), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(570, 21, 570, 31): 'logs[1][1]', (570, 33, 570, 51): '(-1.429425687080494)'}, {}), '(logs[1][1], -1.429425687080494)', False, 'from nose.tools import assert_almost_equal\n'), ((571, 1, 571, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(571, 21, 571, 31): 'logs[1][2]', (571, 33, 571, 52): '(-0.9990078376167526)'}, {}), '(logs[1][2], -0.9990078376167526)', False, 'from nose.tools import assert_almost_equal\n'), ((573, 1, 573, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(573, 21, 573, 31): 'logs[2][0]', (573, 33, 573, 52): '(-3.9007882563128864)'}, {}), '(logs[2][0], -3.9007882563128864)', False, 'from nose.tools import assert_almost_equal\n'), ((574, 1, 574, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(574, 21, 574, 31): 'logs[2][1]', (574, 33, 574, 53): '(-0.23562532881626597)'}, {}), '(logs[2][1], -0.23562532881626597)', False, 'from nose.tools import assert_almost_equal\n'), ((575, 1, 575, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(575, 21, 575, 31): 'logs[2][2]', (575, 33, 575, 52): '(-1.6623251045711958)'}, {}), '(logs[2][2], -1.6623251045711958)', False, 'from nose.tools import assert_almost_equal\n'), ((577, 1, 577, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(577, 21, 577, 31): 'logs[3][0]', (577, 33, 577, 52): '(-3.1703366478831185)'}, {}), '(logs[3][0], -3.1703366478831185)', False, 'from nose.tools import assert_almost_equal\n'), ((578, 1, 578, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(578, 21, 578, 31): 'logs[3][1]', (578, 33, 578, 53): '(-0.4926140321126038)'}, {}), '(logs[3][1], -0.4926140321126038)', False, 'from nose.tools import assert_almost_equal\n'), ((579, 1, 579, 52), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(579, 21, 579, 31): 'logs[3][2]', (579, 33, 579, 51): '(-1.058478108940049)'}, {}), '(logs[3][2], -1.058478108940049)', False, 'from nose.tools import assert_almost_equal\n'), ((581, 1, 581, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(581, 21, 581, 31): 'logs[4][0]', (581, 33, 581, 52): '(-1.3058441172130273)'}, {}), '(logs[4][0], -1.3058441172130273)', False, 'from nose.tools import assert_almost_equal\n'), ((582, 1, 582, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(582, 21, 582, 31): 'logs[4][1]', (582, 33, 582, 52): '(-1.4007102236822906)'}, {}), '(logs[4][1], -1.4007102236822906)', False, 'from nose.tools import assert_almost_equal\n'), ((583, 1, 583, 53), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(583, 21, 583, 31): 'logs[4][2]', (583, 33, 583, 52): '(-0.7284958836972919)'}, {}), '(logs[4][2], -0.7284958836972919)', False, 'from nose.tools import assert_almost_equal\n'), ((590, 1, 590, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(590, 21, 590, 32): 'probs[0][0]', (590, 34, 590, 53): '(0.41025641025641024)'}, {}), '(probs[0][0], 0.41025641025641024)', False, 'from nose.tools import assert_almost_equal\n'), ((591, 1, 591, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(591, 21, 591, 32): 'probs[0][1]', (591, 34, 591, 53): '(0.2564102564102564)'}, {}), '(probs[0][1], 0.2564102564102564)', False, 'from nose.tools import assert_almost_equal\n'), ((592, 1, 592, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(592, 21, 592, 32): 'probs[0][2]', (592, 34, 592, 53): '(0.3333333333333333)'}, {}), '(probs[0][2], 0.3333333333333333)', False, 'from nose.tools import assert_almost_equal\n'), ((594, 1, 594, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(594, 21, 594, 32): 'probs[1][0]', (594, 34, 594, 53): '(0.392308981634461)'}, {}), '(probs[1][0], 0.392308981634461)', False, 'from nose.tools import assert_almost_equal\n'), ((595, 1, 595, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(595, 21, 595, 32): 'probs[1][1]', (595, 34, 595, 53): '(0.23944639992337707)'}, {}), '(probs[1][1], 0.23944639992337707)', False, 'from nose.tools import assert_almost_equal\n'), ((596, 1, 596, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(596, 21, 596, 32): 'probs[1][2]', (596, 34, 596, 53): '(0.36824461844216183)'}, {}), '(probs[1][2], 0.36824461844216183)', False, 'from nose.tools import assert_almost_equal\n'), ((598, 1, 598, 55), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(598, 21, 598, 32): 'probs[2][0]', (598, 34, 598, 54): '(0.020225961918306088)'}, {}), '(probs[2][0], 0.020225961918306088)', False, 'from nose.tools import assert_almost_equal\n'), ((599, 1, 599, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(599, 21, 599, 32): 'probs[2][1]', (599, 34, 599, 53): '(0.790076637433831)'}, {}), '(probs[2][1], 0.790076637433831)', False, 'from nose.tools import assert_almost_equal\n'), ((600, 1, 600, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(600, 21, 600, 32): 'probs[2][2]', (600, 34, 600, 53): '(0.18969740064786292)'}, {}), '(probs[2][2], 0.18969740064786292)', False, 'from nose.tools import assert_almost_equal\n'), ((602, 1, 602, 55), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(602, 21, 602, 32): 'probs[3][0]', (602, 34, 602, 54): '(0.04198945986103252)'}, {}), '(probs[3][0], 0.04198945986103252)', False, 'from nose.tools import assert_almost_equal\n'), ((603, 1, 603, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(603, 21, 603, 32): 'probs[3][1]', (603, 34, 603, 53): '(0.6110270603826564)'}, {}), '(probs[3][1], 0.6110270603826564)', False, 'from nose.tools import assert_almost_equal\n'), ((604, 1, 604, 52), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(604, 21, 604, 32): 'probs[3][2]', (604, 34, 604, 51): '(0.346983479756311)'}, {}), '(probs[3][2], 0.346983479756311)', False, 'from nose.tools import assert_almost_equal\n'), ((606, 1, 606, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(606, 21, 606, 32): 'probs[4][0]', (606, 34, 606, 53): '(0.27094373022369794)'}, {}), '(probs[4][0], 0.27094373022369794)', False, 'from nose.tools import assert_almost_equal\n'), ((607, 1, 607, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(607, 21, 607, 32): 'probs[4][1]', (607, 34, 607, 53): '(0.24642188711704707)'}, {}), '(probs[4][1], 0.24642188711704707)', False, 'from nose.tools import assert_almost_equal\n'), ((608, 1, 608, 54), 'nose.tools.assert_almost_equal', 'assert_almost_equal', ({(608, 21, 608, 32): 'probs[4][2]', (608, 34, 608, 53): '(0.4826343826592551)'}, {}), '(probs[4][2], 0.4826343826592551)', False, 'from nose.tools import assert_almost_equal\n'), ((615, 1, 615, 29), 'nose.tools.assert_equal', 'assert_equal', ({(615, 14, 615, 25): 'predicts[0]', (615, 27, 615, 28): '(0)'}, {}), '(predicts[0], 0)', False, 'from nose.tools import assert_equal\n'), ((616, 1, 616, 29), 'nose.tools.assert_equal', 'assert_equal', ({(616, 14, 616, 25): 'predicts[1]', (616, 27, 616, 28): '(0)'}, {}), '(predicts[1], 0)', False, 'from nose.tools import assert_equal\n'), ((617, 1, 617, 29), 'nose.tools.assert_equal', 'assert_equal', ({(617, 14, 617, 25): 'predicts[2]', (617, 27, 617, 28): '(1)'}, {}), '(predicts[2], 1)', False, 'from nose.tools import assert_equal\n'), ((618, 1, 618, 29), 'nose.tools.assert_equal', 'assert_equal', ({(618, 14, 618, 25): 'predicts[3]', (618, 27, 618, 28): '(1)'}, {}), '(predicts[3], 1)', False, 'from nose.tools import assert_equal\n'), ((619, 1, 619, 29), 'nose.tools.assert_equal', 'assert_equal', ({(619, 14, 619, 25): 'predicts[4]', (619, 27, 619, 28): '(2)'}, {}), '(predicts[4], 2)', False, 'from nose.tools import assert_equal\n'), ((623, 6, 623, 22), 'pomegranate.io.DataGenerator', 'DataGenerator', ({(623, 20, 623, 21): 'X'}, {}), '(X)', False, 'from pomegranate.io import DataGenerator\n'), ((630, 1, 630, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(630, 27, 630, 32): 'logp1', (630, 34, 630, 39): 'logp2'}, {}), '(logp1, logp2)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((631, 1, 631, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(631, 27, 631, 32): 'logp1', (631, 34, 631, 39): 'logp3'}, {}), '(logp1, logp3)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((635, 6, 635, 22), 'pomegranate.io.DataGenerator', 'DataGenerator', ({(635, 20, 635, 21): 'X'}, {}), '(X)', False, 'from pomegranate.io import DataGenerator\n'), ((642, 1, 642, 42), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(642, 27, 642, 33): 'y_hat1', (642, 35, 642, 41): 'y_hat2'}, {}), '(y_hat1, y_hat2)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((643, 1, 643, 42), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(643, 27, 643, 33): 'y_hat1', (643, 35, 643, 41): 'y_hat3'}, {}), '(y_hat1, y_hat3)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((647, 6, 647, 22), 'pomegranate.io.DataGenerator', 'DataGenerator', ({(647, 20, 647, 21): 'X'}, {}), '(X)', False, 'from pomegranate.io import DataGenerator\n'), ((654, 1, 654, 42), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(654, 27, 654, 33): 'y_hat1', (654, 35, 654, 41): 'y_hat2'}, {}), '(y_hat1, y_hat2)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((655, 1, 655, 42), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(655, 27, 655, 33): 'y_hat1', (655, 35, 655, 41): 'y_hat3'}, {}), '(y_hat1, y_hat3)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((659, 6, 659, 22), 'pomegranate.io.DataGenerator', 'DataGenerator', ({(659, 20, 659, 21): 'X'}, {}), '(X)', False, 'from pomegranate.io import DataGenerator\n'), ((666, 1, 666, 42), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(666, 27, 666, 33): 'y_hat1', (666, 35, 666, 41): 'y_hat2'}, {}), '(y_hat1, y_hat2)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((667, 1, 667, 42), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(667, 27, 667, 33): 'y_hat1', (667, 35, 667, 41): 'y_hat3'}, {}), '(y_hat1, y_hat3)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((673, 18, 673, 46), 'pomegranate.io.DataGenerator', 'DataGenerator', ({(673, 32, 673, 33): 'X', (673, 35, 673, 42): 'weights', (673, 44, 673, 45): 'y'}, {}), '(X, weights, y)', False, 'from pomegranate.io import DataGenerator\n'), ((692, 1, 692, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(692, 27, 692, 32): 'logp1', (692, 34, 692, 39): 'logp2'}, {}), '(logp1, logp2)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((698, 18, 698, 46), 'pomegranate.io.DataGenerator', 'DataGenerator', ({(698, 32, 698, 33): 'X', (698, 35, 698, 42): 'weights', (698, 44, 698, 45): 'y'}, {}), '(X, weights, y)', False, 'from pomegranate.io import DataGenerator\n'), ((708, 1, 708, 40), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', ({(708, 27, 708, 32): 'logp1', (708, 34, 708, 39): 'logp2'}, {}), '(logp1, logp2)', False, 'from numpy.testing import assert_array_almost_equal\n'), ((478, 23, 478, 42), 'pickle.dumps', 'pickle.dumps', ({(478, 36, 478, 41): 'model'}, {}), '(model)', False, 'import pickle\n'), ((488, 23, 488, 42), 'pickle.dumps', 'pickle.dumps', ({(488, 36, 488, 41): 'model'}, {}), '(model)', False, 'import pickle\n'), ((624, 25, 624, 44), 'pandas.DataFrame', 'pandas.DataFrame', ({(624, 42, 624, 43): 'X'}, {}), '(X)', False, 'import pandas\n'), ((636, 25, 636, 44), 'pandas.DataFrame', 'pandas.DataFrame', ({(636, 42, 636, 43): 'X'}, {}), '(X)', False, 'import pandas\n'), ((648, 25, 648, 44), 'pandas.DataFrame', 'pandas.DataFrame', ({(648, 42, 648, 43): 'X'}, {}), '(X)', False, 'import pandas\n'), ((660, 25, 660, 44), 'pandas.DataFrame', 'pandas.DataFrame', ({(660, 42, 660, 43): 'X'}, {}), '(X)', False, 'import pandas\n')]