16 namespace tapkee_internal
19 template <
class RandomAccessIterator,
class PairwiseCallback>
21 PairwiseCallback callback,
const Neighbors& neighbors,
22 IndexType target_dimension,
bool global_strategy,
28 k = neighbors[0].size();
32 while (nupdates > N/2)
37 for (RandomAccessIterator i_iter=begin; i_iter!=end; ++i_iter)
39 for (RandomAccessIterator j_iter=i_iter+1; j_iter!=end; ++j_iter)
41 max = std::max(max, callback.distance(*i_iter,*j_iter));
48 alpha = 1.0 / max * std::sqrt(2.0);
51 DenseMatrix Y = (DenseMatrix::Random(target_dimension,N)
52 + DenseMatrix::Ones(target_dimension,N)) / 2;
58 typedef std::vector<int> Indices;
59 typedef std::vector<int>::iterator IndexIterator;
64 max_iter = 2000 +
static_cast<IndexType>(floor(0.04 * N*N));
73 for (
int i=0; i<N; ++i)
83 Indices ind1Neighbors;
85 ind1Neighbors.resize(k*nupdates);
92 ind1 = indices.begin();
93 ind2 = indices.begin()+nupdates;
100 for(
int j=0; j<nupdates; ++j)
106 ind1Neighbors[kk + j*k] = current_neighbors[kk];
109 ind1 = indices.begin();
112 for(
int j=0; j<nupdates; ++j)
115 indices[nupdates+j] = ind1Neighbors[r];
121 for(
int j=0; j<nupdates; ++j)
124 D[j] = (Y.col(*ind1) - Y.col(*ind2)).norm();
134 ind1 = indices.begin();
135 ind2 = indices.begin()+nupdates;
136 for (
int j=0; j<nupdates; ++j)
137 Rt[j] *= callback.distance(*(begin + *ind1++), *(begin + *ind2++));
142 D.array() += tolerance;
143 scale = (Rt-D).cwiseQuotient(D);
145 ind1 = indices.begin();
146 ind2 = indices.begin()+nupdates;
148 for (
int j=0; j<nupdates; ++j)
150 Yd.col(j).noalias() = Y.col(*ind1) - Y.col(*ind2);
155 ind1 = indices.begin();
156 ind2 = indices.begin()+nupdates;
158 for (
int j=0; j<nupdates; ++j)
160 Y.col(*ind1) += lambda / 2 * scale[j] * Yd.col(j);
161 Y.col(*ind2) -= lambda / 2 * scale[j] * Yd.col(j);
167 lambda = lambda - ( lambda / max_iter );
170 return Y.transpose();
void random_shuffle(RAI first, RAI last)
Eigen::Matrix< tapkee::ScalarType, Eigen::Dynamic, Eigen::Dynamic > DenseMatrix
dense matrix type (non-overridable)
ScalarType uniform_random()
double ScalarType
default scalar value (can be overrided with TAPKEE_CUSTOM_INTERNAL_NUMTYPE define) ...
Eigen::Matrix< tapkee::ScalarType, Eigen::Dynamic, 1 > DenseVector
dense vector type (non-overridable)
TAPKEE_INTERNAL_VECTOR< tapkee::IndexType > LocalNeighbors
int IndexType
indexing type (non-overridable) set to int for compatibility with OpenMP 2.0
TAPKEE_INTERNAL_VECTOR< tapkee::tapkee_internal::LocalNeighbors > Neighbors
DenseMatrix spe_embedding(RandomAccessIterator begin, RandomAccessIterator end, PairwiseCallback callback, const Neighbors &neighbors, IndexType target_dimension, bool global_strategy, ScalarType tolerance, int nupdates, IndexType max_iter)