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

initial implementation of DANN #16

Merged
merged 9 commits into from
Feb 5, 2025
Merged

initial implementation of DANN #16

merged 9 commits into from
Feb 5, 2025

Conversation

Nikhil0504
Copy link
Collaborator

@Nikhil0504 Nikhil0504 commented Feb 3, 2025

This pull request introduces significant new functionality to the haloflow package, specifically adding a Domain Adversarial Neural Network (DANN) model for domain adaptation tasks. The changes include the addition of new classes and methods for data loading, model definition, training, evaluation, and visualization.

New Functionality:

Data Loading:

  • src/haloflow/dann/data_loader.py: Added SimulationDataset class to handle loading and preprocessing of simulation data, and to provide DataLoaders for training and testing.

Model Definition:

  • src/haloflow/dann/model.py: Added DANN class for the Domain Adversarial Neural Network model, including feature extractor, label predictor, and domain classifier components.

Training:

  • src/haloflow/dann/train.py: Added train_dann function to train the DANN model, incorporating both task-specific and domain classification losses.

Evaluation:

  • src/haloflow/dann/evalutate.py: Added evaluate_regression and domain_accuracy functions to evaluate the model's regression performance and domain classification accuracy, respectively.

Utility:

  • src/haloflow/dann/utils.py: Added GradientReversal and GradientReversalLayer classes to implement gradient reversal for adversarial training.

Visualization:

@Nikhil0504 Nikhil0504 linked an issue Feb 3, 2025 that may be closed by this pull request
@Nikhil0504 Nikhil0504 marked this pull request as ready for review February 3, 2025 06:59
@Nikhil0504 Nikhil0504 self-assigned this Feb 3, 2025
@Nikhil0504 Nikhil0504 added the enhancement New feature or request label Feb 3, 2025
src/haloflow/dann/model.py Outdated Show resolved Hide resolved
@changhoonhahn
Copy link
Collaborator

Do you understand why Domain 0 has that region with no overlap?

Does Domain 0 have a higher mass resolution? I'm wondering if those blue points are low mass galaxies.

@Nikhil0504
Copy link
Collaborator Author

Do you understand why Domain 0 has that region with no overlap?

Yes, I think so.

Does Domain 0 have a higher mass resolution? I'm wondering if those blue points are low mass galaxies.

Yeah, Domain 0 is TNG 50. TNG 50 should have a higher resolution than all the other simulations. The test simulation (Domain 4/ Test Domain) is TNG_ALL.

@changhoonhahn
Copy link
Collaborator

changhoonhahn commented Feb 3, 2025

I see. For DA purposes, we should impose a consistent mass limit across the simulations. DA should not work for the low mass TNG50 galaxies, since they lie below the mass limits of the other simulations, so it's a waste of training.

@Nikhil0504
Copy link
Collaborator Author

Nikhil0504 commented Feb 3, 2025

@changhoonhahn changhoonhahn merged commit 2440c7e into main Feb 5, 2025
@changhoonhahn
Copy link
Collaborator

Looked through the pull request. Everything looks good, although some of the modules may be a bit excessive, haha.

@Nikhil0504 Nikhil0504 deleted the implement-dann branch February 6, 2025 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implementing domain adversarial neural network (DANN)
2 participants