solde_tr | R Documentation |
This is an extension of the SOLDE-TR algorithm described in: \insertRefyang2017stable
The method extends the Stable Orthogonal Local Discriminant Embedding (SOLDE) approach by recasting its objective function into a trace ratio optimization problem and using an iterative trace-ratio (ITR) algorithm to jointly learn the orthogonal projection vectors. Compared to the step-by-step SOLDE, SOLDE-TR converges faster, yields a global solution, and usually provides improved performance in tasks such as face recognition.
What is new in this version?
We accelerate the adjacency graph construction (Steps 1–2 in Section 3 of the paper)
by using the Rnanoflann
package, which provides a nanoflann
-backed kd-tree
for extremely fast nearest neighbor (k-NN) queries. This can be a substantial improvement
over naive O(N^2)
neighbor searches when N
is large.
Correspondence to the Paper Sections:
Equations (1), (2), (3): Construction of adjacency (weight) matrices
S
, H
, F
for similarity, diversity, and inter-class separability.
Equations (4)–(6): Objective functions in local discriminant embedding.
Equation (7): Combination into L_d = \alpha L_s - (1-\alpha)L_v
.
Equations (11)–(16): The trace ratio formulation and iterative algorithm.
solde_tr(
X,
y,
s = 5,
alpha = 0.9,
sigma = 1,
m = 10,
tol = 1e-06,
maxit = 100,
pca_preprocess = TRUE
)
X |
A numeric matrix of size |
y |
A numeric vector of length |
s |
Number of neighbors for adjacency; default = 5. |
alpha |
Numeric in |
sigma |
Positive scalar for the heat kernel \(\exp(-\|x_i - x_j\|^2 / \sigma)\); default = 1.0. |
m |
Desired dimension of the subspace; default = 10. |
tol |
Stopping threshold for change in trace ratio; default = 1e-6. |
maxit |
Maximum number of ITR iterations; default = 100. |
pca_preprocess |
Logical: whether to do PCA to ensure full rank; default = TRUE. |
Main steps:
(Optional) PCA Projection:
We project X
into a PCA subspace to ensure S_d
is nonsingular.
Build Adjacency Graphs with Rnanoflann
:
- S
(similarity)
If two points x_i
and x_j
belong to the same class and either
x_j
is among the s
nearest neighbors of x_i
or
x_i
is among the s
neighbors of x_j
, then
S_{ij} = \exp(-\|x_i - x_j\|^2/\sigma)
.
- H
(diversity)
Same condition (same-class neighbors), but H_{ij} = 1 - \exp(-\|x_i - x_j\|^2/\sigma)
.
- F
(interclass)
If x_i
and x_j
are from different classes and they are in each
other's s
neighborhoods (union condition),
then F_{ij} = \exp(-\|x_i - x_j\|^2/\sigma)
.
We implement this neighbor search using \code{nanoflann}'s kd-tree via \code{nn()} from the \pkg{Rnanoflann} package for Euclidean distance.
Iterative Trace Ratio (ITR): Solve
\max_{W^T W = I} \frac{\mathrm{tr}(W^T S_p W)}{\mathrm{tr}(W^T S_d W)},
with S_p = X L_m X^T
and S_d = X L_d X^T
, via the iterative approach:
\mathbf{M} = \mathbf{S_p} - \lambda \mathbf{S_d}
, eigen-decompose \(\mathbfM\),
pick the top m
eigenvectors. Update \(\lambda\), repeat until convergence.
Final Embedding:
\mathbf{W} = \mathbf{W}_{\mathrm{PCA}} \times \mathbf{W}_{\mathrm{SOLDE-TR}}
.
A list with:
W_pca |
The PCA projection matrix (columns are the top PCA components). |
W_solde_tr |
The |
W |
The final |
eigvals_pca |
Eigenvalues of the PCA step (if |
trace_ratio_history |
Vector of trace ratio values across ITR iterations. |
Yang, X., Liu, G., Yu, Q., & Wang, R. (2017). Stable and orthogonal local discriminant embedding using trace ratio criterion for dimensionality reduction. Pattern Recognition, 71, 249–264.
Wang, J., Zhu, X., & Gong, S. (2007). ITR: Iterative trace ratio algorithm for feature extraction. IEEE Transactions on Knowledge and Data Engineering.
He, X., Yan, S., Hu, Y., Niyogi, P., & Zhang, H. (2005). Face recognition using Laplacianfaces. IEEE Trans. on Pattern Analysis and Machine Intelligence.
## Not run:
# Simple test on a small dataset
library(Rnanoflann)
set.seed(1)
N <- 100
D <- 20
X <- matrix(rnorm(N*D), nrow = N, ncol = D)
y <- sample.int(3, size = N, replace = TRUE)
solde_res <- SOLDE_TR_fastNN(X, y, s=5, alpha=0.9, sigma=1.0, m=8, tol=1e-5, maxit=50)
# Project new data X_new:
# Ynew <- t(solde_res$W) %*% t(X_new)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.