40 auto &heap = data.
heap;
42 if (pji.size() != n * n)
48 for (
size_t i = 0; i < n; ++i) {
50 for (
size_t j = i + 1; j < n; ++j) {
52 for (
size_t di = 0; di < d; ++di)
60 auto hat = [&pji, &heap, n](
size_t i,
size_t row) ->
float {
61 return pji[row * n + heap[i]];
63 auto hsw = [&heap](
size_t i,
size_t j) { std::swap(heap[i], heap[j]); };
64 auto hdown = [&hat, &hsw](
size_t i,
size_t n,
size_t row) {
71 if (hat(i, row) > hat(l, row))
75 if (hat(l, row) < hat(r, row)) {
84 auto heapify = [&hdown](
size_t n,
size_t row) {
89 auto hpop = [&hdown, &heap](
size_t &n,
size_t row) ->
size_t {
98 for (
size_t i = 0; i < n; ++i) {
99 for (
size_t j = 0; j < n - 1; ++j)
100 heap[j] = j < i ? j : j + 1;
105 for (
size_t k = 1; hs; ++k)
106 wsum += pji[i * n + hpop(hs, i)] = 1 / float(k);
110 for (
size_t j = 0; j < n; ++j)
111 pji[i * n + j] *= wsum;
115 for (
size_t i = 0; i < n; ++i)
116 for (
size_t j = i + 1; j < n; ++j)
117 pji[i * n + j] = pji[j * n + i] =
118 (pji[i * n + j] + pji[j * n + i]) / (2 * n);
121 for (
size_t i = 0; i < n; ++i)
122 for (
size_t j = i + 1; j < n; ++j)
135 float update_weight = 0;
138 for (
size_t i = 0; i < n; ++i)
139 for (
size_t j = i + 1; j < n; ++j) {
144 auto a = vji * pji[i * n + j] * wij;
147 update_weight += glm::length(a);
148 a = vji * Z * wij * wij;
151 update_weight += glm::length(a);
154 update_weight = 100 / update_weight;
157 for (
size_t i = 0; i < n; ++i)
158 if (!vert_pressed || vert_ind != i)
void touch()
Make the cache dirty.
Model of the high- and low-dimensional landmarks.
size_t n_landmarks() const
Reurns number of the 2D landmarks.
std::vector< glm::vec2 > lodim_vertices
Array storing two-dimensional landmark coordinates.
std::vector< float > hidim_vertices
One-dimensional array storing d-dimensional landmark coordinates in row-major order.
A context structure for tSNE computation.
std::vector< glm::vec2 > updates
std::vector< size_t > heap
void tsne_layout_step(TSNELayoutData &data, bool vert_pressed, int vert_ind, LandmarkModel &lm, float time)
Optimize the positions of low-dimensional landmarks using the t-SNE algorithm.
constexpr float sqrf(float x)