예제 #1
0
 def test_norm_diff(self):
     """norm_diff should calculate per-element rms difference"""     
     m =  array([[1.0,2,3],[4,5,6], [7,8,9]])
     m2 = array([[1.0,1,4],[2,6,-1],[8,6,-5]])
     #matrix should not be different from itself
     self.assertEqual(norm_diff(m,m), 0.0)
     self.assertEqual(norm_diff(m2,m2), 0.0)
     #difference should be same either direction
     self.assertEqual(norm_diff(m,m2), sqrt(257.0)/9)
     self.assertEqual(norm_diff(m2,m), sqrt(257.0)/9)
예제 #2
0
파일: usage.py 프로젝트: miklou/pycogent
def test_heuristics(p_range=None, num_to_do=71, heuristics=None):
    if p_range is None:
        p_range = [0.6]
    if heuristics is None:
        heuristics = [
            'fixNegsDiag', 'fixNegsEven', 'fixNegsReflect',
            'fixNegsConstrainedOpt'
        ]
    num_heuristics = len(heuristics)
    print '\t'.join(['p'] + heuristics)
    for p in p_range:
        result = zeros((num_to_do, num_heuristics), Float64)
        has_nonzero = 0
        i = 0
        while i < num_to_do:
            curr_row = result[i]
            random_p = Probs.random(DnaPairs, p)
            q = random_p.toRates()
            if not q.hasNegOffDiags():
                continue
            has_nonzero += 1
            #print "P:"
            #print random_p._data
            #print "Q:"
            #print q._data
            i += 1
            for j, h in enumerate(heuristics):
                #print "HEURISTIC: ", h
                q_corr = getattr(q, h)()
                #print "CORRECTED Q: "
                #print q_corr._data
                p_corr = expm(q_corr._data)(t=1)
                #print "CORRECTED P:"
                #print p_corr
                dist = norm_diff(p_corr, random_p._data)
                #print "DISTANCE: ", dist
                curr_row[j] = dist
        averages = average(result)
        print p, '\t', '\t'.join(map(str, averages))
예제 #3
0
파일: usage.py 프로젝트: miklou/pycogent
def test_heuristics(p_range=None, num_to_do=71, heuristics=None):
    if p_range is None:
        p_range = [0.6]
    if heuristics is None:
        heuristics = ['fixNegsDiag', 'fixNegsEven', 'fixNegsReflect', 'fixNegsConstrainedOpt']
    num_heuristics = len(heuristics)
    print '\t'.join(['p'] + heuristics)
    for p in p_range:
        result = zeros((num_to_do, num_heuristics), Float64)
        has_nonzero = 0
        i = 0
        while i < num_to_do:
            curr_row = result[i]
            random_p = Probs.random(DnaPairs, p)
            q = random_p.toRates()
            if not q.hasNegOffDiags():
                continue
            has_nonzero += 1
            #print "P:"
            #print random_p._data
            #print "Q:"
            #print q._data
            i += 1
            for j, h in enumerate(heuristics):
                #print "HEURISTIC: ", h
                q_corr = getattr(q, h)()
                #print "CORRECTED Q: "
                #print q_corr._data
                p_corr = expm(q_corr._data)(t=1)
                #print "CORRECTED P:"
                #print p_corr
                dist = norm_diff(p_corr, random_p._data)
                #print "DISTANCE: ", dist
                curr_row[j] = dist
        averages = average(result)
        print p, '\t', '\t'.join(map(str, averages))