mumosa
Multi-modal analyses of single-cell data
Loading...
Searching...
No Matches
compute_scale.hpp
Go to the documentation of this file.
1#ifndef MUMOSA_COMPUTE_SCALE_HPP
2#define MUMOSA_COMPUTE_SCALE_HPP
3
4#include <limits>
5#include <utility>
6#include <vector>
7
8#include "sanisizer/sanisizer.hpp"
9
15namespace mumosa {
16
37template<typename Distance_>
38Distance_ compute_scale(const std::pair<Distance_, Distance_>& ref, const std::pair<Distance_, Distance_>& target) {
39 if (target.first == 0 || ref.first == 0) {
40 if (target.second == 0) {
41 return std::numeric_limits<Distance_>::infinity();
42 } else if (ref.second == 0) {
43 return 0;
44 } else {
45 return ref.second / target.second;
46 }
47 } else {
48 return ref.first / target.first;
49 }
50}
51
65template<typename Distance_>
66std::vector<Distance_> compute_scale(const std::vector<std::pair<Distance_, Distance_> >& distances) {
67 const auto ndist = distances.size();
68 auto output = sanisizer::create<std::vector<Distance_> >(ndist);
69
70 // Use the first entry with a non-zero RMSD as the reference.
71 bool found_ref = false;
72 I<decltype(ndist)> ref = 0;
73 for (I<decltype(ndist)> e = 0; e < ndist; ++e) {
74 if (distances[e].second) {
75 found_ref = true;
76 ref = e;
77 break;
78 }
79 }
80
81 // If all of them have a zero RMSD, then all scalings are zero, because it doesn't matter.
82 if (found_ref) {
83 const auto& dref = distances[ref];
84 for (I<decltype(ndist)> e = 0; e < ndist; ++e) {
85 output[e] = (e == ref ? static_cast<Distance_>(1) : compute_scale(dref, distances[e]));
86 }
87 }
88
89 return output;
90}
91
92}
93
94#endif
Scale multi-modal embeddings to adjust for differences in variance.
Definition blocked.hpp:20
Distance_ compute_scale(const std::pair< Distance_, Distance_ > &ref, const std::pair< Distance_, Distance_ > &target)
Definition compute_scale.hpp:38