Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functions for correlation matrix, copula indicator and plotting #103

Merged
merged 17 commits into from
Aug 15, 2024

Conversation

SotirisTouliopoulos
Copy link
Contributor

Aim of this PR is:

  1. to provide functions for calculation of correlation matrix from steady states, filtering based on copula indicator & plotting
  2. to improve the efficiency of the PreProcess class.

The correlated_reactions function that calculates a pearson correlation matrix from reactions steady states is appended to the script dingo/utils.py Correlations that do not make the pearson cutoff are replaced with 0. For pairwise reactions with a greater pearson coefficient than the cutoff, a copula indicator is computed to filter false-positive correlations. Parameters of this function can adjust the width of the copula's diagonal for the calculation of the indicator and return only the lower triangle of the symmetric matrix. Cutoffs for pearson and indicator filtering can be adjusted from the user too.

The plot_corr_matrix function that creates a heatmap plot of a correlation matrix is appended to the script dingo/illustrations.py Parameters of this function can specify the format of the saved image plot and place as labels only the remained reactions for reduced models.

The reduce function of the PreProcess class for the extend parameter set to True has also changed to identify additional reactions for removal in bigger models. It uses the new correlated_reactions function to calculate a correlation matrix and order reactions based on their sum of absolute correlations with other reactions. Reactions with smaller values of overall correlation are removed first. The removal stops in the first reaction that alters the value of the objective function.

A correlation.py unittest is also created in the tests directory and the preprocess.py unittest is updated too.

dingo/utils.py Outdated
Comment on lines 317 to 319
print(positive, "out of", i+1, "copulas were positive correlated based on copula indicator")
print(negative, "out of", i+1, "copulas were negative correlated based on copula indicator")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The prints should be requested by the user I think. These numbers could be part of the output as with a label for each copula: "positive" or "negative"

Copy link
Contributor Author

@SotirisTouliopoulos SotirisTouliopoulos Aug 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a dictionary of this format that is returned

{'ACONTb_ACONTa': {'pearson': 0.9999999999999996, 'indicator': 700000000.9999999, 'classification': 'positive'},
 'ACt2r_ACKr': {'pearson': 1.0, 'indicator': 700000000.9999999, 'classification': 'positive'}}

dingo/utils.py Outdated
'indicator': indicator,
'classification': "no correlation"}

print("Completed process of",i+1,"from",corr_indices.shape[0],"copulas")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the prints should ideally requested by the user and be off by default.
I'd use a flag verbose: bool as an input variable with False as default value. Then, print any message only if verbose is true.

self._model.reactions.get_by_id(reaction).bounds = self._reaction_bounds_dict[reaction]


print(len(self._removed_reactions), "of the", len(self._initial_reactions), \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plz, see my comment below for the printed messages.

@TolisChal TolisChal merged commit 4a961e7 into GeomScale:develop Aug 15, 2024
1 check passed
@SotirisTouliopoulos SotirisTouliopoulos deleted the correlation branch August 16, 2024 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants