diff --git a/include/flucoma/algorithms/public/UMAP.hpp b/include/flucoma/algorithms/public/UMAP.hpp index 9e52c161..d6cfe2f5 100644 --- a/include/flucoma/algorithms/public/UMAP.hpp +++ b/include/flucoma/algorithms/public/UMAP.hpp @@ -209,11 +209,9 @@ class UMAP return out; } - DataSet transform(DataSet& in, index maxIter = 200, double learningRate = 1.0, index seed = -1) const + DataSet transform(DataSet& in, index maxIter = 200, double learningRate = 1.0, bool updateEmbedding = false, index seed = -1) const { if (!mInitialized) return DataSet(); - std::random_device rd; - std::mt19937_64 rng(static_cast(seed < 0 ? rd() : seed)); SparseMatrixXd knnGraph(in.size(), mEmbedding.rows()); ArrayXXd dists = ArrayXXd::Zero(in.size(), mK); makeGraph(in, mK, knnGraph, dists, false); @@ -223,14 +221,18 @@ class UMAP normalizeRows(knnGraph); ArrayXXd embedding = initTransformEmbedding(knnGraph, mEmbedding, in.size()); - ArrayXi rowIndices(knnGraph.nonZeros()); - ArrayXi colIndices(knnGraph.nonZeros()); - ArrayXd epochsPerSample(knnGraph.nonZeros()); - getGraphIndices(knnGraph, rowIndices, colIndices); - computeEpochsPerSample(knnGraph, epochsPerSample); - epochsPerSample = (epochsPerSample == 0).select(-1, epochsPerSample); - optimizeLayout(embedding, mEmbedding, rowIndices, colIndices, - epochsPerSample, learningRate, maxIter, rng); + if (updateEmbedding) { + std::random_device rd; + std::mt19937_64 rng(static_cast(seed < 0 ? rd() : seed)); + ArrayXi rowIndices(knnGraph.nonZeros()); + ArrayXi colIndices(knnGraph.nonZeros()); + ArrayXd epochsPerSample(knnGraph.nonZeros()); + getGraphIndices(knnGraph, rowIndices, colIndices); + computeEpochsPerSample(knnGraph, epochsPerSample); + epochsPerSample = (epochsPerSample == 0).select(-1, epochsPerSample); + optimizeLayout(embedding, mEmbedding, rowIndices, colIndices, + epochsPerSample, learningRate, maxIter, rng); + } DataSet out(in.getIds(), _impl::asFluid(embedding)); return out; } diff --git a/include/flucoma/clients/nrt/UMAPClient.hpp b/include/flucoma/clients/nrt/UMAPClient.hpp index e97bb600..3a66ed26 100644 --- a/include/flucoma/clients/nrt/UMAPClient.hpp +++ b/include/flucoma/clients/nrt/UMAPClient.hpp @@ -115,7 +115,7 @@ class UMAPClient : public FluidBaseClient, } MessageResult transform(InputDataSetClientRef sourceClient, - DataSetClientRef destClient) + DataSetClientRef destClient, bool updateEmbedding) { auto srcPtr = sourceClient.get().lock(); auto destPtr = destClient.get().lock(); @@ -130,7 +130,7 @@ class UMAPClient : public FluidBaseClient, StringVector ids{src.getIds()}; FluidDataSet result; result = mAlgorithm.transform(src, get(), get(), - get()); + updateEmbedding, get()); destPtr->setDataSet(result); return OK(); }