def test_log_pdf(self):
        mu = np.log(np.array([[0.5,3.0,5.0]]))
        sigma = 0.5
        x = np.log(np.array([[0.5,3.0,5.0]]))
        p = model.pdf(x,mu,sigma)
        p_test = model.log_pdf(x,mu,sigma)

        assert_almost_equal(np.log(p),p_test)
Example #2
0
    def test_log_probability(self):
        f = fileinput.input(os.path.join(data_path,"bambus2.scaffold.linear.fasta.one_contig"))
        c = list(SeqIO.parse(f,"fasta"))
        f.close()
        
        dna_c = dna.DNA(id = c[0].id, seq = str(c[0].seq))
        dna_c.calculate_signature()
        k = 4**4
        uniform_prob = np.ones((dna.DNA.kmer_hash_count))
        for i,cnt in dna_c.signature.items():
            uniform_prob[i] = 1./k
        log_prob = ml.log_probability(dna_c,uniform_prob)

        mu = np.log(np.array([0.5,3.0,5.0]))
        sigma = 0.5
        x = np.log(np.array([0.5,3.0,5.0]))
        cov_matrix = np.array([x])

        p_ig = ig.log_pdf(x,mu,sigma)
        p_test = model.log_probability(dna_c,cov_matrix,uniform_prob,mu,sigma)
        assert_equal(p_ig+log_prob,p_test)
Example #3
0
def log_probability(seq,cov_matrix,prob_vector,mu,sigma,factor=1):
    ig_p = isotropic_gaussian.log_pdf(cov_matrix,mu,sigma)
    mu_p = multinomial.log_probability(seq,prob_vector)
    return ig_p*factor+mu_p