mixle.utils.hvis.tsne moduleΒΆ
t-SNE embedding cores: exact full-matrix and sparse Barnes-Hut.
Holds the heavy-tailed student-t kernel and exact full-matrix gradient descent (tsne_exact) as well as the sparse Barnes-Hut optimizer (tsne_barnes_hut) with its quad/oct-tree, the numba/pure-Python repulsion kernels, and the sparse probability-matrix construction. The numba kernel is guarded by HAS_NUMBA exactly as before.
- t_kernel(tx, alpha)[source]
Heavy-tailed student-t kernel on embedding tx.
Returns (Q, num, d2): normalized probabilities Q, the gradient weights num_ij = 1 / (1 + d_ij^2 / alpha), and squared distances d2. At alpha = 1 this is the standard t-SNE kernel.
- update_embed(P, Y, iY, gains, momentum, eta, alpha, min_gain, min_value=1.0e-128)[source]
One delta-bar-delta gradient step of KL(P || Q) on the embedding Y.
- Gradient of the heavy-tailed kernel:
dC/dy_i = (2(alpha+1)/alpha) * sum_j (p_ij - q_ij) num_ij (y_i - y_j),
computed in matrix form (no per-row Python loop).
- update_alpha(P, Y, alpha, min_alpha, min_value, max_its=30, step=0.1, eps=1.0e-6, max_alpha=1.0e6)[source]
Optimize the kernel tail parameter alpha by guarded Newton steps.
d(-log q~_ij)/d(alpha) = 0.5 log(1 + d2/alpha) - (alpha+1) d2 / (2 alpha^2 (1 + d2/alpha)), and dKL/d(alpha) = sum_ij (p_ij - q_ij) d(-log q~_ij)/d(alpha) (the partition function term cancels because sum P = sum Q = 1). Steps are clipped to a +-step trust region; alpha is kept in [min_alpha, max_alpha].
- tsne_exact(P, emb_dim=2, alpha=1.0, Y=None, max_its=1000, eta=None, momentum=0.8, early_exaggeration=12.0, early_its=250, min_gain=0.01, min_value=1.0e-128, optimize_alpha=False, min_alpha=1.0e-6, max_alpha_its=3, tol=1.0e-7, check_every=50, print_iter=100, seed=None, out=None)[source]
Full-matrix t-SNE on symmetrized probabilities P with convergence stopping.
- Parameters:
P (ndarray)
emb_dim (int)
alpha (float)
Y (ndarray | None)
max_its (int)
eta (float | None)
momentum (float)
early_exaggeration (float)
early_its (int)
min_gain (float)
min_value (float)
optimize_alpha (bool)
min_alpha (float)
max_alpha_its (int)
tol (float)
check_every (int)
print_iter (int)
seed (int | None)
- Return type:
- tsne_barnes_hut(P, emb_dim=2, max_its=1000, eta=None, momentum=0.8, early_exaggeration=12.0, min_gain=0.01, tol=1.0e-7, print_iter=100, theta=0.5, leaf_size=16, repulsion_method='auto', exact_repulsion_threshold=5000, seed=None, Y=None, out=None)[source]
Embed a precomputed sparse t-SNE probability matrix with Barnes-Hut.
P must be a symmetric, non-negative affinity/probability matrix. It is normalized internally. This function is self-contained and does not call sklearn.
- Parameters:
- Return type: