Example #1
0
def test_cant_serialize():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    prng = rng()
    s = initialize(defn, data, prng)
    s.serialize()
Example #2
0
def test_cant_serialize():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    prng = rng()
    s = initialize(defn, data, prng)
    s.serialize()
Example #3
0
def test_multi_dish_initialization():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng, initial_dishes=V)
    assert_true(s.ntopics() > 1)
Example #4
0
def test_single_dish_initialization():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng, initial_dishes=1)
    assert_equals(s.ntopics(), 0) # Only dummy topic
Example #5
0
def test_simple():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng)
    assert_equals(s.nentities(), len(data))
Example #6
0
def test_single_dish_initialization():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng, initial_dishes=1)
    assert_equals(s.ntopics(), 0)  # Only dummy topic
Example #7
0
def test_multi_dish_initialization():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng, initial_dishes=V)
    assert_true(s.ntopics() > 1)
Example #8
0
def test_simple():
    N, V = 10, 100
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = numpy_dataview(data)
    R = rng()
    s = initialize(defn, view, R)
    assert_equals(s.nentities(), len(data))
Example #9
0
def test_simple():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng)
    assert_equals(s.nentities(), len(data))
Example #10
0
def test_simple():
    N, V = 10, 100
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = numpy_dataview(data)
    R = rng()
    s = initialize(defn, view, R)
    assert_equals(s.nentities(), len(data))
Example #11
0
def test_runner_specify_basic_kernel():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    latent = model.initialize(defn, view, prng)
    r = runner.runner(defn, view, latent, ["crf"])
    r.run(prng, 1)
Example #12
0
def test_runner_simple():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    latent = model.initialize(defn, view, prng)
    r = runner.runner(defn, view, latent)
    r.run(prng, 1)
Example #13
0
def test_runner_simple():
    N, V = 10, 100
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = numpy_dataview(data)
    prng = rng()
    latent = model.initialize(defn, view, prng)
    kc = runner.default_kernel_config(defn)
    r = runner.runner(defn, view, latent, kc)
    r.run(prng, 1)
Example #14
0
def test_serialize_simple():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng)
    m = s.serialize()
    s2 = deserialize(defn, m)
    assert s2.__class__ == s.__class__
Example #15
0
def test_runner_specify_hp_kernels():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    latent = model.initialize(defn, view, prng)
    kernels = ['crf'] + \
        runner.second_dp_hp_kernel_config(defn) + \
        runner.base_dp_hp_kernel_config(defn)
    r = runner.runner(defn, view, latent, kernels)
    r.run(prng, 1)
Example #16
0
def test_runner_second_dp_valid():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    prng = rng()
    latent = model.initialize(defn, data, prng)
    old_beta = latent.beta
    old_gamma = latent.gamma
    kernels = ['crf'] + \
        runner.second_dp_hp_kernel_config(defn)
    r = runner.runner(defn, data, latent, kernels)
    r.run(prng, 10)
    assert_almost_equals(latent.beta, old_beta)
    assert_almost_equals(latent.gamma, old_gamma)
    assert latent.alpha > 0
Example #17
0
def test_serialize_pickle():
    N, V = 10, 20
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = data
    prng = rng()
    s = initialize(defn, view, prng)
    # Pickle
    bstr = pickle.dumps(s)
    s2 = pickle.loads(bstr)
    assert s2.__class__ == s.__class__

    # cPickle
    bstr = cPickle.dumps(s)
    s2 = cPickle.loads(bstr)
    assert s2.__class__ == s.__class__
Example #18
0
def test_explicit():
    N, V = 5, 100
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = numpy_dataview(data)
    R = rng()

    table_assignments = [
        np.random.randint(low=0, high=10, size=len(d)) for d in data]

    dish_assignments = [
        np.random.randint(low=0, high=len(t)) for t in table_assignments]

    s = initialize(defn, view, R,
        table_assignments=table_assignments,
        dish_assignments=dish_assignments)
    assert_equals(s.nentities(), len(data))
Example #19
0
def test_explicit():
    N, V = 5, 100
    defn = model_definition(N, V)
    data = toy_dataset(defn)
    view = numpy_dataview(data)
    R = rng()

    table_assignments = [
        np.random.randint(low=0, high=10, size=len(d)) for d in data
    ]

    dish_assignments = [
        np.random.randint(low=0, high=len(t)) for t in table_assignments
    ]

    s = initialize(defn,
                   view,
                   R,
                   table_assignments=table_assignments,
                   dish_assignments=dish_assignments)
    assert_equals(s.nentities(), len(data))