def restored(A): """ @param A: full rank symmetric matrix whose rows sum to 1 @return: a doubly centered but otherwise full rank matrix """ assert_symmetric(A) n = A.shape[0] return A - ones_like(A) / n
def get_selection_S(F): """ The F and S notation is from Yang and Nielsen 2008. @param F: a selection value for each codon, up to an additive constant @return: selection differences F_j - F_i, also known as S_ij """ e = algopy.ones_like(F) return algopy.outer(e, F) - algopy.outer(F, e)
def augmented(A): """ @param A: doubly centered symmetric nxn matrix of rank n-1 @return: full rank symmetric matrix whose rows sum to 1 """ assert_square(A) n = A.shape[0] #assert_allclose(dot(ones(n), A), zeros(n), atol=1e-12) #assert_allclose(dot(A, ones(n)), zeros(n), atol=1e-12) return A + ones_like(A) / n
def get_selection_S(F): """ The F and S notation is from Yang and Nielsen 2008. Speed matters. @param F: a selection value for each codon, up to an additive constant @return: selection differences F_j - F_i, also known as S_ij """ # FIXME: use algopy.ones_like when it becomes available e = algopy.ones_like(F) # # FIXME: instead of the following block # e = algopy.zeros_like(F) # for i in range(F.shape[0]): # e[i] = 1. return algopy.outer(e, F) - algopy.outer(F, e)