mlpack  2.0.1
data_dependent_random_initializer.hpp
Go to the documentation of this file.
1 
14 #ifndef __MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
15 #define __MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
16 
17 #include <mlpack/core.hpp>
18 
19 namespace mlpack {
20 namespace sparse_coding {
21 
28 {
29  public:
39  static void Initialize(const arma::mat& data,
40  const size_t atoms,
41  arma::mat& dictionary)
42  {
43  // Set the size of the dictionary.
44  dictionary.set_size(data.n_rows, atoms);
45 
46  // Create each atom.
47  for (size_t i = 0; i < atoms; ++i)
48  {
49  // Add three atoms together.
50  dictionary.col(i) = (data.col(math::RandInt(data.n_cols)) +
51  data.col(math::RandInt(data.n_cols)) +
52  data.col(math::RandInt(data.n_cols)));
53 
54  // Now normalize the atom.
55  dictionary.col(i) /= norm(dictionary.col(i), 2);
56  }
57  }
58 };
59 
60 } // namespace sparse_coding
61 } // namespace mlpack
62 
63 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
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, and then normalizing the atom.
A data-dependent random dictionary initializer for SparseCoding.
Include all of the base components required to write MLPACK methods, and the main MLPACK Doxygen docu...
int RandInt(const int hiExclusive)
Generates a uniform random integer.
Definition: random.hpp:67