def test_simulate(): pops = simulate( model=logistic_map, num_gens=200, rate_min=3.7, rate_max=3.9, num_rates=100, num_discard=100, jit=True, ) assert type(pops) == pd.DataFrame assert pops.shape == (200, 100) pops = simulate( model=logistic_map, num_gens=200, rate_min=3.7, rate_max=3.9, num_rates=100, num_discard=100, jit=False, ) assert type(pops) == pd.DataFrame assert pops.shape == (200, 100)
def test_simulate(): pops = simulate(model=logistic_map, num_gens=200, rate_min=3.7, rate_max=3.9, num_rates=100, num_discard=100, jit=True) assert type(pops)==pd.DataFrame assert pops.shape==(200, 100) pops = simulate(model=logistic_map, num_gens=200, rate_min=3.7, rate_max=3.9, num_rates=100, num_discard=100, jit=False) assert type(pops)==pd.DataFrame assert pops.shape==(200, 100)
def test_bifurcation_plot(): pops = simulate(model=logistic_map, num_gens=200, rate_min=0, rate_max=4, num_rates=100, num_discard=100) assert type(pops)==pd.DataFrame assert pops.shape==(200, 100) # returns None bifurcation_plot(pops, save=True, folder=_img_folder, filename='')
def test_bifurcation_plot(): pops = simulate(model=logistic_map, num_gens=200, rate_min=0, rate_max=4, num_rates=100, num_discard=100) assert type(pops) == pd.DataFrame assert pops.shape == (200, 100) # returns None bifurcation_plot(pops, save=True, folder=_img_folder, filename='')
def test_phase_diagram_3d(): pops = simulate(model=cubic_map, num_gens=200, rate_min=3.5, num_rates=30, num_discard=100) assert type(pops)==pd.DataFrame assert pops.shape==(200, 30) # returns None phase_diagram_3d(pops, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, alpha=0.2, color='viridis', azim=330, legend=True, save=False, folder=_img_folder, filename='') # returns None phase_diagram_3d(pops, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, alpha=0.2, color='inferno', azim=330, legend=True, remove_ticks=False, save=False, folder=_img_folder, filename='')
def test_phase_diagram(): pops = simulate(model=singer_map, num_gens=200, rate_min=3.6, rate_max=4.0, num_rates=50, num_discard=100) assert type(pops)==pd.DataFrame assert pops.shape==(200, 50) # returns None phase_diagram(pops, xmin=0.25, xmax=0.75, ymin=0.8, ymax=1.01, size=7, discard_gens=10, color='b', color_reverse=True, legend=True, save=False, folder=_img_folder, filename='') fig_ax = phase_diagram(pops, xmin=0.25, xmax=0.75, ymin=0.8, ymax=1.01, size=7, discard_gens=10, color=['b', 'g'], legend=True, save=False, show=False, folder=_img_folder, filename='') assert type(fig_ax)==tuple
def test_phase_diagram_3d(): pops = simulate(model=cubic_map, num_gens=200, rate_min=3.5, num_rates=30, num_discard=100) assert type(pops) == pd.DataFrame assert pops.shape == (200, 30) # returns None phase_diagram_3d( pops, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, alpha=0.2, color="viridis", azim=330, legend=True, save=False, folder=_img_folder, filename="", ) # returns None phase_diagram_3d( pops, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, alpha=0.2, color="inferno", azim=330, legend=True, remove_ticks=False, save=False, folder=_img_folder, filename="", )
def test_phase_diagram(): pops = simulate(model=singer_map, num_gens=200, rate_min=3.6, rate_max=4.0, num_rates=50, num_discard=100) assert type(pops) == pd.DataFrame assert pops.shape == (200, 50) # returns None phase_diagram( pops, xmin=0.25, xmax=0.75, ymin=0.8, ymax=1.01, size=7, discard_gens=10, color="b", color_reverse=True, legend=True, save=False, folder=_img_folder, filename="", ) fig_ax = phase_diagram( pops, xmin=0.25, xmax=0.75, ymin=0.8, ymax=1.01, size=7, discard_gens=10, color=["b", "g"], legend=True, save=False, show=False, folder=_img_folder, filename="", ) assert type(fig_ax) == tuple
def test_phase_diagram(): pops = simulate(model=singer_map, num_gens=200, rate_min=3.6, rate_max=4.0, num_rates=50, num_discard=100) phase_diagram(pops, xmin=0.25, xmax=0.75, ymin=0.8, ymax=1.01, size=7, discard_gens=10, color='b', color_reverse=True, legend=True, save=False, folder=_img_folder, filename='') phase_diagram(pops, xmin=0.25, xmax=0.75, ymin=0.8, ymax=1.01, size=7, discard_gens=10, color=['b', 'g'], legend=True, save=False, show=False, folder=_img_folder, filename='')
def test_bifurcation_plot(): pops = simulate(model=logistic_map, num_gens=200, rate_min=0, rate_max=4, num_rates=100, num_discard=100) bifurcation_plot(pops, save=True, folder=_img_folder, filename='')
def test_simulate(): pops = simulate(model=logistic_map, num_gens=200, rate_min=3.7, rate_max=3.9, num_rates=100, num_discard=100, jit=True) pops = simulate(model=logistic_map, num_gens=200, rate_min=3.7, rate_max=3.9, num_rates=100, num_discard=100, jit=False)
import pynamical from pynamical import simulate, bifurcation_plot, save_fig import pandas as pd, numpy as np, IPython.display as display, matplotlib.pyplot as plt, matplotlib.cm as cm from pynamical import logistic_map, simulate, bifurcation_plot pops = simulate(model=logistic_map, num_gens=100, rate_min=0, rate_max=4, num_rates=1000, num_discard=100) bifurcation_plot(pops)
import pynamical from pynamical import simulate, bifurcation_plot, save_fig import pandas as pd, numpy as np, matplotlib.pyplot as plt, matplotlib.cm as cm pops = simulate(num_gens=100, rate_min=0., rate_max=3.5, num_rates=1000, num_discard=100) bifurcation_plot(pops, xmax=3.5, filename='logistic-map-bifurcation-1')
# ax.set_ylim(0, 1) # # ax.set_aspect('equal') # # ax.set_xlabel(r'$x_k$') # ax.set_ylabel(r'$x_{k+1}$') # # plt.savefig('../imgs/chaos_vs_randomness_phase_plane.pdf', bbox_inches='tight', dpi=300) pops = simulate(num_gens=100, rate_min=0, rate_max=4, num_rates=1000, num_discard=100, jit=True) pops = pops.as_matrix() mu = np.linspace(0, 4, 1000) fig = plt.figure(figsize=(fig_width, fig_width/3)) ax = fig.gca() for i in xrange(mu.size): ax.plot(mu[i]*np.ones_like(pops[:, i]), pops[:, i], ',', color='royalblue') # --> x-axis. ax.set_xlim(0, 4) ax.set_xlabel(r'$\mu$') # --> y-axis.
import pynamical from pynamical import simulate, bifurcation_plot, save_fig import pandas as pd, numpy as np, matplotlib.pyplot as plt, matplotlib.cm as cm # run the logistic model for 20 generations for 7 growth rates between 0.5 and 3.5 then view the output pops = simulate(num_gens=20, rate_min=0.6, rate_max=3.6, num_rates=7) pops.applymap(lambda x: '{:03.3f}'.format(x)) print(pops) pops.to_csv("C:/Projects/GitHub/sjanzou/pynamical/Paper/out3.6.csv", sep=',')
def test_phase_diagram_3d(): pops = simulate(model=cubic_map, num_gens=200, rate_min=3.5, num_rates=30, num_discard=100) phase_diagram_3d(pops, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, alpha=0.2, color='viridis', azim=330, legend=True, save=False, folder=_img_folder, filename='') phase_diagram_3d(pops, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1, alpha=0.2, color='inferno', azim=330, legend=True, remove_ticks=False, save=False, folder=_img_folder, filename='')
from pynamical import cobweb_plot, simulate, phase_diagram, bifurcation_plot from numba import jit @jit(nopython=True) def sine_map(x, r): return r * np.sin(np.pi * x) if __name__ == '__main__': pops = simulate(model=sine_map, num_gens=100, rate_min=0.6, rate_max=1, num_rates=1000, num_discard=100, jit=True) pops = pops.as_matrix() mu = np.linspace(0.6, 1, 1000) fig = plt.figure(figsize=(w, w / 3)) ax = fig.gca() for i in xrange(mu.size): ax.plot(mu[i] * np.ones_like(pops[:, i]), pops[:, i], ',', color='royalblue')
''' # Compute population size after breeding season based on y x = y * np.exp(rb - alpha_b * y ) # Compute population after breeding seasone ynew = x * np.exp(rnb - alpha_nb * x ) # Output new population size return ynew # Simulate to get bifurcation points bif_data_x = simulate(model=ricker_b, num_gens=100, rate_min=-0.5, rate_max=rbEmp, num_rates=1000, num_discard=100) bif_data_y = simulate(model=ricker_nb, num_gens=100, rate_min=-0.5, rate_max=rbEmp, num_rates=1000, num_discard=100) # Bifurcation plot bifurcation_plot(bif_data_x, title='Non-breeding population size', xmin=-0.5, xmax=rbEmp, ymin=0, ymax=500, save=False, xlabel='Breeding growth rate (rb)') bifurcation_plot(bif_data_y, title='Breeding population size', xmin=-0.5, xmax=rbEmp, ymin=0, ymax=500, save=False, xlabel='Breeding growth rate (rb)')
# Model parameters (from Betini et al. (2013)) kb = 224 # Carrying capacity for breeding period # Logistic model @jit(nopython=True) def logistic(x, rb): # Output new population size return x * (1 + rb * (1 - x / kb)) # Simulate to get bifurcation points bif_data = simulate(model=logistic, num_gens=100, rate_min=0.5, rate_max=5, num_rates=1000, num_discard=100) # Make plot of bifurcation bifurcation_plot(bif_data, title='Ricker Bifurcation Diagram', xmin=0, xmax=5, ymin=0, ymax=500, save=False) # Export bifurcation points bif_data.to_csv('../data_export/bif_data.csv')
from pynamical import logistic_map, simulate, bifurcation_plot pops = simulate(model=logistic_map, num_gens=100, rate_min=0, rate_max=4, num_rates=1000, num_discard=100) bifurcation_plot(pops) pops = simulate(model=logistic_map, num_gens=100, rate_min=3.7, rate_max=3.9, num_rates=1000, num_discard=100) bifurcation_plot(pops, xmin=3.7, xmax=3.9) from pynamical import cubic_map, phase_diagram_3d pops = simulate(model=cubic_map, num_gens=3000, rate_min=3.5, num_rates=30, num_discard=100) phase_diagram_3d(pops, xmin=-1, xmax=1, ymin=-1, ymax=1, zmin=-1, zmax=1,
''' # Compute population size after non-breeding season based on x y = x * (1 + rnb * (1 - x / knb)) # Compute population after breeding season xnew = y * (1 + (rb - a * x) * (1 - y / kb)) # Output new population size return xnew # Simulate to get bifurcation points bif_data_x = simulate(model=ricker_b, num_gens=100, rate_min=0.5, rate_max=5, num_rates=1000, num_discard=100) # Obtain population size after non-breeding season by direct map from X_{t+1} to Y_{t+1} def x_to_y(x): return x * np.exp(rnb * (1 - x / knb)) # Compute bifurcation points for y by mapping from x bif_data_y = x_to_y(bif_data_x) # Make plot of bifurcation bifurcation_plot(bif_data_x, title='Ricker Bifurcation Diagram',
@jit(cache=True, nopython=True) # pragma: no cover def map2(x, r): """ Define the equation for the cubic map. Arguments --------- x: float current population value at time t rate: float growth rate parameter values Returns ------- float result of map at time t+1 """ return r - x - np.exp(x) x = simulate(model=map2, num_gens=100, initial_pop=1, rate_min=0, rate_max=5, num_rates=2000, num_discard=100) bifurcation_plot(x, xmin=-10, xmax=10, ymin=-10, ymax=10)