输入、重复点与 essential points

English

接受的 array-like 输入

每个 diagram 都必须由实数值组成,并可以转换为形状为 (n, 2)float64 数组:

import numpy as np
import topp

topp.bottleneck_distance([[0, 1], [1, 3]], np.array([[0.0, 2.0]]))

列表、元组、NumPy 数组、整数数组和非连续视图均可使用。元素可以是 Python/NumPy 实数、DecimalFraction。Topp 会验证输入,并复制到按 C 顺序连续的 float64 存储中;超出 float64 范围的有限值不会被转换成无穷。

空 diagrams

两种常见写法都可使用:

empty_a = []
empty_b = np.empty((0, 2))

assert topp.bottleneck_distance(empty_a, empty_b) == 0.0

对角点与重复点

有限对角点 (a, a) 的贡献为零,距离计算会忽略它。重复的非对角行保留重数:

duplicates = [[0.0, 1.0], [0.0, 1.0], [0.0, 1.0]]
assert topp.bottleneck_distance(duplicates, duplicates) == 0.0

Essential points

支持三种形式:

import math

positive = [1.0, math.inf]
negative = [-math.inf, 2.0]
fully = [-math.inf, math.inf]

Essential points 只能匹配相同类型:

a = [[1.0, math.inf], [-math.inf, 2.0], [-math.inf, math.inf]]
b = [[2.0, math.inf], [-math.inf, 4.0], [-math.inf, math.inf]]

assert topp.bottleneck_distance(a, b) == 2.0
assert topp.wasserstein_distance(a, b) == 3.0

任一 essential 类型的重数不同时,结果为 inf

非法输入

复数、MaskedArray、布尔值、数字字符串和其他非实数输入会触发 TypeError。无法表示为 float64 的有限值、NaN、birth > deathbirth=+infdeath=-inf 和其他非法无穷形式会触发 ValueError。Topp 不会丢弃虚部或 mask、交换坐标,也不会静默删除非法行。

>>> topp.prepare_diagram([[2.0, 1.0]])
Traceback (most recent call last):
...
ValueError: diagram points must satisfy birth <= death

匹配规则见数学约定