Skip to main content

PICSLike: Pixel-based Inference with Correlated-Skies Likelihood

Project description

PICSLike

PyPI Python Documentation Parallelization Method

PICSLike logo (light) PICSLike logo (dark)

PICSLike Documentation | Main Documentation

PICSLike (Pixel-based Inference with Correlated-Skies Likelihood) is the pixel-based likelihood analysis engine of CosmoForge, implementing direct likelihood evaluation in map pixel space for cosmological parameter inference from CMB data.

Overview

PICSLike provides pixel-based likelihood computation as an alternative to harmonic-space methods:

  • Pixel-based Likelihood: Direct likelihood evaluation in map pixel space
  • Parameter Grid Analysis: Efficient likelihood computation across parameter grids

The approach is particularly useful for handling incomplete sky coverage, non-Gaussian features, and scenarios where pixel-space analysis offers computational or methodological advantages.

Key Features

Pixel-based Likelihood Analysis

  • Direct likelihood evaluation in pixel space
  • Natural handling of masked regions
  • Support for temperature and polarization data
  • Cross-correlation analysis support
  • Chi-squared and log-likelihood computation

Parameter Grid Management

  • Flexible parameter range specification
  • Theoretical spectra grid management
  • Efficient MPI distribution across parameter points
  • Best-fit parameter extraction
  • Confidence interval computation

Technical Features

  • MPI Parallelization: Distributed computation across parameter grids
  • Memory Optimization: Efficient covariance matrix handling
  • Instrumental Effects: Beam convolution and pixel window functions
  • Flexible Configuration: YAML-based parameter specification

Installation

PICSLike is part of CosmoForge and installs automatically:

pip install -e /path/to/CosmoForge

For MPI support:

pip install mpi4py

Documentation

For detailed API documentation and examples:

Quick Start

Basic Pixel-based Likelihood Analysis

from picslike import PICSLike

# Initialize likelihood analysis
picslike = PICSLike("config/pixel_analysis.yaml")

# Run full pipeline
picslike.run()

# Get results
chi_squared = picslike.get_chi_squared()
best_fit = picslike.get_best_fit()
log_likelihood = picslike.get_log_likelihood()

Step-by-Step Execution

from picslike import PICSLike

# Initialize analysis
picslike = PICSLike("config/pixel_config.yaml")

# Setup pipeline components
picslike.setup_parameter_grid()
picslike.setup_fields()
picslike.setup_geometry()
picslike.setup_covariance_matrices()
picslike.setup_cls()
picslike.setup_beams()
picslike.setup_maps()

# Compute likelihood across parameter grid
picslike.compute()

# Save results
picslike.save_results("output/likelihood_results.pkl")

Accessing Simulation Results

from picslike import PICSLike

# Run analysis
picslike = PICSLike("config.yaml")
picslike.run()

# Get individual simulation results
simulation_results = picslike.get_simulation_results()

# Get mean likelihood result
mean_result = picslike.get_mean_likelihood_result()

# Extract summary statistics
summary = mean_result.get_summary_statistics()

Configuration

PICSLike uses YAML configuration files:

Basic Configuration

# Data specification
nside: 32
lmax: 64
fields: "TEB"  # or "TQU"

# Input files
maskfile: "data/mask.fits"
inputclfile: "data/fiducial_cls.txt"
covmatfile1: "data/noise_cov1.bin"
covmatfile2: "data/noise_cov2.bin"  # for cross-correlation

# Analysis parameters
do_cross: false
calibration: 1.0
nsims: 100

Parameter Grid Configuration

# Parameter ranges for likelihood grid
parameters:
  amplitude:
    - 0.5    # min
    - 1.5    # max
    - 11     # n_points
  tilt:
    - -0.5   # min
    - 0.5    # max
    - 11     # n_points

# Theoretical spectra location
root_dir: "data/templates"
root_filename: "dls"

Beam Configuration

