1#ifndef SINGLEPP_TRAIN_SINGLE_HPP
2#define SINGLEPP_TRAIN_SINGLE_HPP
7#include "tatami/tatami.hpp"
9#include "build_indices.hpp"
10#include "subset_to_markers.hpp"
30template<
typename Index_ = DefaultIndex,
typename Float_ = DefaultFloat,
class Matrix_ = knncolle::Matrix<Index_, Float_> >
46 std::shared_ptr<knncolle::Builder<Index_, Float_, Float_, Matrix_> >
trainer;
60template<
typename Value_,
typename Index_,
typename Label_,
typename Float_,
class Matrix_>
61std::vector<PerLabelReference<Index_, Float_> > build_references(
62 const tatami::Matrix<Value_, Index_>& ref,
64 const std::vector<Index_>& subset,
71 return build_indices(ref, labels, subset, *builder, options.
num_threads);
88template<
typename Index_,
typename Float_>
97 std::vector<Index_> subset,
98 std::vector<internal::PerLabelReference<Index_, Float_> > references) :
99 my_test_nrow(test_nrow),
100 my_markers(std::move(markers)),
101 my_subset(std::move(subset)),
102 my_references(std::move(references))
111 std::vector<Index_> my_subset;
112 std::vector<internal::PerLabelReference<Index_, Float_> > my_references;
144 return my_references.size();
152 for (
const auto& ref : my_references) {
153 n += ref.ranked.size();
161 const auto& get_references()
const {
162 return my_references;
194template<
typename Value_,
typename Index_,
typename Label_,
typename Float_,
class Matrix_>
196 const tatami::Matrix<Value_, Index_>& ref,
197 const Label_* labels,
201 auto subset = internal::subset_to_markers(markers, options.
top);
202 auto subref = internal::build_references(ref, labels, subset, options);
203 Index_ test_nrow = ref.nrow();
217template<
typename Index_,
typename Float_>
226 std::vector<Index_> test_subset,
227 std::vector<Index_> ref_subset,
228 std::vector<internal::PerLabelReference<Index_, Float_> > references) :
229 my_test_nrow(test_nrow),
230 my_markers(std::move(markers)),
231 my_test_subset(std::move(test_subset)),
232 my_ref_subset(std::move(ref_subset)),
233 my_references(std::move(references))
242 std::vector<Index_> my_test_subset;
243 std::vector<Index_> my_ref_subset;
244 std::vector<internal::PerLabelReference<Index_, Float_> > my_references;
270 return my_test_subset;
279 return my_ref_subset;
286 return my_references.size();
294 for (
const auto& ref : my_references) {
295 n += ref.ranked.size();
303 const auto& get_references()
const {
304 return my_references;
339template<
typename Index_,
typename Value_,
typename Label_,
typename Float_>
343 const tatami::Matrix<Value_, Index_>& ref,
344 const Label_* labels,
348 auto pairs = internal::subset_to_markers(intersection, markers, options.
top);
349 auto subref = internal::build_references(ref, labels, pairs.second, options);
357template<
typename Index_,
typename Value_,
typename Label_,
typename Float_,
class Matrix_>
360 const tatami::Matrix<Value_, Index_>& ref,
361 const Label_* labels,
363 const TrainSingleOptions<Index_, Float_, Matrix_>& options)
401template<
typename Index_,
typename Id_,
typename Value_,
typename Label_,
typename Float_,
class Matrix_>
405 const tatami::Matrix<Value_, Index_>& ref,
407 const Label_* labels,
411 auto intersection =
intersect_genes(test_nrow, test_id, ref.nrow(), ref_id);
Classifier built from an intersection of genes.
Definition train_single.hpp:218
std::size_t num_profiles() const
Definition train_single.hpp:292
Index_ get_test_nrow() const
Definition train_single.hpp:250
const Markers< Index_ > & get_markers() const
Definition train_single.hpp:260
const std::vector< Index_ > & get_test_subset() const
Definition train_single.hpp:269
std::size_t num_labels() const
Definition train_single.hpp:285
const std::vector< Index_ > & get_ref_subset() const
Definition train_single.hpp:278
Classifier trained from a single reference.
Definition train_single.hpp:89
const std::vector< Index_ > & get_subset() const
Definition train_single.hpp:136
Index_ get_test_nrow() const
Definition train_single.hpp:118
std::size_t num_labels() const
Definition train_single.hpp:143
std::size_t num_profiles() const
Definition train_single.hpp:150
const Markers< Index_ > & get_markers() const
Definition train_single.hpp:128
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
TrainedSingleIntersect< Index_, Float_ > train_single_intersect(Index_ test_nrow, const Intersection< Index_ > &intersection, const tatami::Matrix< Value_, Index_ > &ref, const Label_ *labels, Markers< Index_ > markers, const TrainSingleOptions< Index_, Float_ > &options)
Definition train_single.hpp:340
TrainedSingle< Index_, Float_ > train_single(const tatami::Matrix< Value_, Index_ > &ref, const Label_ *labels, Markers< Index_ > markers, const TrainSingleOptions< Index_, Float_, Matrix_ > &options)
Definition train_single.hpp:195
std::vector< std::pair< Index_, Index_ > > Intersection
Definition Intersection.hpp:35
Options for train_single() and friends.
Definition train_single.hpp:31
std::shared_ptr< knncolle::Builder< Index_, Float_, Float_, Matrix_ > > trainer
Definition train_single.hpp:46
int num_threads
Definition train_single.hpp:52
int top
Definition train_single.hpp:39