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)
Esempio n. 2
0
def test_get_saddles():
    ## test on two independent toggle switches
    N, L, Delta, theta, gamma = two_independent_toggles()
    RS = RampSystem(N, L, Delta, theta, gamma)
    # loop characteristic cell with only first loop
    LCC = Cell(RS.theta, 1, 0, (3, np.inf), (-np.inf, 2))
    saddles = get_saddles(RS, LCC)
    CFS = CyclicFeedbackSystem(*neg_edge_toggle())
    CFS_saddles, eps_func = CFS.get_bifurcations()
    s = sympy.symbols('s')
    expected_saddle_val = np.zeros([4, 1])
    CFS_saddle_val = CFS_saddles[0][0][1]
    expected_saddle_val = np.array([[CFS_saddle_val[0, 0]],
                                    [CFS_saddle_val[1, 0]],
                                    [L[3, 2] + Delta[3, 2]], [L[2, 3]]])
    for saddle in saddles[(0, 1)]:
        eps = saddle[2].subs(s, saddle[0])
        assert (np.allclose(RS(saddle[1][0], eps), np.zeros([4, 1])))
        assert (np.array_equal(saddle[1][0], expected_saddle_val))
    # LCC with both loops
    LCC = Cell(RS.theta, 1, 0, 3, 2)
    saddles = get_saddles(RS, LCC)
    assert (len(saddles[(0, 1)]) == 3)
    assert (len(saddles[(2, 3)]) == 3)

    ## test that throwing out bifurcations that occur past weak equivalence are thrown out
    N, L, Delta, theta, gamma = almost_two_independent_toggles()
    RS = RampSystem(N, L, Delta, theta, gamma)
    LCC = Cell(RS.theta, 1, 0, (3, np.inf), (-np.inf, 2))
    saddles = get_saddles(RS, LCC)
    assert (len(saddles[(0, 1)]) == 0)
    theta[2, 0] = .3
    Delta[2, 0] = .5
    theta[3, 2] = 1.1
    RS = RampSystem(N, L, Delta, theta, gamma)
    LCC.theta = RS.theta
    saddles = get_saddles(RS, LCC)
    assert (len(saddles[(0, 1)]) == 1)
Esempio n. 3
0
    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))