# Beam parameters
smoothing_type: gaussian  # none, gaussian, cosine_legacy, cosine_npipe, file
fwhmarcmin: 5.0
beam_file: "data/beam.fits"
apply_pixwin: true
smooth_pol: true

MPI Usage

Run analyses in parallel:

# Pixel-based likelihood analysis
mpirun -n 4 python -c "
from picslike import PICSLike
picslike = PICSLike('config.yaml')
picslike.run()
"

# Full analysis with result saving
mpirun -n 8 python main_picslike.py config/pixel_analysis.yaml

Analysis Pipeline

Likelihood Computation Pipeline

  1. Setup: Read parameters and initialize fields
  2. Parameter Grid: Configure parameter ranges and load theoretical spectra
  3. Geometry: Compute pixel pointing vectors
  4. Covariance: Load noise covariance matrices
  5. Maps: Read input observation maps
  6. Broadcast: Distribute data across MPI processes
  7. Compute: Evaluate likelihood at each parameter point
  8. Results: Gather and store likelihood values

Likelihood Function

The pixel-based likelihood is computed as:

ln L(theta) = -1/2 * (d - s(theta))^T * C^(-1) * (d - s(theta))

where:

  • d is the observed data vector
  • s(theta) is the theoretical signal for parameters theta
  • C is the total covariance matrix (signal + noise)

API Reference

PICSLike Class

class PICSLike(Core):
    """Pixel-based likelihood analysis implementation."""

    def run(self):
        """Execute complete likelihood analysis."""

    def compute(self):
        """Compute likelihood across parameter grid."""

    def get_chi_squared(self):
        """Get chi-squared values."""

    def get_log_likelihood(self):
        """Get log-likelihood values."""

    def get_best_fit(self):
        """Get best-fit parameter values."""

    def save_results(self, output_path):
        """Save results to file."""

ParameterGrid Class

class ParameterGrid:
    """Manager for parameter grids and theoretical spectra."""

    def get_total_points(self):
        """Get total number of grid points."""

    def get_points_for_process(self, rank, size):
        """Get parameter points for an MPI process."""

    def get_spectrum(self, param_point):
        """Get theoretical spectrum for a parameter point."""

LikelihoodResult Class

class LikelihoodResult:
    """Container for likelihood computation results."""

    def get_best_fit(self):
        """Get best-fit parameter values."""

    def get_confidence_intervals(self, confidence_level=0.68):
        """Compute confidence intervals."""

    def get_marginalized_likelihood(self, parameter_name):
        """Get marginalized likelihood for a parameter."""

    def get_summary_statistics(self):
        """Get comprehensive summary statistics."""

    def save(self, output_path):
        """Save results to file."""

    @classmethod
    def load(cls, input_path):
        """Load results from file."""

Output Files

Likelihood Analysis Outputs

  • likelihood_results.pkl: Complete likelihood results
  • likelihood_results_sim_XX.pkl: Individual simulation results

Result Content

  • Chi-squared values across parameter grid
  • Log-likelihood values
  • Best-fit parameters
  • Confidence intervals (68%, 95%)
  • Marginalized likelihoods

Performance Optimization

Memory Management

  • Efficient covariance matrix handling
  • In-place operations where possible
  • Memory-mapped file I/O for large datasets

Computational Efficiency

  • Signal matrix computation optimized with Numba
  • Optimized BLAS/LAPACK operations
  • MPI load balancing across parameter points

Scaling

Typical performance scaling:

Processes    Speed-up
1           1.0x
2           1.9x
4           3.7x
8           7.3x
16          14.2x

Testing

Run the test suite:

cd src/cosmoforge.picslike
python -m pytest tests/ -v

Specific tests:

# Test likelihood result class
python -m pytest tests/test_likelihood_result.py

# Test parameter grid
python -m pytest tests/test_parameter_grid.py

# Test full pipeline
python -m pytest tests/test_picslike.py

Examples

Mock Data Generation

# Generate mock inputs for temperature-only analysis
python scripts/produce_mock_inputs.py T /data/mocks config.yaml

