ZHitsAtK

class ZHitsAtK(base_cls: str | RankBasedMetric | type[RankBasedMetric] | None = None, **kwargs)[source]

基础类: ZMetric

k处的z得分命中数(\(ZAH_k\))。

初始化派生指标。

Parameters:
  • base_cls (ClassVar[type[RankBasedMetric] | None]) – 基类或其提示。如果为None,则使用类属性

  • kwargs – 用于实例化基础指标的额外基于关键字的参数

属性摘要

binarize

指标是否需要二值化分数

closed_expectation

是否存在期望的闭式解

closed_variance

是否存在方差的闭式解

increasing

Z-adjusted 指标被设计为递增的

key

返回用于度量结果字典的键。

name

指标的名称

needs_candidates

指标是否需要每个排名任务的候选者数量

supported_rank_types

Z-adjusted 指标只能应用于实际的排名

supports_weights

指标是否支持权重

synonyms

此指标的同义词

value_range

取值范围

方法总结

__call__(ranks[, num_candidates, weights])

评估指标。

adjust(base_metric_result, num_candidates[, ...])

根据候选人的数量调整基础指标结果。

expected_value(num_candidates[, ...])

计算预期的指标值。

extra_repr()

生成额外的 repr,参见。

get_coefficients(num_candidates[, weights])

计算缩放系数。

get_description()

获取描述。

get_link()

从docdata中获取链接。

get_range()

获取此指标范围的数学表示。

get_sampled_values(num_candidates, num_samples)

在采样的排名数组上计算指标。

iter_extra_repr()

遍历extra_repr()的组件。

numeric_expected_value(**kwargs)

通过求和计算预期的指标值。

numeric_expected_value_with_ci(**kwargs)

估计带有置信区间的期望值。

numeric_variance(**kwargs)

通过求和计算方差。

numeric_variance_with_ci(**kwargs)

估计带有置信区间的方差。

std(num_candidates[, num_samples, weights])

计算标准差。

variance(num_candidates[, num_samples, weights])

计算方差。

属性文档

binarize: ClassVar[bool] = False

指标是否需要二值化分数

closed_expectation: ClassVar[bool] = True

是否存在期望的闭式解

closed_variance: ClassVar[bool] = True

是否存在方差的闭式解

increasing: ClassVar[bool] = True

Z-adjusted 指标被设计为递增的

key

返回用于度量结果字典的键。

name: ClassVar[str] = 'z-Hits at K'

指标的名称

needs_candidates: ClassVar[bool] = True

指标是否需要每个排名任务的候选者数量

supported_rank_types: ClassVar[Collection[Literal['optimistic', 'realistic', 'pessimistic']]] = ('realistic',)

Z-adjusted 指标只能应用于实际的排名

supports_weights: ClassVar[bool] = True

指标是否支持权重

synonyms: ClassVar[Collection[str]] = ('z_hits_at_', 'zahk')

此指标的同义词

value_range: ClassVar[ValueRange] = ValueRange(lower=None, lower_inclusive=False, upper=None, upper_inclusive=False)

取值范围

方法文档

__call__(ranks: ndarray, num_candidates: ndarray | None = None, weights: ndarray | None = None) float

评估指标。

Parameters:
  • ranks (ndarray) – 形状: s 各个排名

  • num_candidates (ndarray | None) – 形状: s 每个单独排名任务的候选数量

  • weights (ndarray | None) – 形状: s 各个等级的权重

Return type:

float

adjust(base_metric_result: float, num_candidates: ndarray, weights: ndarray | None = None) float

根据候选人的数量调整基础指标结果。

Parameters:
  • base_metric_result (float) – 基础指标的结果

  • num_candidates (ndarray) – 候选者的数量

  • weights (ndarray | None) – 形状: s 各个排名任务的权重

Returns:

调整后的指标

Return type:

float

注意

由于调整仅取决于候选者的数量,而不是预测的排名,因此该方法也可用于调整已发布的结果,而无需访问训练好的模型。

expected_value(num_candidates: ndarray, num_samples: int | None = None, weights: ndarray | None = None, **kwargs) float

计算预期的指标值。

期望值是在假设每个个体排名遵循离散均匀分布 \(\mathcal{U}\left(1, N_i\right)\) 的情况下计算的,其中 \(N_i\) 表示排名任务 \(r_i\) 的候选者数量。

Parameters:
  • num_candidates (ndarray) – 每个单独排名计算的候选数量

  • num_samples (int | None) – 用于模拟的样本数量,如果没有实现闭式期望值

  • weights (ndarray | None) – 形状: s 各个排名任务的权重

  • kwargs – 如果没有封闭形式的解决方案,则传递给get_sampled_values()的额外基于关键字的参数

Returns:

该指标的期望值

Raises:

NoClosedFormError – 如果未实现闭式期望且未给出样本数量,则抛出此错误

