def test_valid_run(self): def isvalid(probs): return probs.sum() <= 1.00001 and probs.sum() >= 0.99999 and \ (probs > 0).all() and \ (probs < 1).all() annots = self.create_annots(test.SMALL_DEL_FILE) estimator = LDAEstimator(annots, 200, .001, .002, .003, 100, 50, 5, 0) gamma = np.arange(5) prob_items = estimator.prob_items(gamma) prob_items_tag = estimator.prob_items_given_tag(0, gamma) prob_items_user = estimator.prob_items_given_user(0, gamma) prob_items_user_tag = estimator.prob_items_given_user_tag(0, 0, gamma) self.assertTrue(isvalid(prob_items)) self.assertTrue(isvalid(prob_items_tag)) self.assertTrue(isvalid(prob_items_user)) self.assertTrue(isvalid(prob_items_user_tag)) self.assertTrue(estimator.chain_likelihood().all()) self.assertTrue((estimator._get_user_topic_prb() >= 0).all()) self.assertTrue((estimator._get_topic_document_prb() >= 0).all()) self.assertTrue((estimator._get_topic_term_prb() >= 0).all()) self.assertTrue((estimator._get_user_topic_prb() <= 1).all()) self.assertTrue((estimator._get_topic_document_prb() <= 1).all()) self.assertTrue((estimator._get_topic_term_prb() <= 1).all()) self.assertTrue((estimator._get_user_topic_prb()).any()) self.assertTrue((estimator._get_topic_document_prb()).any()) self.assertTrue((estimator._get_topic_term_prb()).any())
def test_valid_probabilities(self): def isvalid(probs): return probs.sum() <= 1.00001 and probs.sum() >= 0.99999 and \ (probs > 0).all() and \ (probs < 1).all() annots = self.create_annots(test.SMALL_DEL_FILE) estimator = LDAEstimator(annots, 2, .1, .2, .3, 2, 0, 1, 0) gamma = np.arange(5) prob_items = estimator.prob_items(gamma) prob_items_tag = estimator.prob_items_given_tag(0, gamma) prob_items_user = estimator.prob_items_given_user(0, gamma) prob_items_user_tag = estimator.prob_items_given_user_tag(0, 0, gamma) self.assertTrue(isvalid(prob_items)) self.assertTrue(isvalid(prob_items_tag)) self.assertTrue(isvalid(prob_items_user)) self.assertTrue(isvalid(prob_items_user_tag))