1#ifndef SINGLEPP_TRAIN_SINGLE_HPP
2#define SINGLEPP_TRAIN_SINGLE_HPP
8#include "build_reference.hpp"
9#include "subset_to_markers.hpp"
38template<
typename Index_,
typename Float_>
39std::size_t get_num_labels_from_built(
const BuiltReference<Index_, Float_>& built) {
40 if (built.sparse.has_value()) {
41 return built.sparse->size();
43 return built.dense->size();
47template<
typename Index_,
typename Float_>
48std::size_t get_num_profiles_from_built(
const BuiltReference<Index_, Float_>& built) {
50 if (built.sparse.has_value()) {
51 for (
const auto& ref : *(built.sparse)) {
52 n += get_num_samples(ref);
55 for (
const auto& ref : *(built->dense)) {
56 n += get_num_samples(ref);
74template<
typename Index_,
typename Float_>
83 std::vector<Index_>
subset,
84 BuiltReference<Index_, Float_> built
88 my_subset(std::move(
subset)),
89 my_built(std::move(built))
93 const auto nlabels = my_built.dense.has_value() ? my_built.dense->size() : my_built.sparse->size();
94 assert(sanisizer::is_equal(my_markers.size(), nlabels));
95 for ([[maybe_unused]]
const auto& mm : my_markers) {
96 assert(sanisizer::is_equal(mm.size(), nlabels));
106 std::vector<Index_> my_subset;
107 BuiltReference<Index_, Float_> my_built;
132 const std::vector<Index_>&
subset()
const {
140 return get_num_labels_from_built(my_built);
147 return get_num_profiles_from_built(my_built);
153 const auto& built()
const {
188template<
typename Float_ =
double,
typename Value_,
typename Index_,
typename Label_>
191 const Label_* labels,
195 auto subset = subset_to_markers(ref.
nrow(), markers);
196 const auto num_labels = markers.size();
197 auto subref = build_reference<Float_>(ref, labels, num_labels, subset, options.
num_threads);
198 const Index_ test_nrow = ref.
nrow();
236template<
typename Float_ =
double,
typename Index_,
typename Value_,
typename Label_>
241 const Label_* labels,
243 std::vector<Index_>* ref_subset,
246 auto pairs = subset_to_markers(test_nrow, intersection, ref.
nrow(), markers);
247 const auto num_labels = markers.size();
248 auto subref = build_reference<Float_>(ref, labels, num_labels, pairs.second, options.
num_threads);
250 *ref_subset = std::move(pairs.second);
291template<
typename Float_ =
double,
typename Index_,
typename Id_,
typename Value_,
typename Label_>
297 const Label_* labels,
299 std::vector<Index_>* ref_subset,
303 return train_single(test_nrow, intersection, ref, labels, std::move(markers), ref_subset, options);
Classifier trained from a single reference.
Definition train_single.hpp:75
const std::vector< Index_ > & subset() const
Definition train_single.hpp:132
Index_ test_nrow() const
Definition train_single.hpp:113
const PairwiseMarkers< Index_ > & markers() const
Definition train_single.hpp:123
std::size_t num_labels() const
Definition train_single.hpp:139
std::size_t num_profiles() const
Definition train_single.hpp:146
virtual Index_ nrow() const=0
Common definitions for singlepp.
Cell type classification using the SingleR algorithm in C++.
Definition classify_single.hpp:20
std::vector< std::vector< std::vector< Index_ > > > PairwiseMarkers
Definition Markers.hpp:39
TrainedSingle< Index_, Float_ > train_single(const tatami::Matrix< Value_, Index_ > &ref, const Label_ *labels, PairwiseMarkers< Index_ > markers, const TrainSingleOptions &options)
Definition train_single.hpp:189
Intersection< Index_ > intersect_genes(Index_ test_nrow, const Id_ *test_id, Index_ ref_nrow, const Id_ *ref_id)
Definition Intersection.hpp:54
std::vector< std::pair< Index_, Index_ > > Intersection
Definition Intersection.hpp:35
Options for train_single() and friends.
Definition train_single.hpp:27
int num_threads
Definition train_single.hpp:32