Пример #1
0
    def test_log_probability_list(self):
        c = dna.DNA(id="ADADAD", seq='ACTTTAAACCC')
        c.calculate_signature()
        d = dna.DNA(id="ADADAD", seq='ACTTTACGAACCC')
        d.calculate_signature()
        dna_l = [c,d]
        alpha = [3.0]*c.kmer_hash_count

        sig_mat = np.zeros((2,c.kmer_hash_count))
        for key,cnt in c.signature.iteritems():
            sig_mat[0,key] += cnt

        for key,cnt in d.signature.iteritems():
            sig_mat[1,key] += cnt

        p = model.neg_log_probability_l(alpha,sig_mat,2,np.array([10,8]))
        assert_almost_equal(p,88.31776,places=4)
Пример #2
0
    def test_log_probability_without_fit(self):
        # Example from figure:
        # http://en.wikipedia.org/wiki/File:Beta-binomial_distribution_pmf.png
        c = dna.DNA(id="ADADAD",seq='ACTTTAAACCC')

        signature = np.array([6,4])

        alpha = np.array([600,400])
        p = model.log_probability_test(signature,alpha)
        # 10 choose 6 = 210
        assert_almost_equal(p + np.log(210),-1.38799, places=3)


        signature_m = np.zeros((1,2))
        signature_m[0,:] = np.array([6,4])

        p2 = model.neg_log_probability_l(alpha,signature_m,1,10)
        assert_almost_equal(-p2+np.log(210),-1.38799, places=3)