57 Float_ med = tatami_stats::medians::direct(distances, num_cells,
false);
59 for (Index_ i = 0; i < num_cells; ++i) {
60 auto d = distances[i];
63 rmsd = std::sqrt(rmsd);
64 return std::make_pair(med, rmsd);
82 std::vector<double> dist(nobs);
85 auto searcher = prebuilt.initialize();
86 std::vector<Float_> distances;
87 for (size_t i = start, end = start + length; i < end; ++i) {
88 searcher->search(i, options.num_neighbors, NULL, &distances);
89 if (distances.size()) {
90 dist[i] = distances.back();
145Float_
compute_scale(
const std::pair<Float_, Float_>& ref,
const std::pair<Float_, Float_>& target) {
146 if (target.first == 0 || ref.first == 0) {
147 if (target.second == 0) {
148 return std::numeric_limits<Float_>::infinity();
149 }
else if (ref.second == 0) {
152 return ref.second / target.second;
155 return ref.first / target.first;
173std::vector<Float_>
compute_scale(
const std::vector<std::pair<Float_, Float_> >& distances) {
174 std::vector<Float_> output(distances.size());
177 bool found_ref =
false;
179 for (
size_t e = 0; e < distances.size(); ++e) {
180 if (distances[e].second) {
189 const auto& dref = distances[ref];
190 for (
size_t e = 0; e < distances.size(); ++e) {
191 output[e] = (e == ref ? 1 :
compute_scale(dref, distances[e]));
221void combine_scaled_embeddings(
const std::vector<Dim_>& num_dims, Index_ num_cells,
const std::vector<Input_*>& embeddings,
const std::vector<Scale_>& scaling, Output_* output) {
222 size_t nembed = num_dims.size();
223 if (embeddings.size() != nembed || scaling.size() != nembed) {
224 throw std::runtime_error(
"'num_dims', 'embeddings' and 'scale' should have the same length");
227 size_t ntotal = std::accumulate(num_dims.begin(), num_dims.end(),
static_cast<size_t>(0));
230 for (
size_t e = 0; e < nembed; ++e) {
231 Dim_ curdim = num_dims[e];
232 auto inptr = embeddings[e];
236 size_t in_position = 0;
237 size_t out_position = offset;
242 for (Index_ c = 0; c < num_cells; ++c, in_position += curdim, out_position += ntotal) {
243 std::fill_n(output + out_position, curdim, 0);
246 for (Index_ c = 0; c < num_cells; ++c, in_position += curdim, out_position += ntotal) {
247 for (Dim_ d = 0; d < curdim; ++d) {
248 output[out_position + d] = inptr[in_position + d] * s;
void combine_scaled_embeddings(const std::vector< Dim_ > &num_dims, Index_ num_cells, const std::vector< Input_ * > &embeddings, const std::vector< Scale_ > &scaling, Output_ *output)
Definition mumosa.hpp:221
Float_ compute_scale(const std::pair< Float_, Float_ > &ref, const std::pair< Float_, Float_ > &target)
Definition mumosa.hpp:145