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()
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)
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
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))
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))
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)
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)
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)
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__
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)
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
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__
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))
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))