Skip to content

Commit d419d27

Browse files
committed
added t-sne docs & tests
1 parent 4acf32a commit d419d27

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ makedocs(
1414
"Laplacian Eigenmaps" => "lem.md",
1515
"Local Tangent Space Alignment" => "ltsa.md",
1616
"Diffusion maps" => "diffmap.md",
17+
"t-SNE" => "tsne.md",
1718
],
1819
"Misc" => [
1920
"Interface" => "interface.md",

docs/src/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ Following dimensionality reduction methods are implemented in this package:
4343
|[`LEM`](@ref)| Laplacian Eigenmaps |
4444
|[`LTSA`](@ref)| Local Tangent Space Alignment |
4545
|[`DiffMap`](@ref)| Diffusion maps |
46+
|[`TSNE`](@ref)| t-Distributed Stochastic Neighborhood Embedding |
4647

4748
**Notes:** All methods implemented in this package adopt the column-major convention of JuliaStats: in a data matrix, each column corresponds to a sample/observation, while each row corresponds to a feature (variable or attribute).

docs/src/tsne.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# t-Distributed Stochastic Neighborhood Embedding
2+
3+
The [`t`-Distributed Stochastic Neighborhood Embedding (t-SNE)](https://en.wikipedia.org/wiki/T-distributed_stochastic_neighbor_embedding) is a statistical dimensionality reduction
4+
methods, based on the original SNE[^1] method with t-distributed variant[^2].
5+
The method constructs a probability distribution over pairwise distances in
6+
the data original space, and then optimizes a similar probability distribution of
7+
the pairwise distances of low-dimensional embedding of the data by minimizing
8+
the [Kullback-Leibler divergence](https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence) between two distributions.
9+
10+
This package defines a [`TSNE`](@ref) type to represent a t-SNE model, and provides
11+
a set of methods to access its properties.
12+
13+
```@docs
14+
TSNE
15+
fit(::Type{TSNE}, X::AbstractArray{T,2}) where {T<:Real}
16+
predict(R::TSNE)
17+
```
18+
19+
# References
20+
[^1]: Hinton, G. E., & Roweis, S. (2002). Stochastic neighbor embedding. Advances in neural information processing systems, 15.
21+
[^2]: Van der Maaten, L., & Hinton, G. (2008). Visualizing data using t-SNE. Journal of machine learning research, 9(11).
22+

test/runtests.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,17 @@ end
8787
X, L = ManifoldLearning.swiss_roll(n; rng=rng)
8888

8989
# test algorithms
90-
@testset for algorithm in [Isomap, LEM, LLE, HLLE, LTSA, DiffMap]
90+
@testset for algorithm in [Isomap, LEM, LLE, HLLE, LTSA, DiffMap, TSNE]
91+
#print("$algorithm ")
9192
for (k, T) in zip([5, 12], [Float32, Float64])
9293
X = convert(Matrix{T}, X)
9394

9495
# construct KW parameters
9596
kwargs = [:maxoutdim=>d]
96-
if algorithm == DiffMap
97+
if algorithm === DiffMap
9798
push!(kwargs, :t => k)
99+
elseif algorithm === TSNE
100+
push!(kwargs, :p => k)
98101
else
99102
push!(kwargs, :k => k)
100103
end
@@ -114,13 +117,15 @@ end
114117
@test eltype(Y) === T
115118
@test size(M) == (3, d)
116119
@test length(split(sprint(show, M), '\n')) > 1
117-
@test length(eigvals(M)) == d
118120

119121
# additional options
120-
if algorithm !== DiffMap
122+
if algorithm !== DiffMap && algorithm !== TSNE
121123
@test neighbors(M) == k
122124
@test length(vertices(M)) > 1
123125
end
126+
if algorithm !== TSNE
127+
@test length(eigvals(M)) == d
128+
end
124129
if algorithm === LEM
125130
@testset for L in [:sym, :rw]
126131
Y = fit(algorithm, X; laplacian=L, kwargs...) |> predict

0 commit comments

Comments
 (0)