def test_categorical_impute_confidence_touching(): # this is not a full model, it's just enough to test confidence m1 = { 'dtypes': [b'continuous', b'categorical'], 'col_assignment': [0, 0], 'row_assignments': [[0, 0, 0, 1, 1]], 'col_suffstats': [ [], [ {}, {'n': 5, 'k': 3, '0': 1, '1': 2, '2': 2} ] ], 'col_hypers': [ {'m': 0, 'r': 1, 's': 1, 'nu': 1}, {'dirichlet_alpha': 1.} ] } m2 = copy.deepcopy(m1) m2['col_suffstats'][1][1]['0'] = 0 m2['col_suffstats'][1][1]['1'] = 2 m2['col_suffstats'][1][1]['2'] = 3 row2idx = [dict((i,i) for i in range(5))] conf = mu._categorical_impute_conf([m1, m2], row2idx*2, 1, 4) assert conf > .5 assert conf < .9
def test_categorical_impute_confidence_touching(): # this is not a full model, it's just enough to test confidence m1 = { 'dtypes': [b'continuous', b'categorical'], 'col_assignment': [0, 0], 'row_assignments': [[0, 0, 0, 1, 1]], 'col_suffstats': [[], [{}, { 'n': 5, 'k': 3, '0': 1, '1': 2, '2': 2 }]], 'col_hypers': [{ 'm': 0, 'r': 1, 's': 1, 'nu': 1 }, { 'dirichlet_alpha': 1. }] } m2 = copy.deepcopy(m1) m2['col_suffstats'][1][1]['0'] = 0 m2['col_suffstats'][1][1]['1'] = 2 m2['col_suffstats'][1][1]['2'] = 3 row2idx = [dict((i, i) for i in range(5))] conf = mu._categorical_impute_conf([m1, m2], row2idx * 2, 1, 4) assert conf > .5 assert conf < .9
def test_categorical_impute_confidence_identical(): # this is not a full model, it's just enough to test confidence m = { 'dtypes': [b'continuous', b'categorical'], 'col_assignment': [0, 0], 'row_assignments': [[0, 0, 0, 1, 1]], 'col_suffstats': [[], [{}, { 'n': 5, 'k': 3, '0': 1, '1': 2, '2': 2 }]], 'col_hypers': [{ 'm': 0, 'r': 1, 's': 1, 'nu': 1 }, { 'dirichlet_alpha': 1. }] } row2idx = [dict((i, i) for i in range(5))] conf = mu._categorical_impute_conf([m] * 3, row2idx * 3, 1, 4) assert conf == pytest.approx(1.)
def test_categorical_impute_confidence_identical(): # this is not a full model, it's just enough to test confidence m = { 'dtypes': [b'continuous', b'categorical'], 'col_assignment': [0, 0], 'row_assignments': [[0, 0, 0, 1, 1]], 'col_suffstats': [ [], [ {}, {'n': 5, 'k': 3, '0': 1, '1': 2, '2': 2} ] ], 'col_hypers': [ {'m': 0, 'r': 1, 's': 1, 'nu': 1}, {'dirichlet_alpha': 1.} ] } row2idx = [dict((i,i) for i in range(5))] conf = mu._categorical_impute_conf([m]*3, row2idx*3, 1, 4) assert conf == pytest.approx(1.)