<commit_before>from __future__ import division

from nose.tools import *

from dit import Distribution as D, ScalarDistribution as SD
from dit.exceptions import ditException
from dit.algorithms import (total_correlation as T,
							mutual_information as I)

def test_tc1():
	outcomes = ['000', '011', '101', '110']
	pmf = [1/4] * 4
	d = D(outcomes, pmf)
	assert_almost_equal(T(d), 1.0)

def test_tc2():
	outcomes = ['0000', '0011', '0101', '0110',
	            '1001', '1010', '1100', '1111']
	pmf = [1/8] * 8
	d = D(outcomes, pmf)
	assert_almost_equal(T(d), 1.0)

def test_tc3():
	outcomes = ['0000', '0011', '0101', '0110',
	            '1001', '1010', '1100', '1111']
	pmf = [1/8] * 8
	d = D(outcomes, pmf)
	assert_almost_equal(T(d, [[0],[1],[2]]), 0.0)
	d.set_rv_names("XYZW")
	assert_almost_equal(T(d, [['X'],['Y'],['Z']]), 0.0)

def test_tc4():
	outcomes = ['0000', '0011', '0101', '0110',
	            '1001', '1010', '1100', '1111']
	pmf = [1/8] * 8
	d = D(outcomes, pmf)
	assert_almost_equal(T(d, [[0],[1],[2]], [3]), 1.0)
	d.set_rv_names("XYZW")
	assert_almost_equal(T(d, [['X'],['Y'],['Z']], ['W']), 1.0)

def test_tc5():
	outcomes = ['0000', '0011', '0101', '0110',
	            '1001', '1010', '1100', '1111']
	pmf = [1/8] * 8
	d = D(outcomes, pmf)
	assert_almost_equal(T(d, [[0],[1]], [2,3]), 1.0)
	d.set_rv_names("XYZW")
	assert_almost_equal(T(d, [['X'],['Y']], ['Z','W']), 1.0)

def test_tc6():
	outcomes = ['0000', '0011', '0101', '0110',
	            '1001', '1010', '1100', '1111']
	pmf = [1/8] * 8
	d = D(outcomes, pmf)
	assert_almost_equal(T(d, [[0,1], [2], [3]]), 1.0)
	d.set_rv_names("XYZW")
	assert_almost_equal(T(d, [['X','Y'], ['Z'], ['W']]), 1.0)

def test_tc7():
	outcomes = ['0000', '0011', '0101', '0110',
	            '1001', '1010', '1100', '1111']
	pmf = [1/8] * 8
	d = D(outcomes, pmf)
	assert_almost_equal(T(d, [[0,1,2], [1,2,3]]), 3.0)
	d.set_rv_names("XYZW")
	assert_almost_equal(T(d, [['X','Y','Z'], ['Y','Z','W']]), 3.0)

def test_tc8():
	outcomes = ['00', '01', '11']
	pmf = [1/3] * 3
	d = D(outcomes, pmf)
	assert_almost_equal(T(d), I(d, [0], [1]))
	d.set_rv_names("XY")
	assert_almost_equal(T(d), I(d, ['X'], ['Y']))

def test_tc9():
	d = SD([1/3]*3)
	assert_raises(ditException, T, d)<commit_msg>fix some spacing in test_tc<commit_after>from __future__ import division

from nose.tools import *

from dit import Distribution as D, ScalarDistribution as SD
from dit.exceptions import ditException
from dit.algorithms import (total_correlation as T,
                            mutual_information as I)

def test_tc1():
    outcomes = ['000', '011', '101', '110']
    pmf = [1/4] * 4
    d = D(outcomes, pmf)
    assert_almost_equal(T(d), 1.0)

def test_tc2():
    outcomes = ['0000', '0011', '0101', '0110',
                '1001', '1010', '1100', '1111']
    pmf = [1/8] * 8
    d = D(outcomes, pmf)
    assert_almost_equal(T(d), 1.0)

def test_tc3():
    outcomes = ['0000', '0011', '0101', '0110',
                '1001', '1010', '1100', '1111']
    pmf = [1/8] * 8
    d = D(outcomes, pmf)
    assert_almost_equal(T(d, [[0], [1], [2]]), 0.0)
    d.set_rv_names("XYZW")
    assert_almost_equal(T(d, [['X'], ['Y'], ['Z']]), 0.0)

def test_tc4():
    outcomes = ['0000', '0011', '0101', '0110',
                '1001', '1010', '1100', '1111']
    pmf = [1/8] * 8
    d = D(outcomes, pmf)
    assert_almost_equal(T(d, [[0], [1], [2]], [3]), 1.0)
    d.set_rv_names("XYZW")
    assert_almost_equal(T(d, [['X'], ['Y'], ['Z']], ['W']), 1.0)

def test_tc5():
    outcomes = ['0000', '0011', '0101', '0110',
                '1001', '1010', '1100', '1111']
    pmf = [1/8] * 8
    d = D(outcomes, pmf)
    assert_almost_equal(T(d, [[0], [1]], [2, 3]), 1.0)
    d.set_rv_names("XYZW")
    assert_almost_equal(T(d, [['X'], ['Y']], ['Z', 'W']), 1.0)

def test_tc6():
    outcomes = ['0000', '0011', '0101', '0110',
                '1001', '1010', '1100', '1111']
    pmf = [1/8] * 8
    d = D(outcomes, pmf)
    assert_almost_equal(T(d, [[0, 1], [2], [3]]), 1.0)
    d.set_rv_names("XYZW")
    assert_almost_equal(T(d, [['X', 'Y'], ['Z'], ['W']]), 1.0)

def test_tc7():
    outcomes = ['0000', '0011', '0101', '0110',
                '1001', '1010', '1100', '1111']
    pmf = [1/8] * 8
    d = D(outcomes, pmf)
    assert_almost_equal(T(d, [[0, 1, 2], [1, 2, 3]]), 3.0)
    d.set_rv_names("XYZW")
    assert_almost_equal(T(d, [['X', 'Y', 'Z'], ['Y', 'Z', 'W']]), 3.0)

def test_tc8():
    outcomes = ['00', '01', '11']
    pmf = [1/3] * 3
    d = D(outcomes, pmf)
    assert_almost_equal(T(d), I(d, [0], [1]))
    d.set_rv_names("XY")
    assert_almost_equal(T(d), I(d, ['X'], ['Y']))

def test_tc9():
    d = SD([1/3]*3)
    assert_raises(ditException, T, d)
{'fraction_non_alphanumeric': 0.2548476454293629, 'fraction_numerical': 0.12486682292776476, 'mean_word_length': 3.445075757575758, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1661908', 'n_tokens_mistral': 2456, 'n_tokens_neox': 2075, 'n_words': 467}