def test_pos_bifurcations(self): N, L, Delta, theta, gamma = self.neg_edge_toggle() cfs = CyclicFeedbackSystem(N, L, Delta, theta, gamma) s = sympy.symbols('s') eps_func = sympy.Matrix([[0, 1], [1, 0]]) * s x_eq = cfs.singular_equilibrium(eps_func, lambdify=False) zero_crossings = cfs.j_border_crossings(0, x_eq, eps_func) assert (len(zero_crossings) == 1) for crossing in zero_crossings: assert (np.allclose(crossing[0], .3162, rtol=1e-4)) assert (np.allclose(cfs(crossing[1], np.array([[0, .3162], [.3162, 0]])), np.zeros([2, 1]), atol=1e-4)) crossings, eps_func_out = cfs.border_crossings(eps_func) assert (eps_func_out == eps_func) assert (crossings[0][0][0] == zero_crossings[0][0]) assert (len(crossings[1]) == 1) for crossing in crossings[1]: assert (np.allclose(crossing[0], .67202)) assert (np.allclose(cfs(crossing[1], np.array([[0, .67202], [.67202, 0]])), np.zeros([2, 1]), atol=1e-4)) #get_bifurcations bifurcations = cfs.get_bifurcations(eps_func)[0] assert (not cfs.in_singular_domain( x_eq.subs(s, .37202), np.array([[0, .37202], [.37202, 0]]), 1)) assert (len(bifurcations[0]) == 1) for s_val in bifurcations[0]: assert (np.allclose(s_val[0], .3162, rtol=1e-4)) #make sure border_crossings runs on three nodes cfs = CyclicFeedbackSystem(*self.three_node_network()) crossings, eps_func = cfs.border_crossings() assert (True)
def test_cyclic_feedback_system_map(self): N, L, Delta, theta, gamma = self.neg_edge_toggle() L[0, 1] = .5 Delta[0, 1] = 1 theta[0, 1] = 1.3 L[1, 0] = .5 Delta[1, 0] = 1 theta[1, 0] = 1 gamma = [1, 1] the_map = RampToHillSaddleMap(N) CFS = CyclicFeedbackSystem(N, L, Delta, theta, gamma) #bifurcations = CFS.get_bifurcations(eps_func)[0] bifurcations, eps_func = CFS.get_bifurcations() assert (len(bifurcations[0]) == 1) for bifurcation in bifurcations[0]: hill_sys_parameter, x_hill = the_map.cyclic_feedback_system_map( CFS, bifurcation, eps_func, 0) assert (np.array_equal(CFS.Delta, hill_sys_parameter.Delta)) assert (np.array_equal(CFS.theta, hill_sys_parameter.theta)) assert (np.array_equal(hill_sys_parameter.sign, np.array([[0, -1], [-1, 0]]))) assert (np.allclose(hill_sys_parameter.L[0, 1], .6560, rtol=1e-2)) assert (np.allclose(hill_sys_parameter.L[1, 0], .5981, rtol=1e-2)) assert (np.allclose(hill_sys_parameter.n[0, 1], 12.1399, rtol=1e-2)) assert (np.allclose(hill_sys_parameter.n[1, 0], 10.2267, rtol=1e-2)) assert (np.allclose(x_hill, np.array([[.7958], [1.5098]]), rtol=1e-2)) hill_saddles = the_map.map_all_saddles(CFS, eps_func) assert (len(hill_saddles) == 1) assert (hill_saddles[0][0] == hill_sys_parameter) assert (hill_sys_parameter != HillSystemParameter( N, [[0, 1], [1, 0]], L, Delta, theta, [[0, 1], [1, 0]], gamma)) assert (np.array_equal(hill_saddles[0][1], x_hill)) gamma = [1.1, 0.9] CFS = CyclicFeedbackSystem(N, L, Delta, theta, gamma) crossings = CFS.border_crossings(eps_func)[0] bifurcations = CFS.get_bifurcations(eps_func)[0] assert (len(bifurcations[0]) == 1) assert (np.allclose(bifurcations[0][0][0], .45622, rtol=1e-4)) assert (np.allclose(bifurcations[0][0][1], np.array([[.54377], [1.66667]]), rtol=1e-4)) hill_sys_parameter, x_hill = the_map.cyclic_feedback_system_map( CFS, bifurcations[0][0], eps_func, 0) assert (np.allclose(hill_sys_parameter.L[0, 1], .77468, rtol=1e-4)) assert (np.allclose(hill_sys_parameter.L[1, 0], .5922, rtol=1e-4)) assert (np.allclose(x_hill, np.array([[.82535], [1.58024]]))) #three node map N, L, Delta, theta, gamma = self.three_node_network() CFS = CyclicFeedbackSystem(N, L, Delta, theta, gamma) saddles, eps_func = CFS.get_bifurcations() assert (len(saddles[0]) == 0) assert (len(saddles[1]) == 1) assert (len(saddles[2]) == 0) assert (len(saddles[3]) == 0) saddle = saddles[1][0] s_val = saddle[0] x = saddle[1] assert (np.allclose(s_val, .292402, rtol=1e-2)) assert (np.allclose(x, np.array([[1.171], [1.292402], [1.5]]), rtol=1e-3)) the_map = RampToHillSaddleMap(N) hill_saddles = the_map.map_all_saddles(CFS) assert (len(hill_saddles) == 1) hill_sys = hill_saddles[0][0] x_hill = hill_saddles[0][1] assert (hill_sys.is_saddle(x_hill))