FCNN.cpp
// Initializes weight matrix and bias vector
// (needs not to be called in ctor, since we don't know there the output dimension)

Initializes weight matrix and bias vector
(needs not to be called in ctor, since we don't know there the output dimension)
Initializes weight matrix and bias vector ( needs not to be called in ctor since we don ' t know there the output dimension )
void NNFullyConnected::InitMatrix(unsigned n, unsigned m)
{
	_weightmatrix_rows = n;
	_weightmatrix_cols = m;
#ifdef USE_WEIGHT_NORMALIZATION
	_weightmatrix_v.resize(n*m);
	_weightupdate_v.resize(n*m);
	_weightmatrix_g.resize(n);
	_weightupdate_g.resize(n);
	_weightupdate_v = 0;
	_weightupdate_g = 0;
#else
	_weightmatrix.resize(n*m);
	_weightupdate.resize(n*m);
	_weightupdate = 0;
#endif
	_bias.resize(_weightmatrix_rows);
	_biasupdate.resize(_weightmatrix_rows);
	_biasupdate = 0;
	std::default_random_engine generator;
	std::normal_distribution<double> distribution(global_mtxmean, global_mtxdev);
#ifdef USE_WEIGHT_NORMALIZATION
	for (unsigned i = 0; i < _weightmatrix_v.size(); ++i) {
		_weightmatrix_v[i] = static_cast<sca_t>(distribution(generator));
	}
	for (unsigned i = 0; i < _weightmatrix_g.size(); ++i) {
		_weightmatrix_g[i] = static_cast<sca_t>(distribution(generator));
	}
#else
	for (unsigned i = 0; i < _weightmatrix.size(); ++i) {
		_weightmatrix[i] = static_cast<sca_t>(distribution(generator));
	}
#endif
	for (unsigned i = 0; i < _bias.size(); ++i) {
		_bias[i] = static_cast<sca_t>(distribution(generator));
	}
}
void NNFullyConnected :: InitMatrix ( unsigned n , unsigned m ) { _weightmatrix_rows = n ; _weightmatrix_cols = m ; #ifdef USE_WEIGHT_NORMALIZATION _weightmatrix_v . resize ( n * m ) ; _weightupdate_v . resize ( n * m ) ; _weightmatrix_g . resize ( n ) ; _weightupdate_g . resize ( n ) ; _weightupdate_v = 0 ; _weightupdate_g = 0 ; #else _weightmatrix . resize ( n * m ) ; _weightupdate . resize ( n * m ) ; _weightupdate = 0 ; #endif _bias . resize ( _weightmatrix_rows ) ; _biasupdate . resize ( _weightmatrix_rows ) ; _biasupdate = 0 ; std :: default_random_engine generator ; std :: normal_distribution < double > distribution ( global_mtxmean , global_mtxdev ) ; #ifdef USE_WEIGHT_NORMALIZATION for ( unsigned i = 0 ; i < _weightmatrix_v . size ( ) ; ++ i ) { _weightmatrix_v [ i ] = static_cast < sca_t > ( distribution ( generator ) ) ; } for ( unsigned i = 0 ; i < _weightmatrix_g . size ( ) ; ++ i ) { _weightmatrix_g [ i ] = static_cast < sca_t > ( distribution ( generator ) ) ; } #else for ( unsigned i = 0 ; i < _weightmatrix . size ( ) ; ++ i ) { _weightmatrix [ i ] = static_cast < sca_t > ( distribution ( generator ) ) ; } #endif for ( unsigned i = 0 ; i < _bias . size ( ) ; ++ i ) { _bias [ i ] = static_cast < sca_t > ( distribution ( generator ) ) ; } }
Initializes weight matrix and bias vector
(needs not to be called in ctor, since we don't know there the output dimension)
Initializes weight matrix and bias vector ( needs not to be called in ctor since we don ' t know there the output dimension )