# Path: distributions/tests/util.py
# def assert_close(lhs, rhs, tol=TOL, err_msg=None):
#     try:
#         if isinstance(lhs, dict):
#             assert_true(
#                 isinstance(rhs, dict),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             assert_equal(set(lhs.keys()), set(rhs.keys()))
#             for key, val in lhs.iteritems():
#                 msg = '{}[{}]'.format(err_msg or '', key)
#                 assert_close(val, rhs[key], tol, msg)
#         elif isinstance(lhs, float) or isinstance(lhs, numpy.float64):
#             assert_true(
#                 isinstance(rhs, float) or isinstance(rhs, numpy.float64),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             diff = abs(lhs - rhs)
#             norm = 1 + abs(lhs) + abs(rhs)
#             msg = '{} off by {}% = {}'.format(
#                 err_msg or '',
#                 100 * diff / norm,
#                 diff)
#             assert_less(diff, tol * norm, msg)
#         elif isinstance(lhs, numpy.ndarray) or isinstance(rhs, numpy.ndarray):
#             assert_true(
#                 (isinstance(lhs, numpy.ndarray) or isinstance(lhs, list)) and
#                 (isinstance(rhs, numpy.ndarray) or isinstance(rhs, list)),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             decimal = int(round(-math.log10(tol)))
#             assert_array_almost_equal(
#                 lhs,
#                 rhs,
#                 decimal=decimal,
#                 err_msg=(err_msg or ''))
#         elif isinstance(lhs, list) or isinstance(lhs, tuple):
#             assert_true(
#                 isinstance(rhs, list) or isinstance(rhs, tuple),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             for pos, (x, y) in enumerate(izip(lhs, rhs)):
#                 msg = '{}[{}]'.format(err_msg or '', pos)
#                 assert_close(x, y, tol, msg)
#         else:
#             assert_equal(lhs, rhs, err_msg)
#     except Exception:
#         print err_msg or ''
#         print 'actual = {}'.format(print_short(lhs))
#         print 'expected = {}'.format(print_short(rhs))
#         raise


import numpy as np
from nose import SkipTest
from distributions.tests.util import assert_close
        from distributions.dbg.models import nich, niw
        from distributions.lp.models import nich, niw
    # make the NIW case
    niw_shared = niw.Shared()
    niw_shared.load({'mu': mu, 'kappa': kappa, 'psi': psi, 'nu': nu})
    niw_group = niw.Group()
    niw_group.init(niw_shared)

    # make the NIX case
    nix_shared = nich.Shared()
    nix_shared.load({
        'mu': mu[0],
        'kappa': kappa,
        'sigmasq': psi[0, 0] / nu,
        'nu': nu
    })
    nix_group = nich.Group()
    nix_group.init(nix_shared)

    data = np.array([4., 54., 3., -12., 7., 10.])
    for d in data:
        niw_group.add_value(niw_shared, np.array([d]))
        nix_group.add_value(nix_shared, d)

    # check marginals
    assert_close(niw_group.score_data(niw_shared),
                 nix_group.score_data(nix_shared))

    # remove and check
    niw_group.remove_value(niw_shared, np.array([data[1]]))
    nix_group.remove_value(nix_shared, np.array([data[1]]))


# Path: distributions/tests/util.py
# def assert_close(lhs, rhs, tol=TOL, err_msg=None):
#     try:
#         if isinstance(lhs, dict):
#             assert_true(
#                 isinstance(rhs, dict),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             assert_equal(set(lhs.keys()), set(rhs.keys()))
#             for key, val in lhs.iteritems():
#                 msg = '{}[{}]'.format(err_msg or '', key)
#                 assert_close(val, rhs[key], tol, msg)
#         elif isinstance(lhs, float) or isinstance(lhs, numpy.float64):
#             assert_true(
#                 isinstance(rhs, float) or isinstance(rhs, numpy.float64),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             diff = abs(lhs - rhs)
#             norm = 1 + abs(lhs) + abs(rhs)
#             msg = '{} off by {}% = {}'.format(
#                 err_msg or '',
#                 100 * diff / norm,
#                 diff)
#             assert_less(diff, tol * norm, msg)
#         elif isinstance(lhs, numpy.ndarray) or isinstance(rhs, numpy.ndarray):
#             assert_true(
#                 (isinstance(lhs, numpy.ndarray) or isinstance(lhs, list)) and
#                 (isinstance(rhs, numpy.ndarray) or isinstance(rhs, list)),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             decimal = int(round(-math.log10(tol)))
#             assert_array_almost_equal(
#                 lhs,
#                 rhs,
#                 decimal=decimal,
#                 err_msg=(err_msg or ''))
#         elif isinstance(lhs, list) or isinstance(lhs, tuple):
#             assert_true(
#                 isinstance(rhs, list) or isinstance(rhs, tuple),
#                 'type mismatch: {} vs {}'.format(type(lhs), type(rhs)))
#             for pos, (x, y) in enumerate(izip(lhs, rhs)):
#                 msg = '{}[{}]'.format(err_msg or '', pos)
#                 assert_close(x, y, tol, msg)
#         else:
#             assert_equal(lhs, rhs, err_msg)
#     except Exception:
#         print err_msg or ''
#         print 'actual = {}'.format(print_short(lhs))
#         print 'expected = {}'.format(print_short(rhs))
#         raise


# Path: distributions/tests/test_normal_models.py
import numpy as np
from nose import SkipTest
from distributions.tests.util import assert_close
        from distributions.dbg.models import nich, niw
        from distributions.lp.models import nich, niw

    # make the NIW case
    niw_shared = niw.Shared()
    niw_shared.load({'mu': mu, 'kappa': kappa, 'psi': psi, 'nu': nu})
    niw_group = niw.Group()
    niw_group.init(niw_shared)

    # make the NIX case
    nix_shared = nich.Shared()
    nix_shared.load({
        'mu': mu[0],
        'kappa': kappa,
        'sigmasq': psi[0, 0] / nu,
        'nu': nu
    })
    nix_group = nich.Group()
    nix_group.init(nix_shared)

    data = np.array([4., 54., 3., -12., 7., 10.])
    for d in data:
        niw_group.add_value(niw_shared, np.array([d]))
        nix_group.add_value(nix_shared, d)

    # check marginals
    assert_close(niw_group.score_data(niw_shared),
                 nix_group.score_data(nix_shared))

    # remove and check
    niw_group.remove_value(niw_shared, np.array([data[1]]))
    nix_group.remove_value(nix_shared, np.array([data[1]]))


    assert_close(niw_group.score_data(niw_shared),