@@ -0,0 +1,1740 @@
+import numpy as np%0A%0Adef normalize_basic(p):%0A    p /= p.sum(axis=p.size%5B-1%5D, keepdims=True)%0A%0Adef plsa(doc_term, n_topics, n_iter, method='basic'):%0A    # Get size%0A    n_docs, n_terms = doc_term.size%0A%0A    # Initialize distributions%0A    topic_doc = np.random.rand(n_docs, n_topics)%0A    normalize_basic(topic_doc)%0A%0A    term_topic = np.random.rand(n_topics, n_terms)%0A    normalize_basic(term_topic)%0A%0A    # Run pLSA algorithm%0A    if method == 'basic':%0A        return plsa_basic(doc_term, topic_doc, term_topic, n_iter)%0A    else:%0A        raise ValueError('Unrecognized method %3C%7B0%7D%3E'.format(method))%0A%0Adef plsa_basic(doc_term, topic_doc, term_topic, n_iter):%0A        n_docs, n_topics, n_terms = topic_doc.shape + %5Bterm_topic.shape%5B1%5D%5D%0A        print %22%22%22%0A            Running basic pLSA algorithm%0A            ============================%0A            Number of iterations: %7B0%7D%0A            Number of documents: %7B1%7D%0A            Number of terms: %7B2%7D%0A            Number of topics: %7B3%7D%0A            ============================%0A        %22%22%22.format(n_iter, n_docs, n_terms, n_topics)%0A%0A        for i in range(n_iter):%0A            print %22Running iteration %7B0%7D%22.format(i)%0A            ### Expectation ###%0A            topic_full = topic_doc%5B:, np.newaxis, :%5D * term_topic.T%0A            normalize_basic(topic_full)%0A            ### Maximization ###%0A            # Compute full likelihood table%0A            dist_table = doc_term%5B:, :, np.newaxis%5D * topic_full%0A            # Marginalize out documents%0A            term_topic = np.sum(dist_table, axis=0).T%0A            normalize_basic(term_topic)%0A            # Marginalize out terms%0A            topic_doc = np.sum(dist_table, axis=1)%0A            normalize_basic(topic_doc)%0A%0A        return topic_full, topic_doc, term_topic%0A%0A

Add basic numpy pLSA implementation