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)
[((3258, 3307), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (3268, 3307), False, 'from nose.tools import with_setup\n'), ((3449, 3495), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (3459, 3495), False, 'from nose.tools import with_setup\n'), ((3635, 3684), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (3645, 3684), False, 'from nose.tools import with_setup\n'), ((4230, 4276), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (4240, 4276), False, 'from nose.tools import with_setup\n'), ((4819, 4868), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (4829, 4868), False, 'from nose.tools import with_setup\n'), ((5422, 5468), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (5432, 5468), False, 'from nose.tools import with_setup\n'), ((6019, 6068), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (6029, 6068), False, 'from nose.tools import with_setup\n'), ((6633, 6679), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (6643, 6679), False, 'from nose.tools import with_setup\n'), ((7241, 7290), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (7251, 7290), False, 'from nose.tools import with_setup\n'), ((7828, 7874), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (7838, 7874), False, 'from nose.tools import with_setup\n'), ((8309, 8358), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (8319, 8358), False, 'from nose.tools import with_setup\n'), ((8904, 8950), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (8914, 8950), False, 'from nose.tools import with_setup\n'), ((9493, 9542), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (9503, 9542), False, 'from nose.tools import with_setup\n'), ((10099, 10145), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (10109, 10145), False, 'from nose.tools import with_setup\n'), ((10599, 10648), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (10609, 10648), False, 'from nose.tools import with_setup\n'), ((10797, 10843), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (10807, 10843), False, 'from nose.tools import with_setup\n'), ((10989, 11038), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (10999, 11038), False, 'from nose.tools import with_setup\n'), ((11195, 11241), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (11205, 11241), False, 'from nose.tools import with_setup\n'), ((11395, 11444), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (11405, 11444), False, 'from nose.tools import with_setup\n'), ((11612, 11658), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (11622, 11658), False, 'from nose.tools import with_setup\n'), ((11823, 11872), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (11833, 11872), False, 'from nose.tools import with_setup\n'), ((12630, 12676), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (12640, 12676), False, 'from nose.tools import with_setup\n'), ((13402, 13451), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (13412, 13451), False, 'from nose.tools import with_setup\n'), ((14282, 14331), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (14292, 14331), False, 'from nose.tools import with_setup\n'), ((14700, 14746), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (14710, 14746), False, 'from nose.tools import with_setup\n'), ((15113, 15162), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (15123, 15162), False, 'from nose.tools import with_setup\n'), ((15541, 15587), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (15551, 15587), False, 'from nose.tools import with_setup\n'), ((15964, 16013), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (15974, 16013), False, 'from nose.tools import with_setup\n'), ((16385, 16431), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_mixed', 'teardown'], {}), '(setup_multivariate_mixed, teardown)\n', (16395, 16431), False, 'from nose.tools import with_setup\n'), ((16801, 16832), 'nose.tools.with_setup', 'with_setup', (['setup_hmm', 'teardown'], {}), '(setup_hmm, teardown)\n', (16811, 16832), False, 'from nose.tools import with_setup\n'), ((18212, 18243), 'nose.tools.with_setup', 'with_setup', (['setup_hmm', 'teardown'], {}), '(setup_hmm, teardown)\n', (18222, 18243), False, 'from nose.tools import with_setup\n'), ((19217, 19248), 'nose.tools.with_setup', 'with_setup', (['setup_hmm', 'teardown'], {}), '(setup_hmm, teardown)\n', (19227, 19248), False, 'from nose.tools import with_setup\n'), ((20228, 20259), 'nose.tools.with_setup', 'with_setup', (['setup_hmm', 'teardown'], {}), '(setup_hmm, teardown)\n', (20238, 20259), False, 'from nose.tools import with_setup\n'), ((20561, 20610), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (20571, 20610), False, 'from nose.tools import with_setup\n'), ((20901, 20950), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (20911, 20950), False, 'from nose.tools import with_setup\n'), ((21216, 21265), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (21226, 21265), False, 'from nose.tools import with_setup\n'), ((21555, 21604), 'nose.tools.with_setup', 'with_setup', (['setup_multivariate_gaussian', 'teardown'], {}), '(setup_multivariate_gaussian, teardown)\n', (21565, 21604), False, 'from nose.tools import with_setup\n'), ((3361, 3385), 'nose.tools.assert_equal', 'assert_equal', (['model.d', '(3)'], {}), '(model.d, 3)\n', (3373, 3385), False, 'from nose.tools import assert_equal\n'), ((3387, 3411), 'nose.tools.assert_equal', 'assert_equal', (['model.n', '(2)'], {}), '(model.n, 2)\n', (3399, 3411), False, 'from nose.tools import assert_equal\n'), ((3413, 3446), 'nose.tools.assert_equal', 'assert_equal', (['model.is_vl_', '(False)'], {}), '(model.is_vl_, False)\n', (3425, 3446), False, 'from nose.tools import assert_equal\n'), ((3546, 3570), 'nose.tools.assert_equal', 'assert_equal', (['model.d', '(3)'], {}), '(model.d, 3)\n', (3558, 3570), False, 'from nose.tools import assert_equal\n'), ((3572, 3596), 'nose.tools.assert_equal', 'assert_equal', (['model.n', '(2)'], {}), '(model.n, 2)\n', (3584, 3596), False, 'from nose.tools import assert_equal\n'), ((3598, 3631), 'nose.tools.assert_equal', 'assert_equal', (['model.is_vl_', '(False)'], {}), '(model.is_vl_, False)\n', (3610, 3631), False, 'from nose.tools import assert_equal\n'), ((4191, 4226), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (4216, 4226), False, 'from numpy.testing import assert_array_almost_equal\n'), ((4780, 4815), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (4805, 4815), False, 'from numpy.testing import assert_array_almost_equal\n'), ((5383, 5418), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (5408, 5418), False, 'from numpy.testing import assert_array_almost_equal\n'), ((5980, 6015), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (6005, 6015), False, 'from numpy.testing import assert_array_almost_equal\n'), ((6594, 6629), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (6619, 6629), False, 'from numpy.testing import assert_array_almost_equal\n'), ((7202, 7237), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (7227, 7237), False, 'from numpy.testing import assert_array_almost_equal\n'), ((7789, 7824), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (7814, 7824), False, 'from numpy.testing import assert_array_almost_equal\n'), ((8270, 8305), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (8295, 8305), False, 'from numpy.testing import assert_array_almost_equal\n'), ((8865, 8900), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (8890, 8900), False, 'from numpy.testing import assert_array_almost_equal\n'), ((9454, 9489), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (9479, 9489), False, 'from numpy.testing import assert_array_almost_equal\n'), ((10060, 10095), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (10085, 10095), False, 'from numpy.testing import assert_array_almost_equal\n'), ((10560, 10595), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (10585, 10595), False, 'from numpy.testing import assert_array_almost_equal\n'), ((10758, 10793), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (10783, 10793), False, 'from numpy.testing import assert_array_almost_equal\n'), ((10950, 10985), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (10975, 10985), False, 'from numpy.testing import assert_array_almost_equal\n'), ((11156, 11191), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (11181, 11191), False, 'from numpy.testing import assert_array_almost_equal\n'), ((11356, 11391), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (11381, 11391), False, 'from numpy.testing import assert_array_almost_equal\n'), ((11573, 11608), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (11598, 11608), False, 'from numpy.testing import assert_array_almost_equal\n'), ((11784, 11819), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y', 'y_hat'], {}), '(y, y_hat)\n', (11809, 11819), False, 'from numpy.testing import assert_array_almost_equal\n'), ((12468, 12505), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['mu1', 'mu1_t'], {}), '(mu1, mu1_t)\n', (12493, 12505), False, 'from numpy.testing import assert_array_almost_equal\n'), ((12507, 12546), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['cov1', 'cov1_t'], {}), '(cov1, cov1_t)\n', (12532, 12546), False, 'from numpy.testing import assert_array_almost_equal\n'), ((12548, 12585), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['mu2', 'mu2_t'], {}), '(mu2, mu2_t)\n', (12573, 12585), False, 'from numpy.testing import assert_array_almost_equal\n'), ((12587, 12626), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['cov2', 'cov2_t'], {}), '(cov2, cov2_t)\n', (12612, 12626), False, 'from numpy.testing import assert_array_almost_equal\n'), ((13142, 13179), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['mu1', 'mu1_t'], {}), '(mu1, mu1_t)\n', (13167, 13179), False, 'from numpy.testing import assert_array_almost_equal\n'), ((13181, 13220), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['cov1', 'cov1_t'], {}), '(cov1, cov1_t)\n', (13206, 13220), False, 'from numpy.testing import assert_array_almost_equal\n'), ((13222, 13277), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['d21.parameters', '[0.34188034]'], {}), '(d21.parameters, [0.34188034])\n', (13247, 13277), False, 'from numpy.testing import assert_array_almost_equal\n'), ((13279, 13346), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['d22.parameters', '[1.01294275, 0.22658346]'], {}), '(d22.parameters, [1.01294275, 0.22658346])\n', (13304, 13346), False, 'from numpy.testing import assert_array_almost_equal\n'), ((13348, 13398), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['d23.parameters', '[2.625]'], {}), '(d23.parameters, [2.625])\n', (13373, 13398), False, 'from numpy.testing import assert_array_almost_equal\n'), ((14120, 14157), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['mu1', 'mu1_t'], {}), '(mu1, mu1_t)\n', (14145, 14157), False, 'from numpy.testing import assert_array_almost_equal\n'), ((14159, 14198), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['cov1', 'cov1_t'], {}), '(cov1, cov1_t)\n', (14184, 14198), False, 'from numpy.testing import assert_array_almost_equal\n'), ((14200, 14237), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['mu2', 'mu2_t'], {}), '(mu2, mu2_t)\n', (14225, 14237), False, 'from numpy.testing import assert_array_almost_equal\n'), ((14239, 14278), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['cov2', 'cov2_t'], {}), '(cov2, cov2_t)\n', (14264, 14278), False, 'from numpy.testing import assert_array_almost_equal\n'), ((14640, 14696), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['model.weights', 'model2.weights'], {}), '(model.weights, model2.weights)\n', (14665, 14696), False, 'from numpy.testing import assert_array_almost_equal\n'), ((15053, 15109), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['model.weights', 'model2.weights'], {}), '(model.weights, model2.weights)\n', (15078, 15109), False, 'from numpy.testing import assert_array_almost_equal\n'), ((15481, 15537), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['model.weights', 'model2.weights'], {}), '(model.weights, model2.weights)\n', (15506, 15537), False, 'from numpy.testing import assert_array_almost_equal\n'), ((15904, 15960), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['model.weights', 'model2.weights'], {}), '(model.weights, model2.weights)\n', (15929, 15960), False, 'from numpy.testing import assert_array_almost_equal\n'), ((16325, 16381), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['model.weights', 'model2.weights'], {}), '(model.weights, model2.weights)\n', (16350, 16381), False, 'from numpy.testing import assert_array_almost_equal\n'), ((16741, 16797), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['model.weights', 'model2.weights'], {}), '(model.weights, model2.weights)\n', (16766, 16797), False, 'from numpy.testing import assert_array_almost_equal\n'), ((18184, 18208), 'nose.tools.assert_equal', 'assert_equal', (['model.d', '(1)'], {}), '(model.d, 1)\n', (18196, 18208), False, 'from nose.tools import assert_equal\n'), ((18399, 18451), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[0][0]', '(-0.8909729238898652)'], {}), '(logs[0][0], -0.8909729238898652)\n', (18418, 18451), False, 'from nose.tools import assert_almost_equal\n'), ((18454, 18506), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[0][1]', '(-1.3609765531356006)'], {}), '(logs[0][1], -1.3609765531356006)\n', (18473, 18506), False, 'from nose.tools import assert_almost_equal\n'), ((18508, 18560), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[0][2]', '(-1.0986122886681096)'], {}), '(logs[0][2], -1.0986122886681096)\n', (18527, 18560), False, 'from nose.tools import assert_almost_equal\n'), ((18563, 18615), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[1][0]', '(-0.9357055312174429)'], {}), '(logs[1][0], -0.9357055312174429)\n', (18582, 18615), False, 'from nose.tools import assert_almost_equal\n'), ((18618, 18669), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[1][1]', '(-1.429425687080494)'], {}), '(logs[1][1], -1.429425687080494)\n', (18637, 18669), False, 'from nose.tools import assert_almost_equal\n'), ((18671, 18723), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[1][2]', '(-0.9990078376167526)'], {}), '(logs[1][2], -0.9990078376167526)\n', (18690, 18723), False, 'from nose.tools import assert_almost_equal\n'), ((18726, 18778), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[2][0]', '(-3.9007882563128864)'], {}), '(logs[2][0], -3.9007882563128864)\n', (18745, 18778), False, 'from nose.tools import assert_almost_equal\n'), ((18780, 18833), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[2][1]', '(-0.23562532881626597)'], {}), '(logs[2][1], -0.23562532881626597)\n', (18799, 18833), False, 'from nose.tools import assert_almost_equal\n'), ((18835, 18887), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[2][2]', '(-1.6623251045711958)'], {}), '(logs[2][2], -1.6623251045711958)\n', (18854, 18887), False, 'from nose.tools import assert_almost_equal\n'), ((18890, 18942), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[3][0]', '(-3.1703366478831185)'], {}), '(logs[3][0], -3.1703366478831185)\n', (18909, 18942), False, 'from nose.tools import assert_almost_equal\n'), ((18944, 18996), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[3][1]', '(-0.4926140321126038)'], {}), '(logs[3][1], -0.4926140321126038)\n', (18963, 18996), False, 'from nose.tools import assert_almost_equal\n'), ((18999, 19050), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[3][2]', '(-1.058478108940049)'], {}), '(logs[3][2], -1.058478108940049)\n', (19018, 19050), False, 'from nose.tools import assert_almost_equal\n'), ((19053, 19105), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[4][0]', '(-1.3058441172130273)'], {}), '(logs[4][0], -1.3058441172130273)\n', (19072, 19105), False, 'from nose.tools import assert_almost_equal\n'), ((19107, 19159), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[4][1]', '(-1.4007102236822906)'], {}), '(logs[4][1], -1.4007102236822906)\n', (19126, 19159), False, 'from nose.tools import assert_almost_equal\n'), ((19161, 19213), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['logs[4][2]', '(-0.7284958836972919)'], {}), '(logs[4][2], -0.7284958836972919)\n', (19180, 19213), False, 'from nose.tools import assert_almost_equal\n'), ((19397, 19450), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[0][0]', '(0.41025641025641024)'], {}), '(probs[0][0], 0.41025641025641024)\n', (19416, 19450), False, 'from nose.tools import assert_almost_equal\n'), ((19452, 19504), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[0][1]', '(0.2564102564102564)'], {}), '(probs[0][1], 0.2564102564102564)\n', (19471, 19504), False, 'from nose.tools import assert_almost_equal\n'), ((19507, 19559), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[0][2]', '(0.3333333333333333)'], {}), '(probs[0][2], 0.3333333333333333)\n', (19526, 19559), False, 'from nose.tools import assert_almost_equal\n'), ((19563, 19614), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[1][0]', '(0.392308981634461)'], {}), '(probs[1][0], 0.392308981634461)\n', (19582, 19614), False, 'from nose.tools import assert_almost_equal\n'), ((19618, 19671), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[1][1]', '(0.23944639992337707)'], {}), '(probs[1][1], 0.23944639992337707)\n', (19637, 19671), False, 'from nose.tools import assert_almost_equal\n'), ((19673, 19726), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[1][2]', '(0.36824461844216183)'], {}), '(probs[1][2], 0.36824461844216183)\n', (19692, 19726), False, 'from nose.tools import assert_almost_equal\n'), ((19729, 19783), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[2][0]', '(0.020225961918306088)'], {}), '(probs[2][0], 0.020225961918306088)\n', (19748, 19783), False, 'from nose.tools import assert_almost_equal\n'), ((19785, 19836), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[2][1]', '(0.790076637433831)'], {}), '(probs[2][1], 0.790076637433831)\n', (19804, 19836), False, 'from nose.tools import assert_almost_equal\n'), ((19840, 19893), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[2][2]', '(0.18969740064786292)'], {}), '(probs[2][2], 0.18969740064786292)\n', (19859, 19893), False, 'from nose.tools import assert_almost_equal\n'), ((19896, 19949), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[3][0]', '(0.04198945986103252)'], {}), '(probs[3][0], 0.04198945986103252)\n', (19915, 19949), False, 'from nose.tools import assert_almost_equal\n'), ((19952, 20004), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[3][1]', '(0.6110270603826564)'], {}), '(probs[3][1], 0.6110270603826564)\n', (19971, 20004), False, 'from nose.tools import assert_almost_equal\n'), ((20007, 20058), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[3][2]', '(0.346983479756311)'], {}), '(probs[3][2], 0.346983479756311)\n', (20026, 20058), False, 'from nose.tools import assert_almost_equal\n'), ((20061, 20114), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[4][0]', '(0.27094373022369794)'], {}), '(probs[4][0], 0.27094373022369794)\n', (20080, 20114), False, 'from nose.tools import assert_almost_equal\n'), ((20116, 20169), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[4][1]', '(0.24642188711704707)'], {}), '(probs[4][1], 0.24642188711704707)\n', (20135, 20169), False, 'from nose.tools import assert_almost_equal\n'), ((20171, 20223), 'nose.tools.assert_almost_equal', 'assert_almost_equal', (['probs[4][2]', '(0.4826343826592551)'], {}), '(probs[4][2], 0.4826343826592551)\n', (20190, 20223), False, 'from nose.tools import assert_almost_equal\n'), ((20410, 20438), 'nose.tools.assert_equal', 'assert_equal', (['predicts[0]', '(0)'], {}), '(predicts[0], 0)\n', (20422, 20438), False, 'from nose.tools import assert_equal\n'), ((20440, 20468), 'nose.tools.assert_equal', 'assert_equal', (['predicts[1]', '(0)'], {}), '(predicts[1], 0)\n', (20452, 20468), False, 'from nose.tools import assert_equal\n'), ((20470, 20498), 'nose.tools.assert_equal', 'assert_equal', (['predicts[2]', '(1)'], {}), '(predicts[2], 1)\n', (20482, 20498), False, 'from nose.tools import assert_equal\n'), ((20500, 20528), 'nose.tools.assert_equal', 'assert_equal', (['predicts[3]', '(1)'], {}), '(predicts[3], 1)\n', (20512, 20528), False, 'from nose.tools import assert_equal\n'), ((20530, 20558), 'nose.tools.assert_equal', 'assert_equal', (['predicts[4]', '(2)'], {}), '(predicts[4], 2)\n', (20542, 20558), False, 'from nose.tools import assert_equal\n'), ((20648, 20664), 'pomegranate.io.DataGenerator', 'DataGenerator', (['X'], {}), '(X)\n', (20661, 20664), False, 'from pomegranate.io import DataGenerator\n'), ((20818, 20857), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['logp1', 'logp2'], {}), '(logp1, logp2)\n', (20843, 20857), False, 'from numpy.testing import assert_array_almost_equal\n'), ((20859, 20898), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['logp1', 'logp3'], {}), '(logp1, logp3)\n', (20884, 20898), False, 'from numpy.testing import assert_array_almost_equal\n'), ((20980, 20996), 'pomegranate.io.DataGenerator', 'DataGenerator', (['X'], {}), '(X)\n', (20993, 20996), False, 'from pomegranate.io import DataGenerator\n'), ((21129, 21170), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y_hat1', 'y_hat2'], {}), '(y_hat1, y_hat2)\n', (21154, 21170), False, 'from numpy.testing import assert_array_almost_equal\n'), ((21172, 21213), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y_hat1', 'y_hat3'], {}), '(y_hat1, y_hat3)\n', (21197, 21213), False, 'from numpy.testing import assert_array_almost_equal\n'), ((21301, 21317), 'pomegranate.io.DataGenerator', 'DataGenerator', (['X'], {}), '(X)\n', (21314, 21317), False, 'from pomegranate.io import DataGenerator\n'), ((21468, 21509), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y_hat1', 'y_hat2'], {}), '(y_hat1, y_hat2)\n', (21493, 21509), False, 'from numpy.testing import assert_array_almost_equal\n'), ((21511, 21552), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y_hat1', 'y_hat3'], {}), '(y_hat1, y_hat3)\n', (21536, 21552), False, 'from numpy.testing import assert_array_almost_equal\n'), ((21644, 21660), 'pomegranate.io.DataGenerator', 'DataGenerator', (['X'], {}), '(X)\n', (21657, 21660), False, 'from pomegranate.io import DataGenerator\n'), ((21823, 21864), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y_hat1', 'y_hat2'], {}), '(y_hat1, y_hat2)\n', (21848, 21864), False, 'from numpy.testing import assert_array_almost_equal\n'), ((21866, 21907), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['y_hat1', 'y_hat3'], {}), '(y_hat1, y_hat3)\n', (21891, 21907), False, 'from numpy.testing import assert_array_almost_equal\n'), ((22069, 22097), 'pomegranate.io.DataGenerator', 'DataGenerator', (['X', 'weights', 'y'], {}), '(X, weights, y)\n', (22082, 22097), False, 'from pomegranate.io import DataGenerator\n'), ((22571, 22610), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['logp1', 'logp2'], {}), '(logp1, logp2)\n', (22596, 22610), False, 'from numpy.testing import assert_array_almost_equal\n'), ((22781, 22809), 'pomegranate.io.DataGenerator', 'DataGenerator', (['X', 'weights', 'y'], {}), '(X, weights, y)\n', (22794, 22809), False, 'from pomegranate.io import DataGenerator\n'), ((23040, 23079), 'numpy.testing.assert_array_almost_equal', 'assert_array_almost_equal', (['logp1', 'logp2'], {}), '(logp1, logp2)\n', (23065, 23079), False, 'from numpy.testing import assert_array_almost_equal\n'), ((14399, 14418), 'pickle.dumps', 'pickle.dumps', (['model'], {}), '(model)\n', (14411, 14418), False, 'import pickle\n'), ((14811, 14830), 'pickle.dumps', 'pickle.dumps', (['model'], {}), '(model)\n', (14823, 14830), False, 'import pickle\n'), ((20690, 20709), 'pandas.DataFrame', 'pandas.DataFrame', (['X'], {}), '(X)\n', (20706, 20709), False, 'import pandas\n'), ((21022, 21041), 'pandas.DataFrame', 'pandas.DataFrame', (['X'], {}), '(X)\n', (21038, 21041), False, 'import pandas\n'), ((21343, 21362), 'pandas.DataFrame', 'pandas.DataFrame', (['X'], {}), '(X)\n', (21359, 21362), False, 'import pandas\n'), ((21686, 21705), 'pandas.DataFrame', 'pandas.DataFrame', (['X'], {}), '(X)\n', (21702, 21705), False, 'import pandas\n')]