コード例 #1
0
def checkMatrix(m, fV, AS=4, reversible=True):
    #print m
    for i in xrange(0, AS):
        j = sum(m[i])
        #print "AAAAA", j
        assert j <= 1.0001
        assert j >= 0.9999
        if reversible:
            for k in xrange(0, AS):
                #print "comp2", (fV[i] * m[i][k]), (fV[k] * m[k][i] )
                assert misc.close(fV[i] * m[i][k], fV[k] * m[k][i], 0.00001)

    wV = fV
    wV2 = fV
    wV3 = transformByDistance(wV, m, AS)
    wV4 = transformByDistance(wV2, m, AS)
    i = sum(multiplyWV(wV2, wV3, AS))
    j = sum(multiplyWV(wV, wV4, AS))
    #print i, j
    assert misc.close(i, j, 0.00001)
コード例 #2
0
def subMatrix_HalpernBruno(d, freqColumn, subMatrix, AS=4):
    #return subMatrix_HKY(d, freqColumn[0], freqColumn[1], freqColumn[2], freqColumn[3], 2.0)
    #return subMatrix
    matrix = [[0.0] * AS for i in xrange(0, AS)]
    for i in xrange(0, AS):
        for j in xrange(0, AS):
            a = freqColumn[i] * subMatrix[i][j]
            b = freqColumn[j] * subMatrix[j][i]
            if not misc.close(a, b, 0.0001):
                matrix[i][j] = subMatrix[i][j] * (math.log(b / a) / (1 -
                                                                     (a / b)))
            else:
                matrix[i][j] = subMatrix[i][j]
    #for i in xrange(0, AS):
    #    #print matrix[i][i], sum(matrix[i])
    #    matrix[i][i] -= sum(matrix[i]) - 1.0
    #    assert matrix[i][i] >= 0
    #checkMatrix(matrix, freqColumn)
    return matrix