Skip to content

Commit

Permalink
added option to provide fixed transformations via file
Browse files Browse the repository at this point in the history
  • Loading branch information
tkchafin committed May 9, 2024
1 parent 0d7e53f commit 02b56a5
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/resistnet/model_optimisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,16 @@ def parse_fixed_params(self, fixed_params):
df = pd.read_csv(fixed_params, sep='\t')
# Check if the DataFrame has a fitness column
if 'fitness' in df.columns:
# Select rows with the minimum fitness for each variable
self.fixed_params = df.loc[
df.groupby('variable')['fitness'].idxmin()
].set_index('variable').to_dict('index')
best_params = dict()
for var in df["variable"].unique():
var_df = df[df['variable'] == var]
best = var_df.loc[var_df['fitness'] == var_df['fitness'].min()]
best = best.sort_values(by=['shape', 'transform']).iloc[0]
best_params[var] = {
'transform': best['transform'],
'shape': best['shape']
}
self.fixed_params = best_params
else:
# Assume file contains correct columns
self.fixed_params = df.set_index(
Expand Down Expand Up @@ -947,8 +953,6 @@ def optimise_univariate(self, fitmetric="aic", threads=1,
}

if out:
if fitmetric == "aic":
df["fitness"] = -df["fitness"]
df.to_csv(
str(out)+".univariateFitness.tsv", index=False, sep="\t")

Expand Down

0 comments on commit 02b56a5

Please sign in to comment.