13 #ifndef MLPACK_CORE_DATA_NORMALIZE_LABELS_IMPL_HPP 14 #define MLPACK_CORE_DATA_NORMALIZE_LABELS_IMPL_HPP 32 template<
typename eT,
typename RowType>
34 arma::Row<size_t>& labels,
35 arma::Col<eT>& mapping)
40 mapping.set_size(labelsIn.n_elem);
41 labels.set_size(labelsIn.n_elem);
43 std::unordered_map<eT, size_t> labelMap;
45 for (
size_t i = 0; i < labelsIn.n_elem; ++i)
48 if (labelMap.count(labelsIn[i]) > 0)
50 labels[i] = labelMap[labelsIn[i]];
55 labelMap[labelsIn[i]] = curLabel;
61 mapping.resize(curLabel);
63 for (
auto it = labelMap.begin(); it != labelMap.end(); ++it)
65 mapping[it->second] = it->first;
79 const arma::Col<eT>& mapping,
80 arma::Row<eT>& labelsOut)
83 labelsOut.set_size(labels.n_elem);
85 for (
size_t i = 0; i < labels.n_elem; ++i)
86 labelsOut[i] = mapping[labels[i]];
void NormalizeLabels(const RowType &labelsIn, arma::Row< size_t > &labels, arma::Col< eT > &mapping)
Given a set of labels of a particular datatype, convert them to unsigned labels in the range [0...
Definition: normalize_labels_impl.hpp:33
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void RevertLabels(const arma::Row< size_t > &labels, const arma::Col< eT > &mapping, arma::Row< eT > &labelsOut)
Given a set of labels that have been mapped to the range [0, n), map them back to the original labels...
Definition: normalize_labels_impl.hpp:78