C2MV commited on
Commit
706a649
1 Parent(s): 4ff26a2

Update interface.py

Browse files
Files changed (1) hide show
  1. interface.py +22 -8
interface.py CHANGED
@@ -156,10 +156,13 @@ class BioprocessModel:
156
  """
157
  if model_type not in self.models:
158
  raise ValueError(f"Model type '{model_type}' is not set. Please use set_model first.")
159
-
160
  func = self.models[model_type]['function']
161
  params = self.models[model_type]['params']
162
 
 
 
 
163
  # Define the fitting function based on model type
164
  if model_type == 'biomass':
165
  def fit_func(t, *args):
@@ -167,13 +170,24 @@ class BioprocessModel:
167
  else:
168
  def fit_func(t, *args):
169
  return func(t, *args)
170
-
171
- popt, _ = curve_fit(fit_func, time, data, bounds=bounds, maxfev=10000)
172
- self.params[model_type] = {param: val for param, val in zip(params, popt)}
173
- y_pred = fit_func(time, *popt)
174
- self.r2[model_type] = 1 - (np.sum((data - y_pred) ** 2) / np.sum((data - np.mean(data)) ** 2))
175
- self.rmse[model_type] = np.sqrt(mean_squared_error(data, y_pred))
176
- return y_pred
 
 
 
 
 
 
 
 
 
 
 
177
 
178
  def plot_combined_results(self, time, biomass, substrate, product,
179
  y_pred_biomass, y_pred_substrate, y_pred_product,
 
156
  """
157
  if model_type not in self.models:
158
  raise ValueError(f"Model type '{model_type}' is not set. Please use set_model first.")
159
+
160
  func = self.models[model_type]['function']
161
  params = self.models[model_type]['params']
162
 
163
+ # Depuración: Asegurarse de que los parámetros estén bien definidos
164
+ print(f"Fitting {model_type} model with function: {func} and parameters: {params}")
165
+
166
  # Define the fitting function based on model type
167
  if model_type == 'biomass':
168
  def fit_func(t, *args):
 
170
  else:
171
  def fit_func(t, *args):
172
  return func(t, *args)
173
+
174
+ # Depuración: Verificar el número de parámetros que se espera ajustar
175
+ print(f"Number of parameters to fit: {len(params)}")
176
+
177
+ try:
178
+ # Ajustar el modelo usando curve_fit
179
+ popt, _ = curve_fit(fit_func, time, data, bounds=bounds, maxfev=10000)
180
+ print(f"Optimal parameters found: {popt}")
181
+
182
+ # Guardar los parámetros ajustados en el modelo
183
+ self.params[model_type] = {param: val for param, val in zip(params, popt)}
184
+ y_pred = fit_func(time, *popt)
185
+ self.r2[model_type] = 1 - (np.sum((data - y_pred) ** 2) / np.sum((data - np.mean(data)) ** 2))
186
+ self.rmse[model_type] = np.sqrt(mean_squared_error(data, y_pred))
187
+ return y_pred
188
+ except Exception as e:
189
+ print(f"Error while fitting {model_type} model: {str(e)}")
190
+ raise
191
 
192
  def plot_combined_results(self, time, biomass, substrate, product,
193
  y_pred_biomass, y_pred_substrate, y_pred_product,