# Add the model parameters k1 = r1.parameter('k1', value=2.0, bounds=(0.0, 5.0), fixed=False) k2 = r1.parameter('k2', value=0.2, bounds=(0.0, 2.0), fixed=False) # Declare the components and give the initial values A = r1.component('A', value=0.001, variance=1e-10, known=False, bounds=(0.0, 3)) B = r1.component('B', value=0.0, variance=1e-11) C = r1.component('C', value=0.0, variance=1e-8) # Use this function to replace the old filename set-up filename = 'data/Ex_1_C_data.txt' full_data = kipet.read_data(filename) r1.add_data(data=full_data.iloc[::10, :], remove_negatives=True) # Define the reaction model r1.add_ode('A', -k1 * A) r1.add_ode('B', k1 * A - k2 * B) r1.add_ode('C', k2 * B) # Settings r1.settings.collocation.nfe = 60 r1.settings.parameter_estimator.covairance = 'k_aug' # Run KIPET r1.run_opt() # Display the results
# Z_in = dict() # Z_in["t=5"] = [0,0,5] r1.unwanted_contribution('time_invariant_G') # Run KIPET r1.run_opt() r1.results.show_parameters if with_plots: r1.report() """We can now compare the results with the known profiles""" # Read the true S to compare with results S_true_filename = 'data/S_True_for_unwanted_G.csv' S_True = kipet.read_data(S_true_filename) # In this example, we know the magnitude of unwanted contribution. # Therefore, we can calculate the matched S according to "" to compare the results. index = list(S_True.index) column = list(S_True.columns) data = [] for i in index: sgi = 2.5E-6 * i / 0.01 row = [sgi, sgi, sgi] data.append(row) Sg = pd.DataFrame(data, columns=column, index=index) S_matched = S_True + Sg # Make sure the columns have the same names as in the original S_matched.columns = ['A', 'B', 'C']
r1 = kipet.ReactionModel('reaction-1') # Add the model parameters k1 = r1.parameter('k1', value=4.0, bounds=(0.0, 5.0)) k2 = r1.parameter('k2', value=0.5, bounds=(0.0, 2.0)) # Declare the components and give the initial values A = r1.component('A', value=1e-3) B = r1.component('B', value=0.0) C = r1.component('C', value=0.0) # Input data file_name = 'data/Dij.txt' r1.add_data(category='spectral', file=file_name) a_data = kipet.read_data('data/uplc.csv') a_data = a_data[['A']] a_data.columns = ['y'] #r1.add_data('y_data', data=a_data) #r1.add_data(category='uplc', file='data/uplc.csv') # Input the reactions as expressions rA = r1.add_reaction('rA', k1*A) rB = r1.add_reaction('rB', k2*B) # Input the ODEs r1.add_ode('A', -rA ) r1.add_ode('B', rA - rB ) r1.add_ode('C', rB )
""" import sys import kipet if __name__ == "__main__": with_plots = True if len(sys.argv) == 2 and int(sys.argv[1]): with_plots = False r1 = kipet.ReactionModel('reaction-1') r1.unit_base.time = 's' full_data = kipet.read_data('data/ratios.csv') # Add the model parameters k1 = r1.parameter('k1', value=2, bounds=(0.0, 10.0), units='1/s') k2 = r1.parameter('k2', value=0.2, bounds=(0.0, 10.0), units='1/s') # Declare the components and give the valueial values A = r1.component('A', value=1.0, units='mol/l') B = r1.component('B', value=0.0, units='mol/l') C = r1.component('C', value=0.0, units='mol/l') # The following has been automated throught the add_expression method #y = r1.algebraic('y', description='Ratio of B to B + C') r1.add_data('C_data', data=full_data[['A']], remove_negatives=True) r1.add_data('y_data', data=full_data[['y']])