mlpack 3.4.2
random_initializer.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
14#define MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
15
16#include <mlpack/prereqs.hpp>
17
18namespace mlpack {
19namespace sparse_coding {
20
26{
27 public:
37 static void Initialize(const arma::mat& data,
38 const size_t atoms,
39 arma::mat& dictionary)
40 {
41 // Create random dictionary.
42 dictionary.randn(data.n_rows, atoms);
43
44 // Normalize each atom.
45 for (size_t j = 0; j < atoms; ++j)
46 dictionary.col(j) /= norm(dictionary.col(j), 2);
47 }
48};
49
50} // namespace sparse_coding
51} // namespace mlpack
52
53#endif
A DictionaryInitializer for use with the SparseCoding class.
static void Initialize(const arma::mat &data, const size_t atoms, arma::mat &dictionary)
Initialize the dictionary randomly from a normal distribution, such that each atom has a norm of 1.
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.