Skip to main content

Transformer-based generative model for galaxies

Project description

CosmoGLINT: Cosmological Generative model for Line INtensity mapping with Transformer

Transformer-based models that generate galaxies.


Installation

This package is available on PyPI.

pip install cosmoglint

This package requires PyTorch. Please install PyTorch first following https://pytorch.org

Documentation & Source code

GitHub: https://github.com/knmoriwaki/cosmoglint

Basic usage

Load model:

import json
from cosmoglint.model.transformer import transformer_model

with open(f"args.json", "r") as f:
  option = json.load(f, object_hook=lambda d: argparse.Namespace(**d))
  
model = transformer_model(option)

with a json file (example):

{"model_name": "transformer1", "max_length": 50, "d_model": 128, "num_layers": 4, "num_heads": 8, "num_features_out": 100, "num_features_in": 4}

Predict probability:

prob = model(context, x) 

Generate new galaxies:

generated, prob = model.generate(context, x, prob_threshold=1e-5)

Input:

  • context: a tensor of shape (N, C_h), containing the properties of halo.
  • x: a tensor of shape (N, L, C_g), containing the properties of up to L galaxies for each of the N halos in the batch. Each feature vector of size C_g may include, for example, the halo mass, relative distance to the halo center, radial velocity, and tangential velocity. Input None to generate from scratch.
  • prob_threshold (optional): when sampling, the probability below this threshold is set to zero.

Output:

  • prob: a tensor of shape (N, L, C_g, d). prob[i,j,k,:] is the probability distribution over d bins for the k-th parameter of the (j+1)-th galaxy in the sequence for the i-th batch element.
  • generated: a tensor of shape (N, L, C_g). generated[i,j,k] is the sampled values for each parameter of (j+1)-th galaxy in the sequence for the i-th batch element.

Shape:

  • N: Batch size
  • L: Sequence length
  • C_h: Number of halo properties
  • C_g: Number of galaxy properties predicted
  • d: Number of bins for the probability distribution of each parameter

Options:

Key Description
model_name Name or identifier for the model configuration (default: "transformer1"). Available options are:
- "transformer1": halo is prepended to the sequence
- "transformer2": halo and galaxy features are embedded together
max_length Maximum number of galaxies (sequence length) the model will process per halo.
d_model Dimensionality of the internal feature space (i.e., size of the token embeddings and hidden layers in the transformer).
num_layers Number of transformer decoder layers stacked in the model.
num_heads Number of attention heads in the multi-head self-attention layers.
num_features_out Total number of output bins for the probability distribution.
num_features_in Number of features per galaxy (e.g., SFR, relative distance, radial/tangential velocity).

Citation

If you use CosmoGLINT in your research, please cite Moriwaki et al. 2025

@ARTICLE{CosmoGLINT,
  title = {CosmoGLINT: Cosmological Generative Model for Line Intensity Mapping with Transformer},
  author = {{Moriwaki}, Kana and {Jun}, Rui Lan and {Osato}, Ken and {Yoshida}, Naoki},
  journal = {arXiv preprints},
  year = 2025,
  month = jun,
  eid = {arXiv:2506.16843},
  doi = {10.48550/arXiv.2506.16843},
  archivePrefix = {arXiv},
  eprint = {2506.16843},
  primaryClass = {astro-ph.CO}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosmoglint-1.0.2.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cosmoglint-1.0.2-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

Details for the file cosmoglint-1.0.2.tar.gz.

File metadata

  • Download URL: cosmoglint-1.0.2.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for cosmoglint-1.0.2.tar.gz
Algorithm Hash digest
SHA256 b7669d425aea96ed176d027ce3640e4067698de4a7e9b8464d64f3cede0fe18b
MD5 9b604b3f05d28570a62ea33b6b28ba98
BLAKE2b-256 02a2b66ef0f48dc5bb70ed613e6f5061d946d63af2a0590664d0bc9bdc265114

See more details on using hashes here.

File details

Details for the file cosmoglint-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: cosmoglint-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 28.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for cosmoglint-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc0435478914107aa3761170147aef8d3ef60bb855582787bc16f98fbb52c99
MD5 92e94ee7127a823b6818867d47972899
BLAKE2b-256 8908d2fcd04a59868a5155a24d463104b0d906dcd4eda3dd652c0b7b6cc03f1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page