mlpack
3.1.1
src
mlpack
methods
ann
init_rules
lecun_normal_init.hpp
Go to the documentation of this file.
1
15
#ifndef MLPACK_METHODS_ANN_INIT_RULES_LECUN_NORMAL_INIT_HPP
16
#define MLPACK_METHODS_ANN_INIT_RULES_LECUN_NORMAL_INIT_HPP
17
18
#include <
mlpack/prereqs.hpp
>
19
#include <
mlpack/core/math/random.hpp
>
20
21
namespace
mlpack
{
22
namespace
ann {
23
49
class
LecunNormalInitialization
50
{
51
public
:
55
LecunNormalInitialization
()
56
{
57
// Nothing to do here.
58
}
59
68
void
Initialize
(arma::mat& W,
69
const
size_t
rows,
70
const
size_t
cols)
71
{
72
// He initialization rule says to initialize weights with random
73
// values taken from a gaussian distribution with mean = 0 and
74
// standard deviation = sqrt(1 / rows), i.e. variance = (1 / rows).
75
const
double
variance = 1.0 / ((double) rows);
76
77
if
(W.is_empty())
78
{
79
W.set_size(rows, cols);
80
}
81
82
// Multipling a random variable X with variance V(X) by some factor c,
83
// then the variance V(cX) = (c ^ 2) * V(X).
84
W.imbue( [&]() {
return
sqrt(variance) * arma::randn(); } );
85
}
86
96
void
Initialize
(arma::cube & W,
97
const
size_t
rows,
98
const
size_t
cols,
99
const
size_t
slices)
100
{
101
if
(W.is_empty())
102
W.set_size(rows, cols, slices);
103
104
for
(
size_t
i = 0; i < slices; i++)
105
Initialize
(W.slice(i), rows, cols);
106
}
107
};
// class LecunNormalInitialization
108
109
}
// namespace ann
110
}
// namespace mlpack
111
112
#endif
mlpack::ann::LecunNormalInitialization
This class is used to initialize weight matrix with the Lecun Normalization initialization rule.
Definition:
lecun_normal_init.hpp:49
prereqs.hpp
random.hpp
mlpack::ann::LecunNormalInitialization::Initialize
void Initialize(arma::cube &W, const size_t rows, const size_t cols, const size_t slices)
Initialize the elements of the specified weight 3rd order tensor with Lecun Normal initialization rul...
Definition:
lecun_normal_init.hpp:96
mlpack::ann::LecunNormalInitialization::Initialize
void Initialize(arma::mat &W, const size_t rows, const size_t cols)
Initialize the elements of the weight matrix with the Lecun Normal initialization rule.
Definition:
lecun_normal_init.hpp:68
mlpack
@serialization.hpp
Definition:
add_to_po.hpp:21
mlpack::ann::LecunNormalInitialization::LecunNormalInitialization
LecunNormalInitialization()
Initialize the LecunNormalInitialization object.
Definition:
lecun_normal_init.hpp:55
Generated by
1.8.17