pypharm 1.3.1__tar.gz → 1.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pypharm
3
- Version: 1.3.1
3
+ Version: 1.3.3
4
4
  Summary: Module for solving pharmacokinetic problems
5
5
  Home-page: https://github.com/Krash13/PyPharm
6
6
  Author: Krash13
@@ -2,7 +2,7 @@ from multiprocessing import shared_memory
2
2
 
3
3
  import numpy as np
4
4
  from scipy.integrate import solve_ivp, RK45
5
- from scipy.integrate._ivp.rk import rk_step, SAFETY, MAX_FACTOR, MIN_FACTOR
5
+ from scipy.integrate import simps
6
6
  from scipy.optimize import minimize
7
7
  from .country_optimization import CountriesAlgorithm
8
8
  from .country_optimization_v2 import CountriesAlgorithm_v2
@@ -129,7 +129,22 @@ class BaseCompartmentModel:
129
129
  t_eval=t_eval
130
130
  )
131
131
  return self.last_result
132
-
132
+
133
+ def get_kinetic_params(self, t_max, d, compartment_number, max_step=0.01):
134
+ one_hour_result = self(t_max=1, d=d, compartment_number=compartment_number, max_step=max_step)
135
+ auc_1h = simps(one_hour_result.y[compartment_number], one_hour_result.t)
136
+ self(t_max=t_max, d=d, compartment_number=compartment_number, max_step=max_step)
137
+ auc = simps(self.last_result.y[compartment_number], self.last_result.t)
138
+ result_dict = {
139
+ 'c_max': self.last_result.y[compartment_number].max(),
140
+ 'V': self.volumes[compartment_number] if self.volumes is not None else None,
141
+ 'AUC': auc,
142
+ 'AUC_1h': auc_1h,
143
+ 'Cl': d / auc
144
+ }
145
+ return result_dict
146
+
147
+
133
148
  def load_data_from_list(self, x):
134
149
  if self.configuration_matrix_target:
135
150
  self.configuration_matrix[self.configuration_matrix_target] = x[:self.configuration_matrix_target_count]
@@ -323,7 +338,7 @@ class ReleaseCompartmentModel(BaseCompartmentModel):
323
338
 
324
339
  need_v_release_optimization = False
325
340
  release_parameters_target = None
326
- release_parameters_target = None
341
+ accumulation_parameters_target = None
327
342
 
328
343
  class ReleaseRK45(RK45):
329
344
 
@@ -496,6 +511,15 @@ class ReleaseCompartmentModel(BaseCompartmentModel):
496
511
  accumulation_type=self.accumulation_type,
497
512
  c0=c0
498
513
  )
514
+ self.last_result.model_realized = c0 - self.get_release_function()(self.last_result.t, c0)
515
+ if self.with_accumulate:
516
+ model_accumulation = self.get_accumulation_function()(self.last_result.t, c0)
517
+ if self.accumulation_type == 1:
518
+ self.last_result.model_realized = model_accumulation - self.get_release_function()(self.last_result.t, c0)
519
+ elif self.accumulation_type == 2:
520
+ accumulation_coeffs = model_accumulation / c0
521
+ self.last_result.model_realized= accumulation_coeffs * self.get_release_function()(self.last_result.t, c0)
522
+ self.last_result.model_realized = model_accumulation - self.last_result.model_realized
499
523
  return self.last_result
500
524
 
501
525
  def _target_function(self, x, max_step=0.01, metric='R2'):
@@ -523,29 +547,13 @@ class ReleaseCompartmentModel(BaseCompartmentModel):
523
547
  if metric == 'R2':
524
548
  plus = 0
525
549
  if self.teoretic_realized is not None:
526
- model_realized = c0 - self.get_release_function()(self.teoretic_x, c0)
527
- if self.with_accumulate:
528
- model_accumulation = self.get_accumulation_function()(self.teoretic_x, c0)
529
- if self.accumulation_type == 1:
530
- model_realized = model_accumulation - self.get_release_function()(self.teoretic_x, c0)
531
- elif self.accumulation_type == 2:
532
- accumulation_coeffs = model_accumulation / c0
533
- model_realized = accumulation_coeffs * self.get_release_function()(self.teoretic_x, c0)
534
- model_realized = model_accumulation - model_realized
550
+ model_realized = self.last_result.model_realized
535
551
  plus = np.sum(((model_realized - self.teoretic_realized) ** 2) / ((self.teoretic_realized - self.teoretic_realized_avg) ** 2))
536
552
  return plus + np.sum(np.sum(self.w * ((target_results - self.teoretic_y) ** 2), axis=1) / np.sum((self.teoretic_avg - self.teoretic_y) ** 2, axis=1))
537
553
  elif metric == 'norm':
538
554
  plus = 0
539
555
  if self.teoretic_realized is not None:
540
- model_realized = c0 - self.get_release_function()(self.teoretic_x, c0)
541
- if self.with_accumulate:
542
- model_accumulation = self.get_accumulation_function()(self.teoretic_x, c0)
543
- if self.accumulation_type == 1:
544
- model_realized = model_accumulation - self.get_release_function()(self.teoretic_x, c0)
545
- elif self.accumulation_type == 2:
546
- accumulation_coeffs = model_accumulation / c0
547
- model_realized = accumulation_coeffs * self.get_release_function()(self.teoretic_x, c0)
548
- model_realized = model_accumulation - model_realized
556
+ model_realized = self.last_result.model_realized
549
557
  plus = np.linalg.norm(self.teoretic_realized - model_realized)
550
558
  return plus + np.linalg.norm(target_results - self.teoretic_y)
551
559
  else:
@@ -597,3 +605,17 @@ class ReleaseCompartmentModel(BaseCompartmentModel):
597
605
  s += self.release_parameters_target_count + int(self.need_v_release_optimization)
598
606
  self.accumulation_parameters[self.accumulation_parameters_target] = x[s:s + self.accumulation_parameters_target_count]
599
607
  return x
608
+
609
+ def plot_model(self, compartment_numbers=None, compartment_names={},
610
+ left=None, right=None, y_lims={}, plot_accumulation=False, **kwargs):
611
+ super().plot_model(compartment_numbers, compartment_names, left, right, y_lims, **kwargs)
612
+ if plot_accumulation:
613
+ if hasattr(self, "teoretic_x") and hasattr(self, "teoretic_realized"):
614
+ plt.plot(self.teoretic_x, self.teoretic_realized, "*r")
615
+ plt.plot(self.last_result.t, self.last_result.model_realized)
616
+ plt.title(compartment_names.get('realized', 'realized'))
617
+ plt.xlim(left=left, right=right)
618
+ if y_lims.get('realized'):
619
+ plt.ylim(y_lims.get('realized'))
620
+ plt.grid()
621
+ plt.show()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pypharm
3
- Version: 1.3.1
3
+ Version: 1.3.3
4
4
  Summary: Module for solving pharmacokinetic problems
5
5
  Home-page: https://github.com/Krash13/PyPharm
6
6
  Author: Krash13
@@ -6,7 +6,7 @@ def readme():
6
6
 
7
7
  setup(
8
8
  name='pypharm',
9
- version='1.3.1',
9
+ version='1.3.3',
10
10
  author='Krash13',
11
11
  author_email='krasheninnikov.r.s@muctr.ru',
12
12
  description='Module for solving pharmacokinetic problems',
File without changes
File without changes
File without changes