# Generate with Galactic mask
python scripts/produce_mock_inputs.py TQU /data/mocks config.yaml --mask

Parameter Constraint Analysis

from picslike import PICSLike, LikelihoodResult

# Run likelihood analysis
picslike = PICSLike("config.yaml")
picslike.run()

# Get likelihood result
result = picslike.get_mean_likelihood_result()

# Get confidence intervals
intervals_68 = result.get_confidence_intervals(0.68)
intervals_95 = result.get_confidence_intervals(0.95)

# Get marginalized likelihood for specific parameter
marg_like = result.get_marginalized_likelihood('amplitude')

print(f"Best-fit parameters: {result.get_best_fit()}")
print(f"68% confidence intervals: {intervals_68}")

Scientific Context

Pixel-based likelihood methods provide several advantages:

  1. Incomplete sky coverage: Natural handling of masked regions without harmonic-space complications
  2. Non-Gaussian features: Direct treatment of non-Gaussian signals and systematics
  3. Cross-correlation analysis: Efficient computation of cross-correlations between different maps
  4. Computational efficiency: Faster for certain analysis configurations

Troubleshooting

Common Issues

  1. Memory errors: Reduce nside or use more MPI processes
  2. Missing spectra errors: Ensure theoretical spectra exist for all grid points
  3. MPI hanging: Ensure consistent configuration across processes

Debug Mode

Enable detailed logging:

feedback: 4  # Maximum verbosity

Performance Profiling

import cProfile

def run_analysis():
    picslike = PICSLike("config.yaml")
    picslike.run()

cProfile.run('run_analysis()', 'profile_output.prof')

Contributing

See the main CosmoForge README for contribution guidelines.

References

  • Wandelt, B.D., Larson, D.L. & Lakshminarayanan, A. "Global, exact cosmic microwave background data analysis using Gibbs sampling" Phys. Rev. D 70, 083511 (2004)
  • Jewell, J., Levin, S. & Anderson, C.H. "Application of Monte Carlo algorithms to the Bayesian analysis of the cosmic microwave background" Astrophys. J. 609, 1-14 (2004)
  • Eriksen, H.K. et al. "Power Spectrum Estimation from High-Resolution Maps by Gibbs Sampling" Astrophys. J. Suppl. 155, 227-241 (2004)
  • Planck Collaboration "Planck 2018 results. V. CMB power spectra and likelihoods" Astron. Astrophys. 641, A5 (2020)
  • Tegmark, M. "How to measure CMB power spectra without losing information" Phys. Rev. D 55, 5895 (1997)

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

picslike-1.0.0rc2.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

picslike-1.0.0rc2-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file picslike-1.0.0rc2.tar.gz.

File metadata

  • Download URL: picslike-1.0.0rc2.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for picslike-1.0.0rc2.tar.gz
Algorithm Hash digest
SHA256 ba82a968fb037ad29527e9dc5e9fdcd914365f7e7b9753d0bb5abfd080ee1755
MD5 85d8357fa2e408357767075d60ff235b
BLAKE2b-256 f498886da26e69d51e235f8f1bdfb7a08096fc949d814ef2764cbea243adfcb7

See more details on using hashes here.

Provenance

The following attestation bundles were made for picslike-1.0.0rc2.tar.gz:

Publisher: publish.yml on ggalloni/CosmoForge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file picslike-1.0.0rc2-py3-none-any.whl.

File metadata

  • Download URL: picslike-1.0.0rc2-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for picslike-1.0.0rc2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c9a5a7bd0d208ed7ec288807a521ef19349d3a4a81754c066613518b9fc6a22
MD5 b7b7a62c2004c8c3394c3a57a9bcc530
BLAKE2b-256 9592c93a938ae48b341862a0c5d99d0b8c1c5d3636fbc64bd06e094407d9d583

See more details on using hashes here.

Provenance

The following attestation bundles were made for picslike-1.0.0rc2-py3-none-any.whl:

Publisher: publish.yml on ggalloni/CosmoForge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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