Utils & Metrics¶
_1d¶
_clip¶
_reduction¶
binaryzation¶
- pyldl.algorithms.utils.binaryzation(D: ndarray, method='threshold', param: any | None = None) ndarray[source]¶
Transform label distribution matrix to logical label matrix.
- Parameters:
D (np.ndarray) – Label distribution matrix (shape: \([n,\, l]\)).
method ({'threshold', 'topk'}, optional) –
Type of binaryzation method, defaults to ‘threshold’. The options are ‘threshold’ and ‘topk’, which can refer to:
[BIN-KWT+24]Zhiqiang Kou, Jing Wang, Jiawei Tang, Yuheng Jia, Boyu Shi, and Xin Geng. Exploiting multi-label correlation in label distribution learning. In Proceedings of the International Joint Conference on Artificial Intelligence, 4326–4334. 2024. URL: https://doi.org/10.24963/ijcai.2024/478.
param (any, optional) – Parameter of binaryzation method, defaults to None. If None, the default value is .5 for ‘threshold’ and \(\lfloor l / 2 \rfloor\) for ‘topk’.
- Returns:
Logical label matrix (shape: \([n,\, l]\)).
- Return type:
np.ndarray
csr2sparse¶
estimate_alpha¶
kernel¶
kl_divergence\(\downarrow\)¶
locass_proj¶
non_diagonal¶
normalize¶
pairwise_cosine¶
pairwise_euclidean¶
pairwise_pearsonr¶
proj¶
shannon_entropy¶
soft_thresholding¶
- pyldl.algorithms.utils.soft_thresholding(A: ndarray, tau: float) ndarray[source]¶
Soft thresholding operation. It is defined as \(\text{soft}(\boldsymbol{A}, \, \tau) = \text{sgn}(\boldsymbol{A}) \odot \max\lbrace \lvert \boldsymbol{A} \rvert - \tau, 0 \rbrace\), where \(\odot\) denotes element-wise multiplication.
- Parameters:
A (np.ndarray) – Matrix \(\boldsymbol{A}\).
tau (float) – \(\tau\).
- Returns:
The result of soft thresholding operation.
- Return type:
np.ndarray
softmax¶
solvel21¶
- pyldl.algorithms.utils.solvel21(A: ndarray, tau: float) ndarray[source]¶
This approach is proposed in paper [CY14].
The solution to the optimization problem \(\mathop{\arg\min}_{\boldsymbol{X}} \Vert \boldsymbol{X} - \boldsymbol{A} \Vert_\text{F}^2 + \tau \Vert \boldsymbol{X} \Vert_{2,\,1}\) is given by the following formula:
\[\begin{split}\vec{x}_{\bullet j}^{\ast} = \left\{ \begin{aligned} & \frac{\Vert \vec{a}_{\bullet j} \Vert - \tau}{\Vert \vec{a}_{\bullet j} \Vert} \vec{a}_{\bullet j}, & \tau \le \Vert \vec{a}_{\bullet j} \Vert \\ & 0, & \text{otherwise} \end{aligned} \right.\text{.}\end{split}\]where \(\vec{x}_{\bullet j}\) is the \(j\)-th column of matrix \(\boldsymbol{X}\), and \(\vec{a}_{\bullet j}\) is the \(j\)-th column of matrix \(\boldsymbol{A}\).
- Parameters:
A (np.ndarray) – Matrix \(\boldsymbol{A}\).
tau (float) – \(\tau\).
- Returns:
The solution to the optimization problem.
- Return type:
np.ndarray
svt¶
- pyldl.algorithms.utils.svt(A: ndarray, tau: float) ndarray[source]¶
Singular value thresholding (SVT) is proposed in paper [CCS10].
The solution to the optimization problem \(\mathop{\arg\min}_{\boldsymbol{X}} \Vert \boldsymbol{X} - \boldsymbol{A} \Vert_\text{F}^2 + \tau \Vert \boldsymbol{X} \Vert_{\ast}\) is given by \(\boldsymbol{U} \max \lbrace \boldsymbol{\Sigma} - \tau, 0 \rbrace \boldsymbol{V}^\top\), where \(\boldsymbol{A} = \boldsymbol{U} \boldsymbol{\Sigma} \boldsymbol{V}^\top\) is the singular value decomposition of matrix \(\boldsymbol{A}\).
- Parameters:
A (np.ndarray) – Matrix \(\boldsymbol{A}\).
tau (float) – \(\tau\).
- Returns:
The solution to the optimization problem.
- Return type:
np.ndarray
_random_mask¶
_weighted_mask¶
artificial¶
download_dataset¶
emphasize¶
gaussian_noise¶
load_dataset¶
make_ldl¶
plot_artificial¶
random_exchange¶
random_missing¶
regressor2ldl¶
_nu¶
_register¶
_uniform_vector¶
accuracy\(\uparrow\)¶
canberra\(\downarrow\)¶
chebyshev\(\downarrow\)¶
chi2\(\downarrow\)¶
clark\(\downarrow\)¶
cosine\(\uparrow\)¶
divisiveness_error\(\downarrow\)¶
dpa\(\uparrow\)¶
- pyldl.metrics.dpa(D, D_pred)[source]¶
- pyldl.metrics.dpa(X: ndarray, Y: ndarray | None = None, **kwargs)
Degree percentile average (DPA) is proposed in paper [LDL-JQLL24]. It is defined as:
\[\text{DPA}(\boldsymbol{u}, \, \boldsymbol{v}) = \frac{1}{l} \sum_{j=1}^{l} u_j \rho(v_j)\text{,}\]where \(\rho(\cdot)\) is the rank of the element in the vector.
error_probability\(\downarrow\)¶
euclidean\(\downarrow\)¶
fidelity\(\uparrow\)¶
hamming\(\downarrow\)¶
intersection\(\uparrow\)¶
jaccard\(\uparrow\)¶
js_divergence\(\downarrow\)¶
- pyldl.metrics.js_divergence(D, D_pred)[source]¶
- pyldl.metrics.js_divergence(X: ndarray, Y: ndarray | None = None, **kwargs)
Jensen-Shannon divergence. It is defined as:
\[\text{JSD}(\boldsymbol{u}, \, \boldsymbol{v}) = \frac{1}{2}\text{KLD}\left(\boldsymbol{u} \bigg\Vert \frac{1}{2}(\boldsymbol{u} + \boldsymbol{v}) \right) + \frac{1}{2}\text{KLD}\left(\boldsymbol{v} \bigg\Vert \frac{1}{2}(\boldsymbol{u} + \boldsymbol{v}) \right)\text{.}\]
jsd_dirichlet_expectation¶
jsd_dirichlet_variance¶
kendall\(\uparrow\)¶
- pyldl.metrics.kendall(D, D_pred, transpose=False)[source]¶
- pyldl.metrics.kendall(X: ndarray, Y: ndarray | None = None, **kwargs)
Kendall’s rank correlation coefficient. It is defined as:
\[\text{Ken.}(\boldsymbol{u}, \, \boldsymbol{v}) = \frac{2 \sum_{j < k} \text{sgn}(u_j - u_k) \text{sgn}(v_j - v_k) }{l (l-1)}\text{.}\]
kendallT\(\uparrow\)¶
match_m\(\uparrow\)¶
max_roc_auc\(\uparrow\)¶
mean_absolute_error\(\downarrow\)¶
mean_squared_error\(\downarrow\)¶
mu\(\uparrow\)¶
- pyldl.metrics.mu(D, D_pred)[source]¶
- pyldl.metrics.mu(X: ndarray, Y: ndarray | None = None, **kwargs)
The \(\mu\) metric is proposed in paper [LDL-LWLJ25]. Its KL-divergence-based form is defined as:
\[\mu(\boldsymbol{U}, \, \boldsymbol{V}) = \frac{1}{\delta_0} \int_0^{\delta_0} \frac{1}{n} \sum_{i=1}^{n} \mathbb{I} (\text{KLD}(\boldsymbol{u}_i, \, \boldsymbol{v}_i) \le \delta) \mathrm{d}\delta\text{,}\]where \(\delta_0 = \mathbb{E}_n[\text{KLD}(\boldsymbol{u}_i, \, \boldsymbol{c})]\) and \(\boldsymbol{c}\) is a uniform vector.
nu1\(\uparrow\)¶
nu2\(\uparrow\)¶
nu3\(\uparrow\)¶
ood_error\(\downarrow\)¶
precision\(\uparrow\)¶
score¶
sensitivity\(\uparrow\)¶
sorensen\(\downarrow\)¶
- pyldl.metrics.sorensen(D, D_pred)[source]¶
- pyldl.metrics.sorensen(X: ndarray, Y: ndarray | None = None, **kwargs)
- Sørensen's distance. It is defined as:\[\text{S}\phi\text{ren.}(\boldsymbol{u}, \, \boldsymbol{v}) = \frac{\sum^l_{j=1}\left\vert u_j - v_j \right\vert}{\sum^l_{j=1}\left( u_j + v_j \right)}\text{.}\]
spearman\(\uparrow\)¶
- pyldl.metrics.spearman(D, D_pred, transpose=False)[source]¶
- pyldl.metrics.spearman(X: ndarray, Y: ndarray | None = None, **kwargs)
Spearman’s rank correlation coefficient. It is defined as:
\[\text{Spear.}(\boldsymbol{u}, \, \boldsymbol{v}) = 1 - \frac{6 \sum_{j=1}^{l} (\rho(u_j) - \rho(v_j))^2 }{l(l^2 - 1)}\text{,}\]where \(\rho(\cdot)\) is the rank of the element in the vector.
spearmanT\(\uparrow\)¶
specificity\(\uparrow\)¶
subset_accuracy\(\uparrow\)¶
top_k\(\uparrow\)¶
wave_hedges\(\downarrow\)¶
worst_kl_divergence¶
youden_index\(\uparrow\)¶
zero_one_loss\(\downarrow\)¶
- pyldl.metrics.zero_one_loss(D, D_pred)[source]¶
- pyldl.metrics.zero_one_loss(X: ndarray, Y: ndarray | None = None, **kwargs)
0/1 loss. It is defined as:
\[\text{0/1 loss}(\boldsymbol{u}, \, \boldsymbol{v}) = \delta(\arg\max(\boldsymbol{u}), \, \arg\max(\boldsymbol{v}))\text{,}\]where \(\delta(\cdot, \, \cdot)\) is the Kronecker delta function.
References¶
Laurent Condat. Fast projection onto the simplex and the l1 ball. Mathematical Programming, 158(1):575–585, 2016. URL: https://doi.org/10.1007/s10107-015-0946-6.
Jinhui Chen and Jian Yang. Robust subspace segmentation via low-rank representation. IEEE Transactions on Cybernetics, 44(8):1432–1445, 2014. URL: https://doi.org/10.1109/TCYB.2013.2286106.
Jian-Feng Cai, Emmanuel J Candès, and Zuowei Shen. A singular value thresholding algorithm for matrix completion. SIAM Journal on Optimization, 20(4):1956–1982, 2010. URL: https://doi.org/10.1137/080738970.