Exemple #1
0
def SPoCK_find_fixedpoints():
    pardict, fndict, vardict, icsdict = init_SPoCK()

    DSargs = dst.args()
    DSargs.pars = pardict
    DSargs.varspecs = vardict
    DSargs.fnspecs = fndict
    DSargs.ics = icsdict

    DSargs.name = 'SPoCK'
    DSargs.tdata = [0, 50000]
    DSargs.xdomain = {
        'X': [0, 10**9],
        'Y': [0, 10**9],
        'A': [0, 10**9],
        'B': [0, 10**9],
    }

    spock_ode = dst.Vode_ODEsystem(DSargs)
    jac_fun = make_jac_pydstool(spock_ode)

    fp_coords = pp.find_fixedpoints(spock_ode,
                                    n=10,
                                    eps=1e-50,
                                    jac=jac_fun,
                                    subdomain={
                                        'X': [0, 10**9],
                                        'Y': [0, 10**9],
                                        'A': [0, 10**9],
                                        'B': [0, 10**9]
                                    })
    fixedpoints_pdf_path = "/Users/behzakarkaria/Documents/UCL/Barnes Lab/PhD Project/research_code/SPoCK_model/parameter_csv/"

    plt.figure(1)
    fig, ax = plt.subplots(figsize=(18, 12.5))
    ax.set_xscale('symlog', basex=10)
    ax.set_yscale('symlog', basey=10)
    ax.set_ylim(0, 10**9)
    ax.set_xlim(0, 10**9)
    good_coords = []
    for fp in fp_coords:
        try:
            fp_obj = pp.fixedpoint_nD(
                spock_ode, dst.Point(fp), coords=fp, jac=jac_fun, eps=1e-20
            )  #Does he tolerance here matter when we find the points above with a good tolerance?
            good_coords.append(fp)
        except:
            continue

        if fp_obj.stability == 'u':
            style = 'wo'
        elif fp_obj.stability == 'c':
            style = 'co'
        else:  # 's'
            style = 'ko'

        print("")
        print(fp_obj.stability)
        print('X:', fp_obj.fp_coords['X'])
        print('Y:', fp_obj.fp_coords['Y'])
        print("")

        try:
            ax.plot(fp_obj.fp_coords['X'], fp_obj.fp_coords['Y'], style)

        except ValueError:
            continue

    plt.xlabel("X")
    plt.ylabel("Y")
    #plt.title('Fixed points \n w = 1*10**-2, D = 0.2 ')

    pdf_page_obj = PdfPages(fixedpoints_pdf_path + "fixedpoints_XY" + ".pdf")
    pdf_page_obj.savefig(ax.get_figure())
    pdf_page_obj.close()

    fixedpoints_csv_path = "/Users/behzakarkaria/Documents/UCL/Barnes Lab/PhD Project/research_code/SPoCK_model/parameter_csv/fixedponts.csv"
    fieldnames = ('index', 'X', 'Y', 'A', 'B')

    index = 0
    for fp_dict in good_coords:
        fp_dict['index'] = index
        index = index + 1

    data_frame = pd.DataFrame.from_records(good_coords)
    data_frame.to_csv(fixedpoints_csv_path)
Exemple #2
0
plt.plot(pts['t'], pts['y'], 'r', linewidth=2)

# figure 2 is the phase plane
plt.figure(2)
# phase plane tools are in the Toolbox module
from PyDSTool.Toolbox import phaseplane as pp

# plot vector field, using a scale exponent to ensure arrows are well spaced
# and sized
pp.plot_PP_vf(vdp, 'x', 'y', scale_exp=-1)

# only one fixed point, hence [0] at end.
# n=4 uses three starting points in the domain to find any fixed points, to an
# accuracy of eps=1e-8.
fp_coord = pp.find_fixedpoints(vdp, n=4, eps=1e-8)[0]
fp = pp.fixedpoint_2D(vdp, dst.Point(fp_coord), eps=1e-8)

# n=3 uses three starting points in the domain to find nullcline parts, to an
# accuracy of eps=1e-8, and a maximum step for the solver of 0.1 units.
# The fixed point found is also provided to help locate the nullclines.
nulls_x, nulls_y = pp.find_nullclines(vdp, 'x', 'y', n=3, eps=1e-8,
                                      max_step=0.1, fps=[fp_coord])


# plot the fixed point
pp.plot_PP_fps(fp)

# plot the nullclines
plt.plot(nulls_x[:,0], nulls_x[:,1], 'b')
plt.plot(nulls_y[:,0], nulls_y[:,1], 'g')
# n=3 uses three starting points in the domain to find nullcline parts, to an
# accuracy of eps=1e-8, and a maximum step for the solver of 0.1 units.
# The fixed points found is also provided to help locate the nullclines.
nulls_x, nulls_y = pp.find_nullclines(ode_sys,
                                      'phi',
                                      'nu',
                                      n=3,
                                      eps=1e-6,
                                      max_step=0.1,
                                      fps=fp_coords)

# plot the fixed points
fps = []
for fp_coord in fp_coords:
    fps.append(pp.fixedpoint_2D(ode_sys, dst.Point(fp_coord)))

for fp_obj in fps:
    plot_PP_fps_custom(fp_obj, do_evecs=True, markersize=7, flip_coords=True)

# plot the nullclines
plt.plot(nulls_x[:, 0], nulls_x[:, 1], 'b')
plt.plot(nulls_y[:, 0], nulls_y[:, 1], 'g')

plt.axis('tight')
plt.title('Phase plane')
plt.xlabel('phi')
plt.ylabel('nu')

# you may not need to run these commands on your system
plt.draw()
Exemple #4
0
g = pt.Par(0.01, "g")

M = [[-3, 0, -g, -5], [-5, -3, 0, -g], [-g, -5, -3, 0], [0, -g, -5, -3]]

net = make_system(M, [1, 1, 0.1, 0.1], [g])

net.set(tdata=[0, 20], algparams={"init_step": 0.01})

traj = net.compute('test')
pts = traj.sample()

display(pts)
plt.show()

origin = pt.Point({"x1": 0, "x2": 0, "x3": 0, "x4": 0})

fp = ptppfixedpoint_nD(net, origin)

print(fp.evals)
print(fp.stability)

## Continuation to explore stability
PC = pt.ContClass(net)

PCargs = args()
PCargs.name = "EQ1"
PCargs.type = "EP-C"
PCargs.freepars = ["g"]
PCargs.StepSize = 1e-3
PCargs.MaxNumPoints = 100