37 arma::Mat<DNN_Dtype>
ee;
60 gamma. set_size(
N_right, 1); gamma.ones();
61 beta. set_size(
N_right, 1); beta.zeros();
64 run_mean.set_size(
N_right, 1); run_mean.zeros();
65 run_var. set_size(
N_right, 1); run_var.zeros();
117 Y1 = gamma%(X_1-
run_mean)/arma::sqrt((run_var+ee))+beta;
130 const arma::Mat<DNN_Dtype> batch_mean = arma::mean(x,1);
131 const arma::Mat<DNN_Dtype> batch_var = arma::var(x,1,1);
132 run_mean = run_mean*run_alpha+batch_mean*((
DNN_Dtype)1.0-run_alpha);
133 run_var = run_var*run_alpha+batch_var*((
DNN_Dtype)1.0-run_alpha);
135 x_mean = x.each_col()-batch_mean;
136 x_stdinv = 1.0/arma::sqrt((batch_var+ee));
137 x_norm = x_mean.each_col()%
x_stdinv;
140 for(arma::uword k=0; k<x_norm.n_cols; k++ )
142 Y.col(k) = x_norm.col(k)%gamma +
beta;
154 arma::Mat<DNN_Dtype> norm = y.each_col()%
gamma;
155 arma::Mat<DNN_Dtype> var = -arma::sum(norm % x_mean, 1) % arma::pow(x_stdinv, 3.0)/2;
167 arma::Cube<DNN_Dtype> G(gamma.memptr(),
N_right,1,1,
false,
true);
168 arma::Cube<DNN_Dtype> dg(
N_right,1,1);
170 arma::Mat<DNN_Dtype> db(beta);
174 db = arma::mean(dy,1);
175 dg.slice(0).col(0) = arma::sum(x_norm%dy,1);
void upd_buf_size(arma::uword nmb)
Updates the buffer sizes.
Batch normalization layer class.
opt * opt_alg
Pointer to optimizer.
std::string type
Layer type string.
arma::Mat< DNN_Dtype > Y
Output buffer mini batch [N_right,N_batch].
arma::Mat< DNN_Dtype > gamma
layer * right
Pointer to next layer.
void prop_mb(void)
Forward mini batch propagation though layer.
arma::uword N_channels_right
Output channels, number of filters.
arma::Mat< DNN_Dtype > x_norm
arma::Mat< DNN_Dtype > Dleft
Error buffer [N_left,N_batch].
arma::Mat< DNN_Dtype > Y1
Output buffer [N_right,1].
virtual arma::uword get_nrof_outputs(void)
Get total number of layer outputs.
virtual arma::Mat< DNN_Dtype > get_Y1(void)
Get output buffer.
virtual void init(void)
Initialize layer.
void set_run_mean(arma::Mat< DNN_Dtype > &r_mean)
Set the running mean matrix.
virtual arma::Mat< DNN_Dtype > * get_Dleft_ptr(void)
Get error buffer pointer - mini batch.
arma::Mat< DNN_Dtype > ee
virtual arma::uword get_nrof_channels(void)
Get output buffer channel/layer size.
void set_run_var(arma::Mat< DNN_Dtype > &r_var)
Set the running variance matrix.
virtual void disp(void)
Display info about layer.
float DNN_Dtype
Data type used in the network (float or double)
arma::uword N_rows_right
Output rows.
virtual void upd_buf_size(arma::uword nmb)
Update layer buffer sizes.
void disp(void)
Display info about layer.
void init(void)
Initialization of layer.
virtual void apply(arma::Cube< DNN_Dtype > &W, arma::Mat< DNN_Dtype > &B, const arma::Cube< DNN_Dtype > &Wgrad, const arma::Mat< DNN_Dtype > &Bgrad)=0
Apply the optimizer to the layer parameters.
virtual arma::uword get_nrof_cols(void)
Get output buffer column size.
arma::uword N_batch
Mini batch size.
bool train_par
Enable training.
void update(void)
Updates the trainable parameters.
arma::Mat< DNN_Dtype > x_stdinv
arma::Mat< DNN_Dtype > run_var
virtual arma::uword get_nrof_rows(void)
Get output buffer row size.
arma::uword N_right
Total size right.
layer * left
Pointer to previous layer.
arma::uword N_cols_right
Output cols.
void prop(void)
Forward propagation though layer.
void backprop(void)
Backpropagation of mini batch propagation though layer.
virtual arma::Mat< DNN_Dtype > * get_Y_ptr(void)
Get output buffer pointer - mini batch.
arma::Mat< DNN_Dtype > run_mean
arma::Mat< DNN_Dtype > x_mean
arma::uword get_nrof_params(void)
Get info about number of trainable parameters in layer.
arma::Mat< DNN_Dtype > beta