Skip to content

Commit

Permalink
#183 PMC reduce outputs of MM if not all measured
Browse files Browse the repository at this point in the history
  • Loading branch information
DavAug committed Mar 7, 2021
1 parent cd7a192 commit 861f808
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions erlotinib/_problems.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,9 @@ def _create_log_likelihood(self, individual):
mask = self._data[self._id_key] == individual
data = self._data[mask][
[self._time_key, self._biom_key, self._meas_key]]
for output in self._mechanistic_model.outputs():
outputs = self._mechanistic_model.outputs()
measured_outputs = []
for output in outputs:
# Mask data for biomarker
biomarker = self._output_biomarker_dict[output]
mask = data[self._biom_key] == biomarker
Expand All @@ -303,26 +305,31 @@ def _create_log_likelihood(self, individual):
temp_df = temp_df[mask]

# Collect data for output
times.append(temp_df[self._time_key].to_numpy())
observations.append(temp_df[self._meas_key].to_numpy())

# Count outputs that were measured
# TODO: copy mechanistic model and update model outputs.
# (Useful for e.g. control group and dose group training)
n_measured_outputs = 0
for output_measurements in observations:
if len(output_measurements) > 0:
n_measured_outputs += 1
t = temp_df[self._time_key].to_numpy()
o = temp_df[self._meas_key].to_numpy()
if (len(t) > 0) and (len(o) > 0):
times.append(t)
observations.append(o)
measured_outputs.append(output)

# If no outputs were measured, do not construct a likelihood
if n_measured_outputs == 0:
if len(measured_outputs) == 0:
return None

# If not all outputs were measured, adjust outputs of mechanistic
# model
if len(measured_outputs) != len(outputs):
self._mechanistic_model.set_outputs(measured_outputs)

# Create log-likelihood and set ID to individual
log_likelihood = erlo.LogLikelihood(
self._mechanistic_model, self._error_models, observations, times)
log_likelihood.set_id(individual)

# If outputs were adjusted, reset to original outputs
if len(measured_outputs) != len(outputs):
self._mechanistic_model.set_outputs(outputs)

return log_likelihood

def _extract_dosing_regimens(self, dose_key, duration_key):
Expand Down

0 comments on commit 861f808

Please sign in to comment.