<jupyter_start><jupyter_text>Mean Curve FitThis is the simpler model use in this project to estimate kinetic parameters. The inferring process is achieved by a built-in Python function called *curve_fit*. This function performs a non linear regression based on least square error. To use this function one just needs the structural model of differential equations to be fitted. Despite that, the estimation performed here is homologous to the performed with the *Mean Cell model*.<jupyter_code>#required libraries
import simsysbio as s2b
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit<jupyter_output><empty_output><jupyter_text>**Loads data**. The data is loaded to save time computing a new whole population.<jupyter_code>tog = np.load("tog.npy")#input stimulus
hog = np.load("hog.npy")#time vector
Obs = np.load("MCobs.npy")#observations<jupyter_output><empty_output><jupyter_text>**Plots data to be estimated**<jupyter_code>plt.figure()
for i in range(len(Obs)):
    plt.plot(tog, Obs[i,:])
plt.xlabel('Time (min)')
plt.ylabel('Concentration')
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>**Sets biological system configuration**<jupyter_code>#molecular species
especies = ['mRNA', 'Proteína']

#Stoichiometric matrices
reactivos = np.array([[0, 1, 1, 0],[0, 0, 0, 1]])
productos = np.array([[1, 0, 1, 0],[0, 0, 1, 0]])

#kinetic parameters names
parametros = ['c1', 'c2', 'c3', 'c4']

#system input
entrada = 'U'
idxR = 0

#computes simbolic system of differential equations
ecuaciones, variables = s2b.simbODE(especies, reactivos, productos, parametros,
                                   inputN=entrada)
#kinetic parameters 
parsValues = [4.0, 0.010, 1.0, 0.006]

#initial concentrations
sp0 = np.zeros(len(especies))

#initial noise measurement guess
noise = np.array([0,0])

#regressor variables
regressor = {
        "ODEs": ecuaciones,
        "matrizR": reactivos,
        "matrizP": productos,
        "vPars": parsValues,
        "idxR": idxR,
        "inpU": hog,
        "Vtime": tog,
        "species0":sp0,
        "noise":noise
        }
regressor.update(variables)<jupyter_output><empty_output><jupyter_text>**Inferring process**<jupyter_code>#initial parameters guesses
beta0 = np.array([2.056, 0.038, 0.187, 0.184])

#mean observations curve
uObs = np.mean(Obs, axis=0)
#modifies ode solver function
def ODEfit(regressor, *pars):
    print(pars)
    cellExpr = s2b.solveODE(pars, regressor)
    return cellExpr[-1,:]


#Performs estimation
betacal, cov = curve_fit(ODEfit, regressor, uObs, beta0)
#simulates curve with inferred parameters
cellCal = s2b.solveODE(betacal, regressor)<jupyter_output><empty_output><jupyter_text>**Comparates initial curve and inferred curve**<jupyter_code>plt.figure()
plt.plot(tog, uObs, label="Observed Curve")
plt.plot(tog, cellCal[-1,:], label="Inferred Curve")
plt.legend(loc='best')
plt.xlabel('Time (min)')
plt.ylabel('Concentration')
plt.grid()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1291181364392679, 'fraction_numerical': 0.020965058236272878, 'mean_word_length': 5.172484599589322, 'pattern_counts': {'":': 9, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '541498', 'license': 'MIT', 'n_tokens_mistral': 1124, 'n_tokens_neox': 1034, 'n_words': 274, 'path': 'Inference_Models/MeanCurveFit.ipynb', 'repo_name': 'Jebrayam/systemsbiology', 'size': '3005'}