-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscratch.py
More file actions
39 lines (32 loc) · 1.12 KB
/
scratch.py
File metadata and controls
39 lines (32 loc) · 1.12 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
"""TCPL scratch testing notebook."""
import numpy as np
import matplotlib.pyplot as plt
from dose_response_models import LogHillModel
# from loss_functions import LossFunctions
# Mock data
conc = np.array([0.03, 0.1, 0.3, 1.0, 3.0, 10.0, 30.0, 100.0])
resp = np.array([0, 0, 0.1, 0.2, 0.5, 1.0, 1.5, 2.0])
# Initialize and fit the model
model = LogHillModel()
model.fit(conc, resp, bid=False)
if model.success_:
# Output results
print('Fit successful!')
print(f'Parameters: {model.best_params_}')
print(f'Log-likelihood: {model.log_likelihood_}')
print(f'AIC: {model.aic_}')
print(f'Predictions: {model.predict(conc)}')
# Predict spaced data for plotting
logc = np.log10(conc)
logc_fine = np.linspace(np.min(logc), np.max(logc), 200)
conc_fine = 10 ** logc_fine
pred = model.predict(conc_fine)
# Generate plot
fig, ax = plt.subplots()
ax.scatter(conc, resp, label='Observed', color='black')
ax.plot(conc_fine, pred, label='Fit', color='blue')
# Add AC50 line
ax.axvline(10 ** model.best_params_[1], linestyle='--', c='red')
plt.show()
else:
print('Fit failed.')