Learning

Detect gamma rays using machine learning

Separate simulated gamma-ray showers from hadronic background

This reproducible benchmark maps ten image descriptors from a simulated imaging atmospheric Cherenkov telescope to a hadron-class score. On 3,804 held-out events, the final model reaches an ROC AUC of 0.935. At the default score threshold of 0.50 it retains 90.2% of gamma events while rejecting 82.8% of hadronic background.

0.935testing ROC AUC
90.2%gamma efficiency at score 0.50
82.8%hadron rejection at score 0.50
3,804held-out testing events

1. Scientific objective

The task is to rank telescope-camera events by how compatible their image morphology is with hadronic background. Events with a low hadron-class score are gamma-like candidates. This is an event-selection benchmark for simulated data; it is not a source detection, a flux measurement or evidence of a gamma-ray signal.

Candidate selection

Reduce the background passed to downstream source and spectral analyses while retaining a controlled fraction of gamma events.

Operating-point design

Choose a score threshold from the required gamma efficiency and accepted hadron leakage instead of optimizing accuracy alone.

Reproducible benchmark

Inspect the exact split, model, regenerated analyses and executable Python export used for the reported results.

Gamma-ray astronomersIACT analystsHigh-energy astrophysicsDetector and ML teams
Scope. The data contains Monte Carlo events described by ten Hillas-style image parameters. The network supports simulated event ranking only; transfer to recorded telescope data requires independent, run-aware validation.

2. Data and provenance

The MAGIC Gamma Telescope data set contains 19,020 simulated events with no missing values: 12,332 gamma events (g) and 6,688 hadronic-background events (h). The examples were generated with CORSIKA and processed into approximately triggered camera images.

The analysis uses the following ten input fields exactly as they appear in the downloadable CSV and the exported model.

CSV fieldPhysical meaningUnit or scale
ellipse_major_axisMajor-axis extent of the shower imagemm
ellipse_minor_axisMinor-axis extent of the shower imagemm
log_total_pixel_signalBase-10 logarithm of total pixel contentlog signal
two_brightest_pixels_signal_ratioSignal fraction in the two brightest pixelsratio
brightest_pixel_signal_ratioSignal fraction in the brightest pixelratio
brightest_pixel_center_offset_major_axisProjected brightest-pixel offset along the major axismm
major_axis_third_moment_cuberootCube root of the third moment along the major axismm
minor_axis_third_moment_cuberootCube root of the third moment along the minor axismm
major_axis_angle_to_originMajor-axis angle to the image origindegrees
ellipse_center_distance_to_originImage-centroid distance to the originmm
SubsetRowsPurpose
Training11,412Estimate model parameters
Selection3,804Select the hidden-layer size
Testing3,804Report final performance once
Class distribution with 64.8 percent gamma and 35.2 percent hadron events
The public simulation contains more gamma than hadron events. The UCI documentation warns that this does not reflect the much larger hadronic background expected in real observations.
Pearson correlations between the ten image descriptors and encoded event type
These are univariate associations with the encoded class (g=0, h=1), not causal importance measures. The nonlinear model can use interactions that Pearson correlation does not show.
Provenance and licence. The source is the UCI MAGIC Gamma Telescope data set (DOI 10.24432/C52C8B), released under CC BY 4.0. The records are simulated rather than observed events, and the public table does not include event energy, run identifier or simulation weights.

3. Model

All ten inputs use mean-and-standard-deviation scaling. The initial network has three tanh neurons in one hidden layer and one sigmoid output, for 37 trainable parameters. This is the baseline architecture trained before the hidden-layer size is evaluated.

The output class ordering is g;h, so the sigmoid value is the score for h, the hadronic-background class.

Output contract. A high score means hadron-like; a low score means gamma-like. The value has not been calibrated as a probability and must not be presented as a gamma probability.
Initial gamma-event classifier with ten inputs, three hidden neurons and one event-type output
Initial 10–3–1 architecture used for the baseline training run before neuron selection.

4. Training strategy

The loss is weighted squared error. The gamma class receives weight 0.7712 and the less frequent hadron class weight 1.4219, so training does not simply follow the simulated class prevalence. A quasi-Newton optimizer estimates the parameters without explicit regularization.

The initial three-neuron network converged in 237 epochs: training error decreased from 0.9177 to 0.4444 and selection error from 0.8921 to 0.4404.

Weighted-squared-error history for training and selection subsets
Error history for the initial 10–3–1 network used before neuron selection.

5. Model selection and baseline

Growing-neurons selection evaluated hidden layers from one to ten neurons. The lowest stored selection error, 0.3677, occurred at ten neurons; its training error was 0.3610. The final architecture is therefore 10–10–1.

Neuron-selection curve from one to ten hidden neurons
The minimum occurs at the configured upper limit. Ten is the best tested size, but this sweep does not prove that it is the global optimum.

Selected architecture

After neuron selection, the hidden layer expands from three to ten tanh neurons. This 10–10–1 network contains 121 trainable parameters and is the model used for testing, deployment and the downloadable Python export.

Selected gamma-event classifier with ten inputs, ten hidden neurons and one event-type output
Final 10–10–1 architecture obtained after neuron selection.
ReferenceROC AUCInterpretation
Random ranking0.500No class-separation ability
Final neural network0.935Strong event ranking on the held-out simulation

6. Scientific validation

Testing uses 2,466 gamma events and 1,338 hadron events that were not used for parameter estimation or neuron selection. Because a hadron accepted as gamma contaminates the candidate sample, threshold selection is reported as gamma efficiency versus hadron rejection rather than relying on accuracy alone.

Testing metricValueMeaning
ROC AUC0.935Probability that a random hadron receives a higher hadron score than a random gamma event
Gamma efficiency at score 0.5090.2%Gamma events retained as gamma-like
Hadron rejection at score 0.5082.8%Hadron events rejected from the gamma-like sample
Hadron leakage at score 0.5017.2%Hadron events incorrectly admitted as gamma-like
Accuracy at score 0.5087.6%Supplementary metric under the simulated class mixture

Confusion matrix at hadron score 0.50

Actual / predictedGamma-likeHadron-likeTotal
Gamma2,2242422,466
Hadron2301,1081,338
Total2,4541,3503,804

Choose the threshold from the scientific objective

Hadron-score thresholdGamma efficiencyHadron rejectionHadron leakage
0.5090.2%82.8%17.2%
0.3078.3%90.4%9.6%
0.1965.6%95.0%5.0%
0.0529.8%99.0%1.0%
ROC curve with area under the curve 0.935
The ROC curve exposes the trade-off between rejecting hadronic background and retaining gamma events. The highlighted balanced point is useful for inspection, but a scientific analysis should select the threshold from its background budget and sensitivity objective.
Scientific interpretation. The model separates the two simulated classes well, but the relevant operating point depends on the expected background and downstream significance. The 87.6% accuracy is not portable to real observations because the public simulation deliberately underrepresents hadrons.

7. Inference and reproducibility

A credible workflow starts from reconstructed camera images, calculates the same ten descriptors, validates schema and ranges, evaluates the hadron-class score, and applies a threshold chosen for the analysis. Selected gamma-like candidates then enter spatial, temporal or spectral inference with exposure and systematic uncertainties.

Triggered camera image
Image cleaning and descriptors
Schema and range checks
Hadron-class score
Gamma-like candidate sample
Statistical source analysis

Representative simulated event

The following point is inside every training range and demonstrates the exported calculation. It is not a recorded telescope event.

InputValue
Ellipse major axis65 mm
Ellipse minor axis49 mm
Log total pixel signal3.20
Two-brightest-pixel ratio0.26
Brightest-pixel ratio0.14
Brightest-pixel major-axis offset−36 mm
Major-axis third-moment cube root46 mm
Minor-axis third-moment cube root28 mm
Major-axis angle to origin78°
Ellipse-centre distance to origin320 mm
Hadron-class score0.99652

At threshold 0.50, the event is classified as hadron-like and excluded from the gamma-like candidate sample.

Reproduce the inference

The Python package contains the exact exported model, ordered input schema, representative case and expected output. It was executed over all 3,804 testing events and reproduced the Neural Designer confusion matrix and ROC AUC. The project package preserves the split, trained parameters and regenerated analyses.

from model import NeuralNetwork

inputs = [65, 49, 3.2, 0.26, 0.14, -36, 46, 28, 78, 320]
hadron_score = NeuralNetwork().calculate_outputs(inputs)[0]

8. Validity, uncertainty and limitations

  • Simulation-to-data transfer is untested. The benchmark uses CORSIKA-generated events and does not validate detector response, atmospheric conditions or image cleaning on recorded observations.
  • The public prevalence is artificial. Gamma events are 64.8% of this table, whereas real observations contain substantially more hadronic background. Accuracy and sample purity therefore do not transfer directly.
  • Energy dependence is hidden. The public CSV has no event-energy column, so performance cannot be reported in the energy bins used in the source study.
  • Validation is row-random. Thirty testing feature vectors (0.79%) duplicate a training vector. A stricter benchmark would group or remove duplicates before partitioning and would validate by simulation or observation run.
  • The score is not calibrated. It is a ranking score for class h, not a posterior gamma probability. Any probabilistic use requires independent calibration under representative class priors.
  • The selection boundary was reached. Ten neurons produced the lowest selection error among the tested sizes but was also the configured maximum.
  • Scientific discovery requires more. Exposure, event weights, control regions, systematic uncertainties and a likelihood-based significance analysis are outside this example.

References