Utils & Metrics¶
_1d¶
_clip¶
_reduction¶
binaryzation¶
- pyldl.algorithms.utils.binaryzation(D: ndarray, method='threshold', param: any = 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
kl_divergence¶
pairwise_cosine¶
- pyldl.algorithms.utils.pairwise_cosine(X: ndarray | Tensor, Y: ndarray | Tensor | None = None, mode: str = 'similarity') ndarray | Tensor [source]¶
Pairwise cosine distance/similarity.
- Parameters:
X (tf.Tensor) – Matrix \(\boldsymbol{X}\) (shape: \([m_{\boldsymbol{X}},\, n]\)).
Y (tf.Tensor) – Matrix \(\boldsymbol{Y}\) (shape: \([m_{\boldsymbol{Y}},\, n]\)).
mode (str) – Defaults to ‘similarity’. The options are ‘similarity’ and ‘distance’.
- Returns:
Pairwise cosine similarity (shape: \([m_{\boldsymbol{X}},\, m_{\boldsymbol{Y}}]\)).
- Return type:
tf.Tensor
pairwise_euclidean¶
- pyldl.algorithms.utils.pairwise_euclidean(X: ndarray | Tensor, Y: ndarray | Tensor | None = None) ndarray | Tensor [source]¶
Pairwise Euclidean distance.
- Parameters:
X (Union[np.ndarray, tf.Tensor]) – Matrix \(\boldsymbol{X}\) (shape: \([m_{\boldsymbol{X}},\, n]\)).
Y (Union[np.ndarray, tf.Tensor], optional) – Matrix \(\boldsymbol{Y}\) (shape: \([m_{\boldsymbol{Y}},\, n]\)), if None, \(\boldsymbol{Y} = \boldsymbol{X}\), defaults to None.
- Returns:
Pairwise Euclidean distance (shape: \([m_{\boldsymbol{X}},\, m_Y]\)).
- Return type:
Union[np.ndarray, tf.Tensor]
pairwise_pearsonr¶
proj¶
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
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
artificial¶
download_dataset¶
emphasize¶
load_dataset¶
make_ldl¶
plot_artificial¶
random_missing¶
accuracy¶
canberra¶
chebyshev¶
chi2¶
clark¶
cosine¶
dpa¶
- pyldl.metrics.dpa(D, D_pred)[source]¶
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 + \rho(v_j)\text{,}\]where \(\rho(\cdot)\) is the rank of the element in the vector.
error_probability¶
euclidean¶
fidelity¶
intersection¶
kendall¶
match_m¶
max_roc_auc¶
mean_absolute_error¶
mean_squared_error¶
mu¶
precision¶
score¶
sensitivity¶
sorensen¶
spearman¶
specificity¶
top_k¶
wave_hedges¶
youden_index¶
zero_one_loss¶
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.