in compert/api.py [0:0]
def latent_dose_response2D(self, perturbations, dose=None,
contvar_min=0, contvar_max=1, n_points=100,):
"""
Parameters
----------
perturbations : list, optional (default: None)
List of atomic drugs for which to return latent dose response.
Currently drug combinations are not supported.
doses : np.array (default: None)
Doses values. If None, default values will be generated on a grid:
n_points in range [contvar_min, contvar_max].
contvar_min : float (default: 0)
Minimum dose value to generate for default option.
contvar_max : float (default: 0)
Maximum dose value to generate for default option.
n_points : int (default: 100)
Number of dose points to generate for default option.
Returns
-------
pd.DataFrame
"""
# dosers work only for atomic drugs. TODO add drug combinations
assert len(perturbations) == 2, "You should provide a list of 2 perturbations."
self.model.eval()
if dose is None:
dose = np.linspace(contvar_min, contvar_max, n_points)
n_points = len(dose)
df = pd.DataFrame(columns=perturbations + ['response'])
response = {}
for drug in perturbations:
d = np.where(self.perts_dict[drug] == 1)[0][0]
this_drug = torch.Tensor(dose).to(self.model.device).view(-1, 1)
if self.model.doser_type == 'mlp':
response[drug] = (self.model.dosers[d](this_drug).sigmoid() *\
this_drug.gt(0)).cpu().clone().detach().numpy().reshape(-1)
else:
response[drug] = self.model.dosers.one_drug(this_drug.view(-1),\
d).cpu().clone().detach().numpy().reshape(-1)
l = 0
for i in range(len(dose)):
for j in range(len(dose)):
df.loc[l] = [dose[i], dose[j], response[perturbations[0]][i]+\
response[perturbations[1]][j]]
l += 1
return df