<jupyter_start><jupyter_text><jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import optimize
def run_ou_process(gamma,gr0,Dgr,tmax,*,dt = 0.01):
    gr = [1]
    v = [1]
    t = [0]
    while t[-1] < tmax:
        gr_new = gr[-1]+gamma*(gr0-gr[-1])*dt + np.sqrt(dt*Dgr)*np.random.normal(0,1)
        gr.append(gr_new)
        v.append(v[-1]+v[-1]*gr[-1]*dt)
        if v[-1]>2+np.random.normal(0,0.2):
            v[-1] = v[-1]/2
        t.append(t[-1]+dt)
        
    return np.array(gr),np.array(v),np.array(t)

def run_constant_process(gamma,gr0,Dgr,tmax,*,dt = 0.01):
    gr = [1]
    v = [1]
    t = [0]
    while t[-1] < tmax:
        gr_new = gr[-1]
        gr.append(gr_new)
        v.append(v[-1]+v[-1]*gr[-1]*dt)
        if v[-1]>2+np.random.normal(0,0.2):
            v[-1] = v[-1]/2
            gr[-1] = gr0 + np.random.normal(0,0.2)
        t.append(t[-1]+dt)
        
    return np.array(gr),np.array(v),np.array(t)
gr_ou,v_ou,t_ou = run_ou_process(10,1,0.2,5)
gr_c,v_c,t_c = run_constant_process(1,1,0.2,5)
fig,axs = plt.subplots(nrows = 2,figsize=(5,4),sharex=True,sharey=True)
ax = axs[0]
ax.plot(t_c,gr_c,label=r'$\lambda$',linewidth=4)
ax.plot(t_c,v_c,'k-',label=r'$v$')
ax.legend(frameon=False)
ax.set_ylim([0,3])

ax = axs[1]
ax.plot(t_ou,gr_ou,linewidth=4)
ax.plot(t_ou,v_ou,'k-')
ax.set_xlabel('Time')
plt.tight_layout()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.2180028129395218, 'fraction_numerical': 0.04992967651195499, 'mean_word_length': 3.089080459770115, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '236968', 'license': 'MIT', 'n_tokens_mistral': 689, 'n_tokens_neox': 676, 'n_words': 85, 'path': 'growth_rate_variation.ipynb', 'repo_name': 'elevien/phenotypic_variability_review', 'size': '1422'}