mlpack 3.4.2
kathirvalavakumar_subavathi_init.hpp
Go to the documentation of this file.
1
27#ifndef MLPACK_METHODS_ANN_INIT_RULES_KATHIRVALAVAKUMAR_SUBAVATHI_INIT_HPP
28#define MLPACK_METHODS_ANN_INIT_RULES_KATHIRVALAVAKUMAR_SUBAVATHI_INIT_HPP
29
30#include <mlpack/prereqs.hpp>
31
32#include "init_rules_traits.hpp"
33#include "random_init.hpp"
34
36
37#include <iostream>
38
39namespace mlpack {
40namespace ann {
41
61{
62 public:
69 template<typename eT>
71 const double s) : s(s)
72 {
73 dataSum = arma::sum(data % data);
74 }
75
84 template<typename eT>
85 void Initialize(arma::Mat<eT>& W, const size_t rows, const size_t cols)
86 {
87 arma::Row<eT> b = s * arma::sqrt(3 / (rows * dataSum));
88 const double theta = b.min();
89 RandomInitialization randomInit(-theta, theta);
90 randomInit.Initialize(W, rows, cols);
91 }
92
99 template<typename eT>
100 void Initialize(arma::Mat<eT>& W)
101 {
102 arma::Row<eT> b = s * arma::sqrt(3 / (W.n_rows * dataSum));
103 const double theta = b.min();
104 RandomInitialization randomInit(-theta, theta);
105 randomInit.Initialize(W);
106 }
107
117 template<typename eT>
118 void Initialize(arma::Cube<eT>& W,
119 const size_t rows,
120 const size_t cols,
121 const size_t slices)
122 {
123 if (W.is_empty())
124 W.set_size(rows, cols, slices);
125
126 for (size_t i = 0; i < slices; ++i)
127 Initialize(W.slice(i), rows, cols);
128 }
129
136 template<typename eT>
137 void Initialize(arma::Cube<eT>& W)
138 {
139 if (W.is_empty())
140 Log::Fatal << "Cannot initialize an empty cube." << std::endl;
141
142 for (size_t i = 0; i < W.n_slices; ++i)
143 Initialize(W.slice(i));
144 }
145
146 private:
148 arma::rowvec dataSum;
149
151 double s;
152}; // class KathirvalavakumarSubavathiInitialization
153
155template<>
157{
158 public:
161 static const bool UseLayer = false;
162};
163
164
165} // namespace ann
166} // namespace mlpack
167
168#endif
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
This is a template class that can provide information about various initialization methods.
static const bool UseLayer
This is true if the initialization method is used for a single layer.
This class is used to initialize the weight matrix with the method proposed by T.
void Initialize(arma::Cube< eT > &W, const size_t rows, const size_t cols, const size_t slices)
Initialize the elements of the specified weight 3rd order tensor with the Kathirvalavakumar-Subavathi...
void Initialize(arma::Mat< eT > &W, const size_t rows, const size_t cols)
Initialize the elements of the specified weight matrix with the Kathirvalavakumar-Subavathi method.
KathirvalavakumarSubavathiInitialization(const arma::Mat< eT > &data, const double s)
Initialize the random initialization rule with the given values.
void Initialize(arma::Cube< eT > &W)
Initialize the elements of the specified weight 3rd order tensor with the Kathirvalavakumar-Subavathi...
void Initialize(arma::Mat< eT > &W)
Initialize the elements of the specified weight matrix with the Kathirvalavakumar-Subavathi method.
This class is used to initialize randomly the weight matrix.
Definition: random_init.hpp:25
void Initialize(arma::Mat< eT > &W, const size_t rows, const size_t cols)
Initialize randomly the elements of the specified weight matrix.
Definition: random_init.hpp:56
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.