-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.py
More file actions
73 lines (58 loc) · 2.34 KB
/
simulation.py
File metadata and controls
73 lines (58 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import numpy as np
from dataclasses import dataclass
import pandas as pd
@dataclass
class SimulationParams:
drug_concentration: float
time_period: int
growth_factor: float
class OrganoidSimulator:
def __init__(self):
self.time_points = None
self.growth_curve = None
self.drug_response = None
def simulate_growth(self, params: SimulationParams):
"""Simulate organoid growth with given parameters"""
self.time_points = np.linspace(0, params.time_period, 100)
# Simulate growth curve with logistic growth
carrying_capacity = 1.0
growth_rate = params.growth_factor
initial_population = 0.1
self.growth_curve = carrying_capacity / (1 + ((carrying_capacity - initial_population) /
initial_population) * np.exp(-growth_rate * self.time_points))
# Simulate drug response
drug_effect = 1 - (params.drug_concentration / (params.drug_concentration + 1))
self.drug_response = self.growth_curve * drug_effect
return self._create_simulation_df()
def _create_simulation_df(self):
"""Create a DataFrame with simulation results"""
df = pd.DataFrame({
'time': self.time_points,
'growth': self.growth_curve,
'drug_response': self.drug_response
})
return df
def generate_synthetic_data(n_samples=100):
"""Generate synthetic data for ML model training"""
np.random.seed(42)
data = []
for _ in range(n_samples):
drug_conc = np.random.uniform(0, 2)
growth_factor = np.random.uniform(0.1, 1)
time_period = np.random.randint(10, 50)
params = SimulationParams(
drug_concentration=drug_conc,
time_period=time_period,
growth_factor=growth_factor
)
simulator = OrganoidSimulator()
df = simulator.simulate_growth(params)
# Calculate effectiveness metric
effectiveness = np.mean(1 - df['drug_response'] / df['growth'])
data.append({
'drug_concentration': drug_conc,
'growth_factor': growth_factor,
'time_period': time_period,
'effectiveness': effectiveness
})
return pd.DataFrame(data)