def test_hdp_dense_input(): """Dense and sparse input should be the same""" X = make_uniform_doc_word_matrix(n_topics=10, words_per_topic=3, docs_per_topic=3) dense_X = X.todense() array_X = X.toarray() params = { 'n_topic_truncate': 20, 'n_doc_truncate': 5, 'learning_method': 'batch', 'max_iter': 10, 'random_state': 1, } hdp1 = HierarchicalDirichletProcess(**params) transformed_1 = hdp1.fit_transform(dense_X) hdp2 = HierarchicalDirichletProcess(**params) transformed_2 = hdp2.fit_transform(array_X) hdp3 = HierarchicalDirichletProcess(**params) transformed_3 = hdp3.fit_transform(X) assert_almost_equal(transformed_1, transformed_2) assert_almost_equal(transformed_2, transformed_3)
def test_likelihood_check(): """Test enable doc_likelihood check The result should be the same no matter it is True or False. """ X = make_uniform_doc_word_matrix(n_topics=10, words_per_topic=3, docs_per_topic=3) params = { 'n_topic_truncate': 20, 'n_doc_truncate': 5, 'learning_method': 'batch', 'max_iter': 10, 'random_state': 1, 'check_doc_likelihood': True, 'evaluate_every': 1, } hdp1 = HierarchicalDirichletProcess(**params) ret1 = hdp1.fit_transform(X) params['check_doc_likelihood'] = False hdp2 = HierarchicalDirichletProcess(**params) ret2 = hdp2.fit_transform(X) assert_almost_equal(ret1, ret2)
def test_hdp_fit_transform(): """Test HDP fit_transform""" X = make_uniform_doc_word_matrix(n_topics=10, words_per_topic=3, docs_per_topic=3) params = { 'n_topic_truncate': 20, 'n_doc_truncate': 5, 'learning_method': 'batch', 'max_iter': 10, 'random_state': 1, } hdp1 = HierarchicalDirichletProcess(**params) hdp1.fit(X) transformed_1 = hdp1.transform(X) hdp2 = HierarchicalDirichletProcess(**params) transformed_2 = hdp2.fit_transform(X) assert_almost_equal(transformed_1, transformed_2)