lir.aggregation module

class lir.aggregation.AggregatePlot(plot_fn: Callable, plot_name: str, output_path: Path | None = None, **kwargs: Any)[source]

Bases: Aggregation

Aggregation that generates plots by repeatedly calling a plotting function.

Parameters:
  • plot_fn (Callable) – The plotting function to be used for generating plots.

  • plot_name (str) – The name of the plot.

  • output_path (Path | None, optional) – The directory where the plots will be saved. If None, plots are not saved.

  • **kwargs (Any) – Additional arguments to be passed to the plotting function.

output_path

The directory where the plots will be saved. If None, plots are not saved.

Type:

Path | None

plot_fn

The plotting function to be used for generating plots.

Type:

Callable

plot_name

The name of the plot.

Type:

str

plot_fn_args

Additional arguments to be passed to the plotting function.

Type:

dict[str, Any]

report(data: AggregationData) None[source]

Plot the data when new results are available.

Parameters:

data (AggregationData) – The aggregated data to be plotted.

class lir.aggregation.Aggregation[source]

Bases: ABC

Base representation of an aggregated data collection.

Other classes may extend from this class.

close() None[source]

Finalize the aggregation; no more results will come in.

The close method is called at the end of gathering the aggregation(s) to ensure files are closed, buffers are cleared, or other things that need to finish / tear down.

abstractmethod report(data: AggregationData) None[source]

Report that new results are available.

Parameters:

data (AggregationData) – The aggregated data to be reported.

class lir.aggregation.AggregationData(llrdata: LLRData, lrsystem: LRSystem, parameters: dict[str, Any], run_name: str, get_full_fit_lrsystem: Callable[[], LRSystem] | None = None)[source]

Bases: NamedTuple

Representation of aggregated data.

llrdata

The LLR data containing LLRs and labels.

Type:

LLRData

lrsystem

The model that produced the results.

Type:

LRSystem

parameters

Parameters that identify the system producing the results.

Type:

dict[str, Any]

run_name

String representation of the run that produced the results.

Type:

str

get_full_fit_lrsystem

Optional callable that lazily provides a model fitted on full data (ignoring splits).

Type:

Callable[[], LRSystem] | None

get_full_fit_lrsystem: Callable[[], LRSystem] | None

Alias for field number 4

llrdata: LLRData

Alias for field number 0

lrsystem: LRSystem

Alias for field number 1

parameters: dict[str, Any]

Alias for field number 2

run_name: str

Alias for field number 3

class lir.aggregation.CaseLLRToCsv(output_dir: Path, case_data_provider: DataProvider, filename: str = 'case_llr.csv')[source]

Bases: Aggregation

Aggregation that applies a full-data-fitted LR system to case data and stores LLRs as CSV.

Parameters:
  • output_dir (Path) – Directory where the CSV file will be written.

  • case_data_provider (DataProvider) – Provider for the case data to apply the LR system to.

  • filename (str, optional) – Name of the output CSV file, by default ‘case_llr.csv’.

report(data: AggregationData) None[source]

Apply the full-data-fitted LR system to the case data and store the resulting LLRs as CSV.

Parameters:

data (AggregationData) – Aggregation data containing the fitted LR system and case data.

class lir.aggregation.SubsetAggregation(aggregation_methods: list[Aggregation], category_field: str)[source]

Bases: Aggregation

Aggregation method that manages data categorization.

A separate aggregation method is used for each category.

Parameters:
  • aggregation_methods (list[Aggregation]) – A list of methods to aggregate results by category.

  • category_field (str) – The name of the category field.

close() None[source]

Close all subset aggregation methods.

report(data: AggregationData) None[source]

Report that new results are available.

The data are categorized into subsets and forwarded to the actual aggregation method.

Parameters:

data (AggregationData) – The aggregated data to be reported.

class lir.aggregation.WriteMetricsToCsv(path: Path, columns: Mapping[str, Callable])[source]

Bases: Aggregation

Helper class to write aggregated results to CSV file.

Parameters:
  • path (Path) – The path to the CSV file where the metrics will be written.

  • columns (Mapping[str, Callable]) – A mapping of column names to metric functions that compute the values for those columns.

close() None[source]

Ensure the CSV file is properly closed after writing.

report(data: AggregationData) None[source]

Write the metrics to CSV.

Parameters:

data (AggregationData) – The aggregated data for which to compute and write the metrics.