Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions include/flucoma/algorithms/public/UMAP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned int>(seed < 0 ? rd() : seed));
SparseMatrixXd knnGraph(in.size(), mEmbedding.rows());
ArrayXXd dists = ArrayXXd::Zero(in.size(), mK);
makeGraph(in, mK, knnGraph, dists, false);
Expand All @@ -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<unsigned int>(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;
}
Expand Down
4 changes: 2 additions & 2 deletions include/flucoma/clients/nrt/UMAPClient.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class UMAPClient : public FluidBaseClient,
}

MessageResult<void> transform(InputDataSetClientRef sourceClient,
DataSetClientRef destClient)
DataSetClientRef destClient, bool updateEmbedding)
{
auto srcPtr = sourceClient.get().lock();
auto destPtr = destClient.get().lock();
Expand All @@ -130,7 +130,7 @@ class UMAPClient : public FluidBaseClient,
StringVector ids{src.getIds()};
FluidDataSet<string, double, 1> result;
result = mAlgorithm.transform(src, get<kNumIter>(), get<kLearningRate>(),
get<kRandomSeed>());
updateEmbedding, get<kRandomSeed>());
destPtr->setDataSet(result);
return OK();
}
Expand Down
Loading