{"id":26172429,"url":"https://github.com/jwuphysics/sparse-feature-networks","last_synced_at":"2025-04-14T20:21:28.980Z","repository":{"id":273562745,"uuid":"858332940","full_name":"jwuphysics/sparse-feature-networks","owner":"jwuphysics","description":"Learning astrophysics with top-k sparse feature networks (SF-Nets)","archived":false,"fork":false,"pushed_at":"2025-02-19T22:32:51.000Z","size":1288,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T08:35:41.480Z","etag":null,"topics":["convolutional-neural-networks","explainable-artificial-intelligence","galaxy-evolution","sparse-coding"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwuphysics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-16T18:01:11.000Z","updated_at":"2025-02-19T22:32:54.000Z","dependencies_parsed_at":"2025-01-21T17:26:50.509Z","dependency_job_id":"82638253-a316-4f60-ae18-56ee7b61a26b","html_url":"https://github.com/jwuphysics/sparse-feature-networks","commit_stats":null,"previous_names":["jwuphysics/sparse-feature-networks"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwuphysics%2Fsparse-feature-networks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwuphysics%2Fsparse-feature-networks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwuphysics%2Fsparse-feature-networks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwuphysics%2Fsparse-feature-networks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwuphysics","download_url":"https://codeload.github.com/jwuphysics/sparse-feature-networks/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248952345,"owners_count":21188427,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convolutional-neural-networks","explainable-artificial-intelligence","galaxy-evolution","sparse-coding"],"created_at":"2025-03-11T19:56:29.593Z","updated_at":"2025-04-14T20:21:28.954Z","avatar_url":"https://github.com/jwuphysics.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![arXiv](https://img.shields.io/badge/ApJ-980,_183-ffa600.svg)](https://iopscience.iop.org/article/10.3847/1538-4357/adadec)\n[![arXiv](https://img.shields.io/badge/arXiv-2501.00089-b31b1b.svg)](https://arxiv.org/abs/2501.00089)\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.14712542.svg)](https://doi.org/10.5281/zenodo.14712542)\n\n\n# Insights on Galaxy Evolution from Interpretable Sparse Feature Networks (SFNets)\n\nWe introduce sparse feature networks (SFNets), which contain a simple top-k sparsity constraint in their penultimate layers. We show that these SFNets can predict galaxy properties, such as gas metallicity or BPT line ratios, directly from image cutouts. SFNets produce interpretable feature activations, which can then be studied to better understand galaxy formation and evolution.\n\n## Requirements\n\nThis software uses [`fastai`](https://github.com/fastai/fastai), built atop `pytorch`, and a few other packages that are commonly found in the data science stack. We've tested that this code works using `fastai==2.7.17` and `torch==2.4.1` on both Linux and macOS.\n\nInstall requirements with:\n```bash\npip install torch fastai numpy pandas matplotlib cmasher tqdm\n```\n\n## Directory Structure\n\n```\n./\n├── data/\n│   ├── images-sdss/\n│   └── galaxies.csv\n├── model/\n├── results/\n└── src/\n    ├── config.py          \n    ├── dataloader.py     \n    ├── model.py         \n    ├── main.py             \n    └── trainer.py         \n```\n\n## Usage\n\n1. Prepare your data:\n   - For convenience, the data can all be obtained via [Zenodo](https://zenodo.org/records/14712542). Simply download the `images-sdss.tar.gz` and unpack it (`tar xzf images-sdss.tar.gz`), and also download `galaxies.csv`.\n   - Alternatively, you can obtain the data directly from the source:\n       - Construct `galaxies.csv` with the required columns (`objID`, `oh_p50` for metallicity, or line flux measurements for BPT analysis). We used CASJobs to download galaxies using [this query](https://github.com/cherryquinnlg/agn-convnets/blob/main/data/AGN_K03.sql), and then enforced a signal-to-noise ratio (SNR) cut of 3 for all spectral lines.\n       - Download SDSS galaxy images into `data/images-sdss/`. We used the DESI Legacy Viewer to download via the RESTful interface, e.g. `http://legacysurvey.org/viewer/cutout.jpg?ra={ra}\u0026dec={dec}\u0026pixscale=0.262\u0026layer=sdss\u0026size=160`.\n   \n2. Run experiments: \n   - Modify and run the main `python main.py`\n```python\nfrom config import ExperimentConfig, DataConfig, TrainingConfig\nfrom trainer import ModelTrainer\n\nconfig = ExperimentConfig(\n    name=\"metallicity_experiments\",\n    target=\"metallicity\",\n    k=2,\n    model_dir=Path(\"../model\"),\n    results_dir=Path(\"../results\"),\n    data_config=DataConfig(),\n    training_config=TrainingConfig()\n)\n\n# Train models\ntrainer = ModelTrainer(config)\ntrainer.train_model()\n```\n\n## Models and results\n\nThe trained model weights can also be found on [Zenodo](https://zenodo.org/records/14712542).\n\nAdditionally, we have uploaded our trained model weights and sparse activation results [here](https://www.dropbox.com/scl/fo/8v0wd2r97251c4gb69iax/AAaRdE7QPFSgFOuOtsnGEEE?rlkey=14jj9mt6evtdgcqsx8ogccim9\u0026st=zctk6mzo\u0026dl=0). The optimized `ResNetTopK18` models should be able to reproduce the results shown in the paper.\n\n## Citation\n\nThis paper can be found on arXiv. For now, please use the following citation:\n\n```latex\n@ARTICLE{2025ApJ...980..183W,\n       author = {{Wu}, John F.},\n        title = \"{Insights into Galaxy Evolution from Interpretable Sparse Feature Networks}\",\n      journal = {\\apj},\n     keywords = {Galaxies, Astronomy image processing, Convolutional neural networks, 573, 2306, 1938, Astrophysics - Astrophysics of Galaxies, Computer Science - Machine Learning},\n         year = 2025,\n        month = feb,\n       volume = {980},\n       number = {2},\n          eid = {183},\n        pages = {183},\n          doi = {10.3847/1538-4357/adadec},\narchivePrefix = {arXiv},\n       eprint = {2501.00089},\n primaryClass = {astro-ph.GA},\n       adsurl = {https://ui.adsabs.harvard.edu/abs/2025ApJ...980..183W},\n      adsnote = {Provided by the SAO/NASA Astrophysics Data System}\n}\n```\n\n## License\n\nThis project is licensed under the MIT License; please see the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwuphysics%2Fsparse-feature-networks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwuphysics%2Fsparse-feature-networks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwuphysics%2Fsparse-feature-networks/lists"}