lir.transform.distance module

class lir.transform.distance.ElementWiseDifference[source]

Bases: Transformer

Calculate the element-wise absolute difference between pairs.

Takes an array of sample pairs and returns the element-wise absolute difference.

Expects: - a PairedFeatureData object with n_trace_instances=1 and n_ref_instances=1;

Return type:

  • a copy of the FeatureData object with features of shape (n, f)

apply(instances: InstanceData) FeatureData[source]

Calculate the absolute difference between all elements in the instance data (pairs).

Parameters:

instances (InstanceData) – Input instances to be processed by this method.

Returns:

FeatureData object parsed from the source.

Return type:

FeatureData

class lir.transform.distance.EuclideanDistance[source]

Bases: Transformer

Calculate the Euclidean distance between pairs.

Takes a PairedFeatureData object or a FeatureData object and returns the euclidean distance.

If the input is a PairedFeatureData object, the distance is computed as the euclidean distance, i.e. the square root of the sum of the squared element-wise difference between both sides of the pairs, for all features.

If the input is a FeatureData object, it is assumed that it contains the element-wise differences, and the square root of the sum over these differences is calculated.

In yaml configurations, it can be used by specifying euclidean_distance, e.g.: scoring: euclidean_distance

apply(instances: InstanceData) FeatureData[source]

Calculate the Euclidean distance between all elements in the instance data (pairs).

Parameters:

instances (InstanceData) – Input instances to be processed by this method.

Returns:

FeatureData object parsed from the source.

Return type:

FeatureData

class lir.transform.distance.ManhattanDistance[source]

Bases: Transformer

Calculate the Manhattan distance between pairs.

Takes a PairedFeatureData object or a FeatureData object and returns the manhattan distance.

If the input is a PairedFeatureData object, the distance is computed as the manhattan distance, i.e. the sum of the element-wise difference between both sides of the pairs, for all features.

If the input is a FeatureData object, it is assumed that it contains the element-wise differences, and the sum over these differences is calculated.

apply(instances: InstanceData) FeatureData[source]

Calculate the Manhattan distance between all elements in the instance data (pairs).

Parameters:

instances (InstanceData) – Input instances to be processed by this method.

Returns:

FeatureData object parsed from the source.

Return type:

FeatureData