XGBoost Classification¶
This guide explains how pycWB uses XGBoost gradient-boosted trees to build a ranking classifier that separates gravitational-wave signals from background noise triggers.
Overview¶
While the coherent network SNR \(\rho\) is a powerful single statistic,
combining multiple event features with a machine-learning classifier
significantly improves search sensitivity. pycWB uses XGBoost
(eXtreme Gradient Boosting) to train a binary classifier on background and
simulated signal events. The classifier outputs a signal probability
(xgb_prob) per trigger; a ranking statistic used for FAR assignment and
detection efficiency (for example rhor) is derived from it by a
user-defined hook (see Inference (Scoring)).
Why XGBoost?¶
XGBoost is chosen for several reasons:
State-of-the-art on tabular data: Gradient-boosted trees consistently outperform deep learning on structured event features.
Fast training and inference: histogram-based tree construction (
tree_method: hist) handles millions of events.Interpretable: Feature importance scores reveal which event properties drive the classification.
Robust to hyperparameters: Works well with default settings; tuning provides modest gains.
Input Features¶
The feature list (ML_list) comes from
pycwb.modules.cwb_xgboost.config.xgb_config() for the chosen
search (blf, bhf, bld, bbh or imbhb) and may be
modified by the user’s update_config. Catalog columns are renamed to cWB
names (coherent_energy → ecor, q_veto → qveto,
q_factor → qfactor, per-detector <name>_<ifo> → <name><n> in
the catalog’s ifo_list order), and derived features are computed by
pycwb.modules.cwb_xgboost.preprocess_events().
Default feature list:
blf/bhf/bld:norm,netcc0,penalty,Lveto2,chunk,sSNR<n>/likelihoodfor \(n = 0 \ldots n_{ifo}-2\),rho0_20d0,Qa,Qp.bbh/imbhb:norm,netcc0,penalty,frequency0,bandwidth0,duration0,Lveto2,chirp1,chirp3,chunk,sSNR<n>/likelihoodfor \(n = 0 \ldots n_{ifo}-2\),rho0_11d0,Qa,Qp.
Feature definitions (as computed by preprocess_events):
\(\rho_0 = \sqrt{e_{cor} / (1 + p\,(\max(1, p) - 1))}\) with \(p\) =
penalty(ML_options['rho0(define)'] = 1, the default); withrho0(define) = 0, \(\rho_0\) is the storedrho[0].rho0_<cap>— \(\rho_0\) clipped at the capML_caps['rho0'](20 for burst searches, 11 forbbh/imbhb); the name encodes the cap, e.g.ML_caps['rho0'] = 40givesrho0_40d0.Qa— \(\sqrt{Q_{veto}[0]}\) (fromq_veto).Qp— \(Q_{veto}[1] / (2\sqrt{\log_{10}\min(200, e_{cor})})\) (fromq_factor).sSNR<n>/likelihood— per-detectorsSNRoverlikelihood.netcc0— network correlation (net_cc);norm— packet normalisation (packet_norm);Lveto2—Lveto[2];chunk— a constant 0.frequency0,bandwidth0,duration0— values of the first detector in the catalog’s detector order;chirp1,chirp3— elements 1 and 3 of the cWBchirparray.
Additional derived features available to update_config include
ecor/likelihood, mSNR/likelihood (minimum sSNR over detectors,
divided by likelihood) and noise
(\((\sum_n 1/\text{noise}_n^2)^{-1/2}\)).
Training Configuration¶
Training is configured through the workflow YAML using the
train_xgboost() action
(bkg_split is the split step shown in Background Estimation):
- id: model
name: Train XGBoost Classifier
action: postprocess.train_xgboost.train_xgboost
inputs:
bkg_catalogs: # Background selected upstream
- "@bkg_split.train.triggers_file"
- /path/to/bkg_train_1/selected_background.parquet
sim_catalogs: # Recovered, non-vetoed SIM triggers
- /path/to/sim_train_1/clean_matched.parquet
- /path/to/sim_train_2/clean_matched.parquet
config_file: ${paths.config_file} # update_config(...) and ranking hooks
args:
model_file: ${paths.model_file}
search: blf
dump: false
dump_training_review: true
verbose: false
n_threads: 6
device: cpu # cuda or cuda:0 for GPU training
outputs:
training_settings_file: ${paths.xgb_training_settings}
training_output_file: ${paths.xgb_training_output}
Training uses these catalogs as given. Prepare every input upstream: select
background with trigger_selection (exclude_zero_lag: true removes zero
lag), and keep recovered, non-vetoed simulation triggers with
filter_real_simulation. Training logs a warning when a background catalog
still contains triggers with no time or segment shift, but does not remove them,
so a workflow may deliberately use a different reference lag.
n_threads and device select training resources directly in the YAML.
n_threads must be a positive integer; it overrides the config hook’s
nthread / n_jobs setting. It also controls CPU-side work during GPU
training. Omitting it retains the configured thread count (one by default).
device accepts cpu, cuda (first visible GPU), or cuda:<ordinal>.
An explicit YAML value overrides xgb_params['device'] from update_config.
Omitting it preserves the hook’s setting or XGBoost’s CPU default. To switch
only training to GPU, change the example to:
args:
n_threads: 8
device: cuda:0
GPU training requires a CUDA-enabled XGBoost installation, a compatible NVIDIA
driver and a visible GPU. The action checks device availability before reading
catalog payloads and verifies the fitted device before publishing the model.
It rejects CPU fallback and substitution of a different explicitly requested
GPU. The default tree_method: hist supports CUDA; other hook-supplied
hyper-parameters, feature definitions, balancing and the split remain intact.
This option controls XGBoost training, not Parquet preprocessing or the device
used by later scoring steps.
Run the workflow through the Python interpreter containing CUDA-enabled XGBoost:
/path/to/cuda-env/bin/python -m pycwb post-process workflow.yaml
Activating a JAX GPU environment or setting JAX_PLATFORMS does not enable
XGBoost CUDA support. See the XGBoost GPU documentation.
Other XGBoost hyper-parameters are not action arguments: extra keys such as
n_estimators or max_depth under args are ignored. They are set in
xgb_params inside update_config. Defaults from xgb_config:
Parameter |
|
|
|---|---|---|
|
0.03 |
0.03 |
|
6 |
13 |
|
5.0 |
10.0 |
|
0.6 / 1.0 |
0.6 / 1.0 |
|
2.0 |
2.0 |
|
20000 |
20000 |
Common to all searches: objective: binary:logistic, tree_method: hist,
grow_policy: lossguide, scale_pos_weight: 1.0, seed: 150914,
nthread: 1; unless set in xgb_params, training uses
eval_metric: [logloss, auc, aucpr] and early_stopping_rounds: 50.
Training procedure (as implemented):
BKG catalogs selected upstream are concatenated and labelled
classifier = 0; training preserves that selection and warns about any unshifted (zero-lag) triggers it contains. SIM catalogs are labelledclassifier = 1; rows flaggedsim_vetoed_cat0,sim_vetoed_cat2orsim_across_segmentsare removed when those columns exist. Every other SIM row is treated as signal, so clean SIM catalogs first withfilter_real_simulation().preprocess_eventsbuilds the features, thencuts(training)(default \(\rho_0 > 6.5\)) is applied to both classes.Tail balance (
tail(training), default on): SIM events withrho0_<cap>\(\geq\) cap are resampled (seeded) to the number of BKG events in that tail; all BKG events are kept.The merged set is split 90 % / 10 % into training and evaluation samples (
random_state=xgb_params['seed']).Bulk balance (
bulk(training), default on): below the cap, BKG events receive sample weights per bin, \(W_i = (N_{sim,i}/N_{bkg,i})\,A^{(1 - i/(n_{bins}-1))^{q}}\), withnbins(training)= 100 bins whose edges are SIM percentiles (binning(training) = 'sim(percentiles)'). Defaults are \(q = 6, A = 20\) for burst searches and \(q = 1, A = 14\) forbbh/imbhb. SIM events keep weight 1.XGBClassifier.fitruns with these sample weights and the evaluation sample for early stopping.
XGBoost Configuration File¶
The config_file (conventionally xgb_config.py) must define
update_config, which receives the five objects returned by xgb_config
and mutates them in place. It may also define ranking hooks used at scoring
time (postprocess_scores, postprocess_dataframe, getrhor, or names
listed in ML_options['ranking_statistics(functions)']). The class label is
not configurable: it is the classifier column set from the catalog lists.
# Example xgb_config.py
import numpy as np
def update_config(xgb_params, ML_list, ML_caps, ML_balance, ML_options):
xrho0 = 'sqrt(ecor/(1+penalty*(max(1.0,penalty)-1)))'
ML_caps['rho0'] = 40 # feature becomes rho0_40d0
ML_balance['cuts(training)'] = xrho0 + '>6.5'
xgb_params['max_depth'] = 4
xgb_params['n_estimators'] = 500
ML_list.append('ecor/likelihood')
# Ranking hook: adds the ``rhor`` column after scoring
def getrhor(xdp, search):
source = "MLstat" if "MLstat" in xdp.columns else "xgb_prob"
prob = xdp[source].astype(float).clip(upper=0.99999999)
xdp["rhor"] = -np.log(1.0 - prob)
return xdp
Model Output¶
With a .ubj (Universal Binary JSON) or .json extension the model is
written with XGBoost’s native save_model; any other extension is pickled.
The native file holds the trained booster, feature names, the
cwb-compatible-v1 catalog preprocessing identifier and versioned evaluation
history in the pycwb_training booster attribute. Training diagnostics read
that history after JSON/UBJ reload; no separate review-text file is required.
Derived features are recomputed from config_file at scoring time, so the
same config_file must be passed to every scoring action.
With dump_training_review (or dump, or an explicit
training_settings_file / training_output_file) two review files are
also written:
training_settings_file(default<model stem>.cfg) —xgb_params,ML_list,ML_caps,ML_balance,ML_optionsand row counts at each stage.training_output_file(default<model stem>.out) — training summary, tree statistics, evaluation history and feature importances.
The action returns model_file and auc, which is XGBoost’s
best_score on the evaluation sample: the last configured eval_metric,
aucpr by default.
Inference (Scoring)¶
Training consumes background catalogs already selected upstream. Perform the
zero-lag split with trigger_selection before training or FAR estimation, as
in examples/postproduction/standard_analysis_10pct_workflow.yaml. For that
selected FAR holdout, use exclude_zero_lag: false; do not discard a selected
superlag merely because its regular lag_idx is zero.
Newly trained models record the cwb-compatible-v1 catalog field conventions
alongside their trees. Scoring rejects a missing or incompatible convention
identifier before prediction. Retrain older PycWB native-catalog models: the
norm and sSNR definitions and detector-indexed ordering have changed,
even though the feature names are unchanged.
Use postprocess.model_io.import_cwb_model for a trusted original cWB pickle.
Its fit-time evaluation history, when present, is preserved in the portable
model. A model without recorded history can still provide feature importance,
but learning curves and exact history comparisons are unavailable.
For an unversioned portable model whose training inputs have been independently
verified to use the current cWB conventions, declare that in the existing
scoring configuration hook:
def update_config(xgb_params, ML_list, ML_caps, ML_balance, ML_options):
ML_options["model_preprocessing"] = "cwb-compatible-v1"
This declaration does not convert incompatible old models and cannot override an incompatible identifier already recorded in a model. Keep the training feature caps and other configuration choices consistent with scoring as well.
Trained models are applied to new catalogs via the scoring actions:
evaluate_far_rho()— score the FAR background and build the FAR lookup tablescore_catalog()— score any catalog (lag_selection:all,zero_lagornonzero_lag)evaluate_efficiency()— score a SIM catalog and write it for the efficiency actions (Detection Efficiency)score_mdc_catalog()— score the zero-lag triggers of a blind MDC catalog and list detections above an IFAR threshold
Each scoring action:
builds the model’s features with
preprocess_events(features absent from the catalog are filled with 0);writes
xgb_prob(the positive-class probability) and a copy namedMLstat;runs the ranking hooks from
config_file, e.g.getrhorabove giving \(\rho_r = -\ln(1 - \min(\text{MLstat}, 0.99999999))\);drops triggers that fail
cuts(prediction)(default \(\rho_0 > 7.2\) for burst searches, \(\rho_0 > 6.5\) forbbh/imbhb).
The statistic used for FAR is selected with ranking_par. It defaults to
rho in evaluate_far_rho, so set it explicitly.
- id: far_rho
name: Score FAR Holdout And Build FAR(ρ)
action: postprocess.evaluate.evaluate_far_rho
inputs:
catalog_file: "@bkg_split.far.triggers_file"
model_file: ${paths.model_file}
config_file: ${paths.config_file}
args:
livetime: "@bkg_split.far.livetime.seconds"
exclude_zero_lag: false # Preserve the upstream background selection
ranking_par: rhor
bin_size: 0.0001
vmin: 0.0
vmax: 10.0
outputs:
output_file: ${paths.far_rho_file} # binned FAR JSON
scored_catalog: tmp://bkg_far_scored.parquet # scored FAR background
Performance Considerations¶
Multi-catalog batching: The training action accepts lists of background and simulation catalogs via
bkg_catalogsandsim_catalogs, enabling training across multiple observing chunks simultaneously. Only the columns needed by the configured features are read from Parquet.Class balancing: SIM/BKG imbalance is handled by the tail resampling and bulk sample weights described above (
ML_balance);scale_pos_weightstays at 1.0 unless changed inupdate_config.Threads and GPU:
xgb_params['nthread']defaults to 1; raise it inupdate_configto train on more cores.tree_method: gpu_histis rejected by current XGBoost releases; for GPU training setxgb_params['device'] = 'cuda'and keeptree_method: hist.
Feature Importance¶
After training, feature importance scores are written to the
training_output_file (.out). It contains one section for each XGBoost
importance type (weight, gain, cover, total_gain,
total_cover), with features sorted by decreasing score:
[feature_importance_gain]
rho0_20d0 = <score>
netcc0 = <score>
penalty = <score>
...
Evaluate the trained model¶
Keep model-training data separate from FAR and sensitivity evaluation samples.
With interval_livetime, compare the selected (shift_key, lag_idx)
intervals; the same job IDs can appear in both partitions. With a whole-job
split, compare the job lists.
Compare the trained ranking with the original statistic at the same FAR on an independent evaluation population. Inspect feature distributions across data chunks and the training diagnostics in Postproduction Reports when investigating a change in performance.
See also: Background Estimation · Training Set Preparation · Detection Efficiency
Next: Detection Efficiency — measuring detection sensitivity