Public Member Functions | Public Attributes | List of all members
keras::LayerDense Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-01-21/ExoticsTriggers/KerasModel.h"

Inheritance diagram for keras::LayerDense:
keras::Layer keras::Layer

Public Member Functions

 LayerDense ()
 
void load_weights (std::ifstream &fin)
 
keras::DataChunkcompute_output (keras::DataChunk *)
 
virtual unsigned int get_input_rows () const
 
virtual unsigned int get_input_cols () const
 
virtual unsigned int get_output_units () const
 
 LayerDense ()
 
void load_weights (std::ifstream &fin)
 
keras::DataChunkcompute_output (keras::DataChunk *)
 
virtual unsigned int get_input_rows () const
 
virtual unsigned int get_input_cols () const
 
virtual unsigned int get_output_units () const
 
std::string get_name ()
 
std::string get_name ()
 

Public Attributes

std::vector< std::vector< float > > m_weights
 
std::vector< float > m_bias
 
int m_input_cnt
 
int m_neurons
 
std::string m_name
 

Detailed Description

Definition at line 184 of file KerasModel.h.

Constructor & Destructor Documentation

keras::LayerDense::LayerDense ( )
inline

Definition at line 186 of file KerasModel.h.

References fin.

186 : Layer("Dense") {}
Layer(std::string name)
Definition: KerasModel.h:111
keras::LayerDense::LayerDense ( )
inline

Definition at line 184 of file KerasModel.h.

References fin.

184 : Layer("Dense") {}
Layer(std::string name)
Definition: KerasModel.h:111

Member Function Documentation

keras::DataChunk* keras::LayerDense::compute_output ( keras::DataChunk )
virtual

Implements keras::Layer.

keras::DataChunk * keras::LayerDense::compute_output ( keras::DataChunk dc)
virtual

Implements keras::Layer.

Definition at line 322 of file KerasModel.cxx.

References keras::DataChunk::get_1d(), keras::DataChunkFlat::get_1d_rw(), MECModelEnuComparisons::i, calib::j, confusionMatrixTree::out, gen_hdf5record::size, and w.

Referenced by keras::missing_activation_impl().

322  {
323  size_t size = m_weights[0].size();
324  size_t size8 = size >> 3;
325  keras::DataChunkFlat *out = new DataChunkFlat(size, 0);
326  float * y_ret = out->get_1d_rw().data();
327  auto const & im = dc->get_1d();
328 
329  for (size_t j = 0; j < m_weights.size(); ++j) { // iter over input
330  const float * w = m_weights[j].data();
331  float p = im[j];
332  size_t k = 0;
333  for (size_t i = 0; i < size8; ++i) { // iter over neurons
334  y_ret[k] += w[k] * p; // vectorize if you can
335  y_ret[k+1] += w[k+1] * p;
336  y_ret[k+2] += w[k+2] * p;
337  y_ret[k+3] += w[k+3] * p;
338  y_ret[k+4] += w[k+4] * p;
339  y_ret[k+5] += w[k+5] * p;
340  y_ret[k+6] += w[k+6] * p;
341  y_ret[k+7] += w[k+7] * p;
342  k += 8;
343  }
344  while (k < size) { y_ret[k] += w[k] * p; ++k; }
345  }
346  for (size_t i = 0; i < size; ++i) { // add biases
347  y_ret[i] += m_bias[i];
348  }
349 
350  return out;
351 }
const char * p
Definition: xmltok.h:285
std::vector< std::vector< float > > m_weights
Definition: KerasModel.h:190
const double j
Definition: BetheBloch.cxx:29
std::vector< float > m_bias
Definition: KerasModel.h:191
std::vector< float > & get_1d_rw()
Definition: KerasModel.h:89
Float_t w
Definition: plot.C:20
virtual std::vector< float > const & get_1d() const
Definition: KerasModel.h:36
virtual unsigned int keras::LayerDense::get_input_cols ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 192 of file KerasModel.h.

192 { return m_input_cnt; }
virtual unsigned int keras::LayerDense::get_input_cols ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 194 of file KerasModel.h.

194 { return m_input_cnt; }
virtual unsigned int keras::LayerDense::get_input_rows ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 191 of file KerasModel.h.

191 { return 1; } // flat, just one row
virtual unsigned int keras::LayerDense::get_input_rows ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 193 of file KerasModel.h.

193 { return 1; } // flat, just one row
std::string keras::Layer::get_name ( )
inlineinherited

Definition at line 116 of file KerasModel.h.

References string.

116 { return m_name; }
std::string m_name
Definition: KerasModel.h:119
std::string keras::Layer::get_name ( )
inlineinherited

Definition at line 118 of file KerasModel.h.

118 { return m_name; }
std::string m_name
Definition: KerasModel.h:119
virtual unsigned int keras::LayerDense::get_output_units ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 193 of file KerasModel.h.

References string, and copy_new_pkl_files::verbose.

193 { return m_neurons; }
virtual unsigned int keras::LayerDense::get_output_units ( ) const
inlinevirtual

Implements keras::Layer.

Definition at line 195 of file KerasModel.h.

195 { return m_neurons; }
void keras::LayerDense::load_weights ( std::ifstream &  fin)
virtual

Implements keras::Layer.

void keras::LayerDense::load_weights ( std::ifstream &  fin)
virtual

Implements keras::Layer.

Definition at line 86 of file KerasModel.cxx.

References MECModelEnuComparisons::i, keras::KerasModel::KerasModel(), and getGoodRuns4SAM::n.

86  {
88  float tmp_float;
89  char tmp_char = ' ';
90  for(int i = 0; i < m_input_cnt; ++i) {
91  vector<float> tmp_n;
92  fin >> tmp_char; // for '['
93  for(int n = 0; n < m_neurons; ++n) {
94  fin >> tmp_float;
95  tmp_n.push_back(tmp_float);
96  }
97  fin >> tmp_char; // for ']'
98  m_weights.push_back(tmp_n);
99  }
100  fin >> tmp_char; // for '['
101  for(int n = 0; n < m_neurons; ++n) {
102  fin >> tmp_float;
103  m_bias.push_back(tmp_float);
104  }
105  fin >> tmp_char; // for ']'
106 
107 }
TString fin
Definition: Style.C:24
std::vector< std::vector< float > > m_weights
Definition: KerasModel.h:190
std::vector< float > m_bias
Definition: KerasModel.h:191

Member Data Documentation

std::vector< float > keras::LayerDense::m_bias

Definition at line 191 of file KerasModel.h.

int keras::LayerDense::m_input_cnt

Definition at line 197 of file KerasModel.h.

std::string keras::Layer::m_name
inherited

Definition at line 119 of file KerasModel.h.

int keras::LayerDense::m_neurons

Definition at line 198 of file KerasModel.h.

std::vector< std::vector< float > > keras::LayerDense::m_weights

Definition at line 190 of file KerasModel.h.


The documentation for this class was generated from the following files: