COSMICStroopOutput

class cosmic.output.COSMICStroopOutput(bpp, bcm, initC, kick_info, samples, param_names, weights, is_hit, generation, gaussian_idx, num_explored, num_hits, fraction_explored, label=None)[source]

Bases: COSMICOutput

Results from a STROOPWAFEL adaptive importance-sampling run.

Extends COSMICOutput with the sampled parameters, importance weights, hit flags, and STROOPWAFEL bookkeeping arrays.

The link between the numpy arrays and the COSMIC tables is bin_num: samples[bin_num], weights[bin_num], and is_hit[bin_num] all correspond to the row(s) in bpp/bcm/initC/kick_info with that bin_num. Bin numbers are assigned sequentially (0-indexed) across all batches so they can be used directly as array indices.

Parameters:
bpp, bcm, initC, kick_infopandas.DataFrame

COSMIC output tables (concatenated across all batches).

samplesnumpy.ndarray

(N, D) array of sampled parameters in physical space.

param_nameslist of str

Parameter names corresponding to the columns of samples.

weightsnumpy.ndarray

(N,) importance-sampling weights.

is_hitnumpy.ndarray

(N,) boolean array; True where the system satisfied the hit criterion.

generationnumpy.ndarray

(N,) integer array — 0 = exploration phase, 1+ = refinement generation.

gaussian_idxnumpy.ndarray

(N,) integer array — -1 = drawn from prior, k = drawn from Gaussian k.

num_exploredint

Number of systems evolved during the exploration phase.

num_hitsint

Total raw hit count across all phases.

fraction_exploredfloat

Fraction of total systems used for exploration.

labelstr, optional

Human-readable label for the run, by default None

Container for COSMIC output data components.

Can be initialized either from data components directly or by loading from an HDF5 file.

Parameters:
bpppandas.DataFrame, optional

Important evolution timestep table, by default None

bcmpandas.DataFrame, optional

User-defined timestep table, by default None

initCpandas.DataFrame, optional

Initial conditions table, by default None

kick_infopandas.DataFrame, optional

Natal kick information table, by default None

filestr, optional

Filename/path to HDF5 file to load data from, by default None

labelstr, optional

Optional label for the output instance, by default None

file_key_suffixstr, optional

Suffix to append to dataset keys when loading from file, by default ‘’. E.g. if set to ‘_singles’, datasets ‘bpp_singles’, ‘bcm_singles’, etc. will be loaded as bpp, bcm, etc.

Raises:
ValueError

If neither file nor all data components are provided.

Attributes Summary

hit_rate

Importance-weighted hit rate: sum(w[is_hit]) / N.

hit_rate_uncertainty

Standard error on the importance-weighted hit rate.

Methods Summary

draw_representative_sample(n_samples[, rng])

Draw a representative sample of hits from the explored systems.

from_file(path[, label])

Load from an HDF5 file written by save().

save(output_file)

Save to an HDF5 file.

Attributes Documentation

hit_rate[source]

Importance-weighted hit rate: sum(w[is_hit]) / N.

Returns:
float
hit_rate_uncertainty[source]

Standard error on the importance-weighted hit rate.

Returns std(w[is_hit], ddof=1) / sqrt(N), or 0.0 if fewer than two hits are present.

Returns:
float

Methods Documentation

draw_representative_sample(n_samples, rng=None)[source]

Draw a representative sample of hits from the explored systems.

Performs a weighted bootstrap: hits are drawn with replacement in proportion to their importance weights, yielding a set of systems distributed according to the true (prior-weighted) population that can be analysed without any further weighting.

Parameters:
n_samplesint

Number of hits to draw.

rngnumpy.random.Generator, optional

Random number generator to use for sampling. If None, a new default generator is created.

Returns:
representative_samplenumpy.ndarray

Array of shape (n_samples, D) containing the drawn samples in physical space.

bin_numsnumpy.ndarray

Array of shape (n_samples,) containing the corresponding bin numbers, so the full evolution history of each drawn system can be recovered from the bpp/bcm/initC/kick_info tables (e.g. self.initC.loc[bin_num]).

classmethod from_file(path, label=None)[source]

Load from an HDF5 file written by save().

Parameters:
pathstr

File path to read.

labelstr, optional

Override the stored label, by default None

Returns:
COSMICStroopOutput
save(output_file)[source]

Save to an HDF5 file.

Writes COSMIC tables via the parent save, then appends STROOPWAFEL arrays to a stroopwafel/ group.

Parameters:
output_filestr

Filename/path to create or overwrite.