lir.datasets package
Submodules
lir.datasets.alcohol_breath_analyser module
- class lir.datasets.alcohol_breath_analyser.AlcoholBreathAnalyser(ill_calibrated: bool = False)[source]
Bases:
DataProviderAlcohol Breath Analyser example class.
- Example from paper:
Peter Vergeer, Andrew van Es, Arent de Jongh, Ivo Alberink and Reinoud Stoel, Numerical likelihood ratios outputted by LR systems are often based on extrapolation: When to stop extrapolating? In: Science and Justice 56 (2016) 482–491.
- Parameters:
ill_calibrated (bool) – Whether to load the intentionally ill-calibrated variant of the dataset.
lir.datasets.feature_data_csv module
- class lir.datasets.feature_data_csv.DataField(field_name: str, column_names: list[str], validate_cell: ~collections.abc.Callable[[str], ~typing.Any] = <class 'str'>)[source]
Bases:
objectA data field for parsing a CSV file into an
InstanceDataobject.
- class lir.datasets.feature_data_csv.ExtraField(field_name: str, column_name: str, validate_cell: Callable[[str], Any])[source]
Bases:
DataFieldExtra field for CSV parsing.
- class lir.datasets.feature_data_csv.FeatureDataCsvParser(file: Callable[[], IO] | str | Path, /, *, source_id_column: str | list[str] | None = None, hypothesis_column: str | None = None, label_column: str | None = None, feature_columns: str | list[str] | None = None, instance_id_column: str | None = None, role_assignment_column: str | None = None, fold_assignment_column: str | None = None, extra_fields: list[ExtraField] | None = None, ignore_columns: list[str] | None = None, head: int | None = None, message_prefix: str | None = None, continue_on_error: bool = False)[source]
Bases:
DataProviderParse a CSV file into an
InstanceDataobject.The CSV contents can be a URL, a file path, or a function with no arguments that returns a data stream.
- Parameters:
file (Callable[[], IO] | str | Path) – Reference to the contents of a CSV file.
source_id_column (str | list[str] | None) – Column name(s) containing source identifiers (each source has a unique string identifier).
hypothesis_column (str | None) – Column name containing hypothesis labels (value 0 for H2 or 1 for H2).
label_column (str | None) – Deprecated alias for hypothesis_column.
feature_columns (str | list[str] | None) – Column names containing numerical feature values. If not specified, all columns not otherwise designated are interpreted as feature columns.
instance_id_column (str | None) – Column name containing instance identifiers.
role_assignment_column (str | None) – Column name containing predefined roles (value ‘train’ for training or ‘test’ for test).
fold_assignment_column (str | None) – Column name containing predefined fold assignments (each fold has a unique string identifier).
extra_fields (list[ExtraField] | None) – Optional extra fields to parse from each row.
ignore_columns (list[str] | None) – Column names ignored when extracting features. This attribute is ignored if feature_columns is available.
head (int | None) – Maximum number of rows to read from the source.
message_prefix (str | None) – Prefix added to parser log and error messages.
continue_on_error (bool) – If True, a row will be dropped if a parse error occurs. Otherwise, parsing will be aborted.
Examples
Assume a CSV file containing two features and source identifiers:
source_id,feature1,feature2,feature3,name_of_an_irrelevant_column 0,1,10,1,sherlock 0,1,11,1,holmes 1,20,30,1,irene 1,18,32,3,adler 2,5,10,8,professor 2,1,11,8,moriarty
This file can be parsed using the following YAML configuration:
data: provider: parse_features_from_csv_file path: path/to/file.csv source_id_column: source_id ignore_columns: - name_of_an_irrelevant_column
data: provider: parse_features_from_csv_url url: https://raw.githubusercontent.com/NetherlandsForensicInstitute/elemental_composition_glass/refs/heads/main/training.csv source_id_column: Item ignore_columns: - id - Piece
- get_instances() FeatureData[source]
Retrieve FeatureData instances.
- Returns:
FeatureData object parsed from the source.
- Return type:
- class lir.datasets.feature_data_csv.ImplicitFeaturesField[source]
Bases:
DataFieldA features field for parsing a CSV file into an
InstanceDataobject.This field does not require feature columns to be specified explicitly, but assumes all columns not otherwise assigned to hold feature values.
- exception lir.datasets.feature_data_csv.ParseError[source]
Bases:
ValueErrorException to be raised on parse errors.
This happens when an input file is malformatted or contains invalid input.
lir.datasets.glass module
- class lir.datasets.glass.GlassData(cache_dir: Path | str | None = None)[source]
Bases:
DataProviderLA-ICP-MS measurements of elemental concentration from floatglass.
The measurements are from reference glass from casework, collected in the past 10 years or so. For more info on the DataProvider, see: https://github.com/NetherlandsForensicInstitute/elemental_composition_glass
This data provider has a pre-defined train/test split, with a training set of three instances per source, and a test set of five instances per source.
If
cache_diris not None, data are retrieved from the web as needed and stored locally for later use. The classrequests_cache.CachedSessonfrom the requests library handles caching.- Parameters:
cache_dir (Path | str | None) – Cache directory used for storing downloaded dataset files.
- get_instances() FeatureData[source]
Return data with pre-defined assignments of training data and test data.
The training data is read from training.csv and has three instances (replicates) per source. The test data is read from duplo.csv and triplo.csv and has a total of five instances per source.
The features are elemental concentrations on a log_10 basis, and normalized to Si. The elements are: K39, Ti49, Mn55, Rb85, Sr88, Zr90, Ba137, La139, Ce140, Pb208
The source_ids are unique identifiers of a glass particle. Each particle is from a different reference window. An instance is a replicate measurement on a glass particle. Source ids are prefixed with the role assignment, e.g. ‘test-123’ and ‘train-123’. The ids ‘test-123’ and ‘train-123’ refer to different glass particles (and therefore different reference windows).
The instance_ids values of an instance are a concatenation of the filename and a row number, e.g. “training.csv:22”.
The data are returned as a FeatureData object with the following properties: - features: an (n, 10) array of feature values - source_ids: a 1d array of source ids (str) - instance_ids: a 1d array of unique instance ids (str) - role_assignments: a 1d array of role assignments (values “train” or “test”)
- Returns:
FeatureData object parsed from the source.
- Return type:
lir.datasets.synthesized_normal_binary module
- class lir.datasets.synthesized_normal_binary.SynthesizedNormalBinaryData(h1_params: SynthesizedNormalData, h2_params: SynthesizedNormalData, seed: int | None = None)[source]
Bases:
DataProviderImplementation of a data source generating normally distributed binary class data.
- Parameters:
h1_params (SynthesizedNormalData) – Distribution parameters used to sample class-1 data.
h2_params (SynthesizedNormalData) – Distribution parameters used to sample class-2 data.
seed (int | None) – Random seed controlling stochastic behaviour for reproducible results.
- get_instances() FeatureData[source]
Return instances with randomly synthesized data and binary labels.
The features are drawn from a normal distribution, as configured.
- Returns:
FeatureData object parsed from the source.
- Return type:
- class lir.datasets.synthesized_normal_binary.SynthesizedNormalData(mean: float, std: float, size: int | tuple[int, int])[source]
Bases:
objectRepresentation of normally distributed data, leveraging a number generator.
The generated data can be used to generate normally distributed data and is useful for debugging purposes or gaining insight in the effect of varying parts within the LR system pipeline.
- Parameters:
lir.datasets.synthesized_normal_multiclass module
- class lir.datasets.synthesized_normal_multiclass.SynthesizedDimension(population_mean: float, population_std: float, sources_std: float)[source]
Bases:
NamedTupleRepresentation of a data distribution.
- class lir.datasets.synthesized_normal_multiclass.SynthesizedNormalMulticlassData(dimensions: list[SynthesizedDimension], population_size: int, sources_size: int, seed: int | None)[source]
Bases:
DataProviderImplementation of a data source generating normally distributed multiclass data.
- Parameters:
dimensions (list[SynthesizedDimension]) – Number of feature dimensions to include in the header.
population_size (int) – Number of sources to sample in the synthetic population.
sources_size (int) – Number of source groups represented in the dataset.
seed (int | None) – Random seed controlling stochastic behaviour for reproducible results.
- get_instances() FeatureData[source]
Return instances with randomly synthesized data and multi-class labels.
The features are drawn from a normal distribution, as configured.
- Returns:
FeatureData object parsed from the source.
- Return type: