1#ifndef SINGLEPP_TRAIN_SINGLE_HPP
2#define SINGLEPP_TRAIN_SINGLE_HPP
6#include "tatami/tatami.hpp"
8#include "build_reference.hpp"
9#include "subset_to_markers.hpp"
48template<
typename Index_,
typename Float_>
49std::size_t get_num_labels_from_built(
const BuiltReference<Index_, Float_>& built) {
50 if (built.sparse.has_value()) {
51 return built.sparse->size();
53 return built.dense->size();
57template<
typename Index_,
typename Float_>
58std::size_t get_num_profiles_from_built(
const BuiltReference<Index_, Float_>& built) {
60 if (built.sparse.has_value()) {
61 for (
const auto& ref : *(built.sparse)) {
62 n += get_num_samples(ref);
65 for (
const auto& ref : *(built->dense)) {
66 n += get_num_samples(ref);
84template<
typename Index_,
typename Float_>
93 std::vector<Index_>
subset,
94 BuiltReference<Index_, Float_> built
98 my_subset(std::move(
subset)),
99 my_built(std::move(built))
108 std::vector<Index_> my_subset;
109 BuiltReference<Index_, Float_> my_built;
134 const std::vector<Index_>&
subset()
const {
142 return get_num_labels_from_built(my_built);
149 return get_num_profiles_from_built(my_built);
155 const auto& built()
const {
186template<
typename Float_ =
double,
typename Value_,
typename Index_,
typename Label_>
188 const tatami::Matrix<Value_, Index_>& ref,
189 const Label_* labels,
193 auto subset = internal::subset_to_markers(markers, options.
top);
194 auto subref = build_reference<Float_>(ref, labels, subset, options.
num_threads);
195 const Index_ test_nrow = ref.nrow();
229template<
typename Float_ =
double,
typename Index_,
typename Value_,
typename Label_>
233 const tatami::Matrix<Value_, Index_>& ref,
234 const Label_* labels,
236 std::vector<Index_>* ref_subset,
239 auto pairs = internal::subset_to_markers(intersection, markers, options.
top);
240 auto subref = build_reference<Float_>(ref, labels, pairs.second, options.
num_threads);
242 *ref_subset = std::move(pairs.second);
279template<
typename Float_ =
double,
typename Index_,
typename Id_,
typename Value_,
typename Label_>
283 const tatami::Matrix<Value_, Index_>& ref,
285 const Label_* labels,
287 std::vector<Index_>* ref_subset,
290 auto intersection =
intersect_genes(test_nrow, test_id, ref.nrow(), ref_id);
291 return train_single(test_nrow, intersection, ref, labels, std::move(markers), ref_subset, options);
Classifier trained from a single reference.
Definition train_single.hpp:85
const std::vector< Index_ > & subset() const
Definition train_single.hpp:134
Index_ test_nrow() const
Definition train_single.hpp:115
std::size_t num_labels() const
Definition train_single.hpp:141
std::size_t num_profiles() const
Definition train_single.hpp:148
const Markers< Index_ > & markers() const
Definition train_single.hpp:125
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_ > > > Markers
Definition Markers.hpp:40
Intersection< Index_ > intersect_genes(Index_ test_nrow, const Id_ *test_id, Index_ ref_nrow, const Id_ *ref_id)
Definition Intersection.hpp:54
TrainedSingle< Index_, Float_ > train_single(const tatami::Matrix< Value_, Index_ > &ref, const Label_ *labels, Markers< Index_ > markers, const TrainSingleOptions &options)
Definition train_single.hpp:187
std::vector< std::pair< Index_, Index_ > > Intersection
Definition Intersection.hpp:35
Options for train_single() and friends.
Definition train_single.hpp:25
int num_threads
Definition train_single.hpp:42
int top
Definition train_single.hpp:36