mlpack 3.4.2
data_dependent_random_initializer.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
13#define MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
14
15#include <mlpack/prereqs.hpp>
17
18namespace mlpack {
19namespace sparse_coding {
20
27{
28 public:
38 static void Initialize(const arma::mat& data,
39 const size_t atoms,
40 arma::mat& dictionary)
41 {
42 // Set the size of the dictionary.
43 dictionary.set_size(data.n_rows, atoms);
44
45 // Create each atom.
46 for (size_t i = 0; i < atoms; ++i)
47 {
48 // Add three atoms together.
49 dictionary.col(i) = (data.col(math::RandInt(data.n_cols)) +
50 data.col(math::RandInt(data.n_cols)) +
51 data.col(math::RandInt(data.n_cols)));
52
53 // Now normalize the atom.
54 dictionary.col(i) /= norm(dictionary.col(i), 2);
55 }
56 }
57};
58
59} // namespace sparse_coding
60} // namespace mlpack
61
62#endif
A data-dependent random dictionary initializer for SparseCoding.
static void Initialize(const arma::mat &data, const size_t atoms, arma::mat &dictionary)
Initialize the dictionary by adding together three random observations from the data,...
int RandInt(const int hiExclusive)
Generates a uniform random integer.
Definition: random.hpp:110
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
Miscellaneous math random-related routines.