12 #ifndef MLPACK_CORE_DATA_IMPUTE_STRATEGIES_MEDIAN_IMPUTATION_HPP 13 #define MLPACK_CORE_DATA_IMPUTE_STRATEGIES_MEDIAN_IMPUTATION_HPP 40 const size_t dimension,
41 const bool columnMajor =
true)
43 using PairType = std::pair<size_t, size_t>;
45 std::vector<PairType> targets;
47 std::vector<double> elemsToKeep;
51 for (
size_t i = 0; i < input.n_cols; ++i)
53 if (input(dimension, i) == mappedValue ||
54 std::isnan(input(dimension, i)))
56 targets.emplace_back(dimension, i);
60 elemsToKeep.push_back(input(dimension, i));
66 for (
size_t i = 0; i < input.n_rows; ++i)
68 if (input(i, dimension) == mappedValue ||
69 std::isnan(input(i, dimension)))
71 targets.emplace_back(i, dimension);
75 elemsToKeep.push_back(input(i, dimension));
81 const double median = arma::median(arma::vec(elemsToKeep));
83 for (
const PairType& target : targets)
85 input(target.first, target.second) = median;
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.