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

Integrate the multihit model into the DNSM framework #60

Closed
wants to merge 19 commits into from

Conversation

matsen
Copy link
Contributor

@matsen matsen commented Sep 25, 2024

Here we add the multihit model to the DNSM. We chose to do so by storing the multihit model, as an object, as part of the DNSMDataset object, and bringing it into molevol.py.

This is a bit of a break from the previous work, which was able to stay in tensor land rather than object land. E.g. molevol.py now has objects from models.py.

Here is the rationale.

Previously, we could pre-compute the per-site rates and then all future calculations would be relative to those rates. To emphasize, the per-site rates don't depend on the branch lengths or anything.

Here, we have the multihit multipliers being applied after the codon level calculations. These codon calculations depend on the branch lengths and rates in a nonlinear way. Thus we can't precompute rates and then apply them in a straightforward way.

In theory we could stay more in tensor land by precomputing a 64*64 (this is codon by codon, because the hit classes depend on the source and dest codon) offset per site per sequence, and multiplying that after the codon aggregation step. However, that seems wasteful of memory and overkill.

So we have decided to apply the multihit correction using the forward function of the corresponding object, which is exactly what it's meant to do.

In any case, all of this work happens only in the branch length optimization phase of making the DNSMs, and not the transformer backprop.

Copy link
Contributor Author

@matsen matsen left a comment

Choose a reason for hiding this comment

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

Hey, this is looking almost done!

@@ -142,6 +150,7 @@ def clone(self):
self.all_rates.copy(),
self.all_subs_probs.copy(),
self._branch_lengths.copy(),
multihit_model=copy.deepcopy(self.multihit_model),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This deepcopy and the one below are no longer necessary now that you are copying in the init, right?

@@ -14,6 +15,15 @@
from netam.dnsm import DNSMBurrito, train_val_datasets_of_pcp_df


def force_spawn():
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We were going to move this into common, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(and remove the other instance)

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