def zero_eig(result): """ Qff and Qaa cannot be singular. """ from dcprogs.likelihood import svd from numpy import all, any, abs try: singular = svd(result.aa)[1] except: return False if any(abs(singular) < 1e-8): return False try: singular = svd(result.ff)[1] except: return False return all(abs(singular) > 1e-8)
def zero_eig(result): from dcprogs.likelihood import svd from numpy import sum, abs try: U, sing, V = svd(result) except: return False else: return sum(abs(sing) < tolerance) == 1
def step(context): from dcprogs.likelihood import inv, svd from numpy import abs, all, dot, identity for matrix, idealg in zip(context.qmatrices, context.idealgs): occupancies = idealg.final_occupancies kernel = dot( dot(inv(matrix.ff), matrix.fa), dot(inv(matrix.aa), matrix.af) ) kernel = identity(kernel.shape[0]) - kernel U, singvals, V = svd(kernel) try: assert sum(abs(singvals) < context.tolerance) == 1 assert all(dot(occupancies, kernel) < context.tolerance) except: print(matrix) print("Equilibrium: {0}".format(occupancies)) print("Kernel Application: {0}".format(dot(occupancies, kernel))) raise
def step(context): from dcprogs.likelihood import inv, svd from numpy import abs, all, dot, identity for matrix, idealg in zip(context.qmatrices, context.idealgs): occupancies = idealg.final_occupancies kernel = dot(dot(inv(matrix.ff), matrix.fa), dot(inv(matrix.aa), matrix.af)) kernel = identity(kernel.shape[0]) - kernel U, singvals, V = svd(kernel) try: assert sum(abs(singvals) < context.tolerance) == 1 assert all(dot(occupancies, kernel) < context.tolerance) except: print(matrix) print("Equilibrium: {0}".format(occupancies)) print("Kernel Application: {0}".format(dot(occupancies, kernel))) raise
def step(context, name): from dcprogs.likelihood import svd from numpy import dot, identity, abs, all for qmatrix, G, occ in zip(context.qmatrices, context.likelihoods, context.occupancies): eqmatrix = dot(G.laplace_af(0), G.laplace_fa(0)) if name == "initial" \ else dot(G.laplace_fa(0), G.laplace_af(0)) eqmatrix -= identity(eqmatrix.shape[0]) left, sings, right = svd(eqmatrix) sings = sorted(sings) try: assert abs(sings[0]) < context.tolerance assert sings[0] < sings[1] + context.tolerance assert all(abs(dot(occ, eqmatrix)) < context.tolerance) except: print(G) print(" * occupancies: {0}".format(occ)) print(" * matrix:\n{0}".format(eqmatrix)) print(" * error: {0}".format(dot(occ, eqmatrix))) print(" * singular values: {0}".format(sings)) raise