MLPACK  1.0.11
data_dependent_random_initializer.hpp
Go to the documentation of this file.
1 
22 #ifndef __MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
23 #define __MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
24 
25 #include <mlpack/core.hpp>
26 
27 namespace mlpack {
28 namespace sparse_coding {
29 
36 {
37  public:
47  static void Initialize(const arma::mat& data,
48  const size_t atoms,
49  arma::mat& dictionary)
50  {
51  // Set the size of the dictionary.
52  dictionary.set_size(data.n_rows, atoms);
53 
54  // Create each atom.
55  for (size_t i = 0; i < atoms; ++i)
56  {
57  // Add three atoms together.
58  dictionary.col(i) = (data.col(math::RandInt(data.n_cols)) +
59  data.col(math::RandInt(data.n_cols)) +
60  data.col(math::RandInt(data.n_cols)));
61 
62  // Now normalize the atom.
63  dictionary.col(i) /= norm(dictionary.col(i), 2);
64  }
65  }
66 };
67 
68 }; // namespace sparse_coding
69 }; // namespace mlpack
70 
71 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
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.
int RandInt(const int hiExclusive)
Generates a uniform random integer.
Definition: random.hpp:106