57std::pair<Distance_, Distance_>
compute_distance(Index_ num_cells, Distance_* distances) {
58 Distance_ med = tatami_stats::medians::direct(distances, num_cells,
false);
60 for (Index_ i = 0; i < num_cells; ++i) {
61 auto d = distances[i];
64 rmsd = std::sqrt(rmsd);
65 return std::make_pair(med, rmsd);
85 std::vector<double> dist(nobs);
88 auto searcher = prebuilt.initialize();
89 std::vector<Distance_> distances;
90 for (Index_ i = start, end = start + length; i < end; ++i) {
91 searcher->search(i, capped_k, NULL, &distances);
92 if (distances.size()) {
93 dist[i] = distances.back();
150Distance_
compute_scale(
const std::pair<Distance_, Distance_>& ref,
const std::pair<Distance_, Distance_>& target) {
151 if (target.first == 0 || ref.first == 0) {
152 if (target.second == 0) {
153 return std::numeric_limits<Distance_>::infinity();
154 }
else if (ref.second == 0) {
157 return ref.second / target.second;
160 return ref.first / target.first;
178std::vector<Distance_>
compute_scale(
const std::vector<std::pair<Distance_, Distance_> >& distances) {
179 std::vector<Distance_> output(distances.size());
182 bool found_ref =
false;
183 auto ndist = distances.size();
184 decltype(ndist) ref = 0;
185 for (
decltype(ndist) e = 0; e < ndist; ++e) {
186 if (distances[e].second) {
195 const auto& dref = distances[ref];
196 for (
decltype(ndist) e = 0; e < ndist; ++e) {
197 output[e] = (e == ref ? 1 :
compute_scale(dref, distances[e]));
226void combine_scaled_embeddings(
const std::vector<std::size_t>& num_dims, Index_ num_cells,
const std::vector<Input_*>& embeddings,
const std::vector<Scale_>& scaling, Output_* output) {
227 auto nembed = num_dims.size();
228 if (embeddings.size() != nembed || scaling.size() != nembed) {
229 throw std::runtime_error(
"'num_dims', 'embeddings' and 'scale' should have the same length");
232 std::size_t ntotal = std::accumulate(num_dims.begin(), num_dims.end(),
static_cast<std::size_t
>(0));
233 std::size_t offset = 0;
235 for (
decltype(nembed) e = 0; e < nembed; ++e) {
236 auto curdim = num_dims[e];
237 auto inptr = embeddings[e];
241 std::size_t in_position = 0;
242 std::size_t out_position = offset;
247 for (Index_ c = 0; c < num_cells; ++c, in_position += curdim, out_position += ntotal) {
248 std::fill_n(output + out_position, curdim, 0);
251 for (Index_ c = 0; c < num_cells; ++c, in_position += curdim, out_position += ntotal) {
252 for (std::size_t d = 0; d < curdim; ++d) {
253 output[out_position + d] = inptr[in_position + d] * s;
Distance_ compute_scale(const std::pair< Distance_, Distance_ > &ref, const std::pair< Distance_, Distance_ > &target)
Definition mumosa.hpp:150
void combine_scaled_embeddings(const std::vector< std::size_t > &num_dims, Index_ num_cells, const std::vector< Input_ * > &embeddings, const std::vector< Scale_ > &scaling, Output_ *output)
Definition mumosa.hpp:226