Compare
Similarity metrics for comparing device structures.
This module provides various metrics for quantifying the similarity between two Device objects, including general-purpose metrics (MSE) and binary-specific metrics (IoU, Hamming distance, Dice coefficient).
dice_coefficient(device_a, device_b)
Calculate the Dice coefficient between two binary devices.
Also known as the Sørensen-Dice coefficient or F1 score. The Dice coefficient measures similarity as twice the intersection divided by the sum of the sizes of both sets. Higher values indicate greater similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_a
|
Device
|
The first device (should be binarized for meaningful results). |
required |
device_b
|
Device
|
The second device (should be binarized for meaningful results). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The Dice coefficient. Range: [0, 1], where 1 indicates perfect overlap. |
Source code in prefab/compare.py
hamming_distance(device_a, device_b)
Calculate the Hamming distance between two binary devices.
The Hamming distance is the count of positions where corresponding pixels differ. Lower values indicate greater similarity, with 0 representing identical devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_a
|
Device
|
The first device (should be binarized for meaningful results). |
required |
device_b
|
Device
|
The second device (should be binarized for meaningful results). |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of differing pixels. Range: [0, total_pixels], where 0 indicates identical devices. |
Source code in prefab/compare.py
intersection_over_union(device_a, device_b)
Calculate the Intersection over Union (IoU) between two binary devices.
Also known as the Jaccard index. IoU measures the overlap between two binary masks as the ratio of their intersection to their union. Higher values indicate greater similarity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_a
|
Device
|
The first device (should be binarized for meaningful results). |
required |
device_b
|
Device
|
The second device (should be binarized for meaningful results). |
required |
Returns:
| Type | Description |
|---|---|
float
|
The IoU score. Range: [0, 1], where 1 indicates perfect overlap. |
Source code in prefab/compare.py
mean_squared_error(device_a, device_b)
Calculate the mean squared error (MSE) between two devices.
MSE quantifies the average squared difference between corresponding pixels. Lower values indicate greater similarity, with 0 representing identical devices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_a
|
Device
|
The first device. |
required |
device_b
|
Device
|
The second device. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The mean squared error. Range: [0, ∞), where 0 indicates identical devices. |