Return type:

float

注意

如果可用,优先选择解析解,但会回退到通过求和进行数值估计,参见 RankBasedMetric.numeric_expected_value()

extra_repr() str

生成额外的 repr,参见 :meth`torch.nn.Module.extra_repr`。

Returns:

repr() 的额外部分

Return type:

str

get_coefficients(num_candidates: ndarray, weights: ndarray | None = None) AffineTransformationParameters

计算缩放系数。

Parameters:
  • num_candidates (ndarray) – 候选者的数量

  • weights (ndarray | None) – 各个排名任务的权重

Returns:

一个元组 (scale, offset)

Return type:

AffineTransformationParameters

classmethod get_description() str

获取描述。

Return type:

str

从docdata中获取链接。

Return type:

str

classmethod get_range() str

获取此指标范围的数学表示。

Return type:

str

get_sampled_values(num_candidates: ndarray, num_samples: int, weights: ndarray | None = None, generator: Generator | None = None, memory_intense: bool = True) ndarray

在采样的排名数组上计算指标。

Parameters:
  • num_candidates (ndarray) – 形状: s 每个排名任务的候选数量

  • num_samples (int) – 样本数量

  • weights (ndarray | None) – 形状: s 各个排名任务的权重

  • generator (Generator | None) – 用于可重复性的随机状态

  • memory_intense (bool) – 是否使用更占用内存但更节省时间的变体

Returns:

形状: (num_samples,) 在num_samples采样的排名数组上评估的指标

Return type:

ndarray

iter_extra_repr() Iterable[str]

遍历extra_repr()的组件。

此方法通常被重写。一个常见的模式是

def iter_extra_repr(self) -> Iterable[str]:
    yield from super().iter_extra_repr()
    yield "<key1>=<value1>"
    yield "<key2>=<value2>"
Returns:

一个可迭代的extra_repr()的各个组件

Return type:

Iterable[str]

numeric_expected_value(**kwargs) float

通过求和计算预期的指标值。

期望值是在假设每个个体排名遵循离散均匀分布\(\mathcal{U}\left(1, N_i\right)\)的情况下计算的,其中\(N_i\)表示排名任务\(r_i\)的候选者数量。

Parameters:

kwargs – 传递给get_sampled_values()的基于关键字的参数

Returns:

该指标的估计期望值

Return type:

float

警告

根据指标的不同,估计可能不太准确且收敛缓慢,参见 https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_discrete.expect.html

numeric_expected_value_with_ci(**kwargs) ndarray

估计带有置信区间的期望值。

Return type:

ndarray

numeric_variance(**kwargs) float

通过求和计算方差。

方差的计算基于每个个体排名遵循离散均匀分布的假设 \(\mathcal{U}\left(1, N_i\right)\),其中 \(N_i\) 表示排名任务 \(r_i\) 的候选者数量。

Parameters:

kwargs – 传递给get_sampled_values()的基于关键字的参数

Returns:

此指标的估计方差

Return type:

float

警告

根据指标的不同,估计可能不太准确且收敛缓慢,参见 https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_discrete.expect.html

numeric_variance_with_ci(**kwargs) ndarray

估计带有置信区间的方差。

Return type:

ndarray

std(num_candidates: ndarray, num_samples: int | None = None, weights: ndarray | None = None, **kwargs) float

计算标准差。

Parameters:
  • num_candidates (ndarray) – 每个单独排名计算的候选数量

  • num_samples (int | None) – 用于模拟的样本数量,如果没有实现闭式期望值

  • weights (ndarray | None) – 形状: s 各个排名任务的权重

  • kwargs – 传递给variance()的额外基于关键字的参数,

Returns:

该指标的标准差(即方差的平方根)

Return type:

float

有关详细解释,请参见 RankBasedMetric.variance()

variance(num_candidates: ndarray, num_samples: int | None = None, weights: ndarray | None = None, **kwargs) float

计算方差。

方差的计算基于每个个体排名遵循离散均匀分布的假设 \(\mathcal{U}\left(1, N_i\right)\),其中 \(N_i\) 表示排名任务 \(r_i\) 的候选者数量。

Parameters:
  • num_candidates (ndarray) – 每个单独排名计算的候选数量

  • num_samples (int | None) – 用于模拟的样本数量,如果没有实现闭式期望值

  • weights (ndarray | None) – 形状: s 各个排名任务的权重

  • kwargs – 传递给 get_sampled_values() 的额外基于关键字的参数,如果没有可用的闭式解

Returns:

该指标的方差

Raises:

NoClosedFormError – 如果没有实现闭式方差并且没有给出样本数量,则引发此错误

Return type:

float

注意

如果可用,优先选择解析解,但会回退到通过求和进行数值估计,参见 RankBasedMetric.numeric_variance()