Skip to content

Commit 215bae7

Browse files
Fix build break: 3
1 parent ab9312a commit 215bae7

11 files changed

Lines changed: 55 additions & 559 deletions

scripts/calculate_linear_prediction_scores.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ def processModels(first_model_num: int, last_model_num: int,
105105
endtime_dct = getBiomodelsEndtimes(is_include_endtime_source=True)
106106

107107
score = Score(serialization_path=serialization_path)
108-
if os.path.exists(score.serialization_path):
109-
existing_models = set(score.score_df["description"].unique())
108+
if len(score.score_df) > 0:
109+
if "description" in score.score_df.columns:
110+
existing_models = set(score.score_df["description"].unique())
111+
else:
112+
existing_models = set(score.score_df[cn.COL_SYSTEM_ID].unique())
110113
else:
111114
existing_models = set()
112115
excluded_models = list(set(EXCLUDED_MODELS) | existing_models)

scripts/make_biomodels_endtime.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

src/constants.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
DIAMETER_MAX_CV = "max_cv"
3131

3232
# Columns
33+
COL_AGGREGATION_TYPE = "aggregation_type" # model or species name
34+
COL_AGGREGATION_TYPE_MODEL = "model"
3335
COL_MAXCV = "max_cv"
3436
COL_ENDTIME = "end_time"
3537
COL_MODEL_NAME = "model_name"
@@ -77,8 +79,3 @@
7779
# Endtime fraction
7880
ENDTIME_FRACTION_STEADYSTATE = 0.1 # Fraction of endtime to use for timecourse analysis
7981
ENDTIME_FRACTION_MAXMEDIAN = 0.1 # Fraction of endtime to use for timecourse analysis
80-
81-
# Aggregations
82-
AGGREGATION_TYPE = "aggregation_type" # model or species name
83-
AGGREGATION_TYPE_MODEL = "model"
84-
DESCRIPTION = "description" # Description of the aggregation

src/piecewise_system_discovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ def score(self, column_name: str = 'p95') -> float:
146146
"""Length-weighted aggregation of per-subsequence ScoreInfo. See
147147
docs/piecewise_system_discovery.md `score()` section."""
148148
weighted_score_df = self.getWeightedScores()
149-
sel = weighted_score_df[cn.AGGREGATION_TYPE] == cn.AGGREGATION_TYPE_MODEL
149+
sel = weighted_score_df[cn.COL_AGGREGATION_TYPE] == cn.COL_AGGREGATION_TYPE_MODEL
150150
result = weighted_score_df[sel][column_name].values
151151
if len(result) != 1:
152-
raise RuntimeError(f"Expected 1 row for {cn.AGGREGATION_TYPE_MODEL} but got {len(result)}")
152+
raise RuntimeError(f"Expected 1 row for {cn.COL_AGGREGATION_TYPE_MODEL} but got {len(result)}")
153153
return cast(float, result[0])
154154

155155
def __str__(self) -> str:

src/score.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,15 @@ def add(self,
105105
The full score DataFrame after this addition.
106106
"""
107107
mape_df: pd.DataFrame = self.calculateMAPE(true_timecourse_df, prediction_timecourse_df)
108-
self.statistic_calculator.add(cn.AGGREGATION_TYPE_MODEL, mape_df.values.flatten())
108+
self.statistic_calculator.add(cn.COL_AGGREGATION_TYPE_MODEL, mape_df.values.flatten())
109109
# Species level aggregations (one per species column, across all timepoints)
110110
species_names = list(mape_df.columns)
111111
for species_name in species_names:
112112
self.statistic_calculator.add(species_name, mape_df[species_name].to_numpy())
113113
# Add the system ID
114114
self.score_df = self.statistic_calculator.dataframe.copy()
115115
self.score_df[cn.COL_SYSTEM_ID] = system_id
116+
self.score_df = self.score_df.rename(columns={cn.COL_LABEL: cn.COL_AGGREGATION_TYPE})
116117
# Serialize the accumulated statistics
117118
if self._is_persist:
118119
self.score_df.to_csv(self.serialization_path, index=False)
@@ -163,14 +164,14 @@ def doPlot(value_arr: np.ndarray, xlabel: str):
163164
plt.close()
164165
##
165166
if is_plot_model:
166-
if cn.AGGREGATION_TYPE in df.columns:
167-
model_df = df[df[cn.AGGREGATION_TYPE] == cn.AGGREGATION_TYPE_MODEL]
167+
if cn.COL_AGGREGATION_TYPE in df.columns:
168+
model_df = df[df[cn.COL_AGGREGATION_TYPE] == cn.COL_AGGREGATION_TYPE_MODEL]
168169
if not model_df.empty and metric_name in model_df.columns:
169170
value_arr = np.array(model_df[metric_name].values)
170171
doPlot(value_arr, xlabel=metric_name)
171172
if is_plot_species:
172-
if cn.AGGREGATION_TYPE in df.columns:
173-
species_df = df[df[cn.AGGREGATION_TYPE] != cn.AGGREGATION_TYPE_MODEL]
173+
if cn.COL_AGGREGATION_TYPE in df.columns:
174+
species_df = df[df[cn.COL_AGGREGATION_TYPE] != cn.COL_AGGREGATION_TYPE_MODEL]
174175
if not species_df.empty and metric_name in species_df.columns:
175176
value_arr = np.array(species_df[metric_name].values)
176177
doPlot(value_arr, xlabel=metric_name)

src/system_discovery.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,8 @@ def calculateRsq(self, method: str = "derivative",
545545
self._require_fitted()
546546
score_type = "timecourse" if method == "simulation" else "derivative"
547547
detail_df = self.getScoreDetails(test_df=test_df, score_type=score_type)
548-
species_rows = detail_df[detail_df[cn.AGGREGATION_TYPE]
549-
!= cn.AGGREGATION_TYPE_MODEL].copy()
548+
species_rows = detail_df[detail_df[cn.COL_AGGREGATION_TYPE]
549+
!= cn.COL_AGGREGATION_TYPE_MODEL].copy()
550550
result: dict[str, float] = {}
551551
for i, sp_name in enumerate(self.species_names):
552552
if i < len(species_rows):
@@ -938,18 +938,21 @@ def getScoreDetails(self, test_df: pd.DataFrame = NULL_DF, score_type: str = "de
938938
A DataFrame containing the score information for the model and each species.
939939
"""
940940
score = Score()
941+
result_df = pd.DataFrame()
941942
if score_type == "derivative":
942943
if test_df is NULL_DF:
943944
test_df = self.df
944945
pred_arr = self.predictAllDerivatives(test_df.to_numpy(dtype=float))
945946
pred_df = pd.DataFrame(pred_arr[:-1], index=test_df.index[1:],
946947
columns=self.species_names)
947-
return score.add(self.Xdot_df, pred_df)
948+
result_df = score.add(self.Xdot_df, pred_df)
948949
elif score_type == "timecourse":
949950
pred_df = self.predict()
950-
return score.add(self.df, pred_df)
951+
result_df =score.add(self.df, pred_df)
951952
else:
952953
raise ValueError(f"Invalid score_type '{score_type}'. Must be 'derivative' or 'timecourse'.")
954+
#
955+
return result_df
953956

954957
def score(self, score_type: str = "derivative") -> float:
955958
"""
@@ -973,12 +976,12 @@ def score(self, score_type: str = "derivative") -> float:
973976
- ``"timecourse"``: R² for the species timecourses
974977
"""
975978
score_detail_df = self.getScoreDetails(score_type=score_type)
976-
model_sel = score_detail_df["aggregation_type"] == "model"
979+
model_sel = score_detail_df[cn.COL_AGGREGATION_TYPE] == "model"
977980
if score_type == "derivative":
978981
result = float(score_detail_df[model_sel]["min"].iloc[0])
979982
return result
980983
elif score_type == "timecourse":
981-
species_sel = score_detail_df["aggregation_type"] != "model"
984+
species_sel = score_detail_df[cn.COL_AGGREGATION_TYPE] != "model"
982985
p95_vals = score_detail_df[species_sel]["p95"].to_numpy(dtype=float)
983986
result = float(np.max(p95_vals))
984987
return result

0 commit comments

Comments
 (0)