CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
PhysicsTools::MLP Class Reference

#include <MLP.h>

Public Member Functions

void clear ()
 
const double * eval (double *data) const
 
unsigned int getEpoch () const
 
int getLayers () const
 
const int * getLayout () const
 
void init (unsigned int rows)
 
void load (const std::string file)
 
 MLP (unsigned int nIn, unsigned int nOut, const std::string layout)
 
void save (const std::string file) const
 
void set (unsigned int row, double *data, double *target, double weight=1.0)
 
double train ()
 
 ~MLP ()
 

Private Member Functions

void setLearn (void)
 
void setNPattern (unsigned int size)
 

Private Attributes

unsigned int epoch
 
bool initialized
 
int layers
 
int * layout
 

Static Private Attributes

static bool inUse = false
 

Detailed Description

Definition at line 6 of file MLP.h.

Constructor & Destructor Documentation

PhysicsTools::MLP::MLP ( unsigned int  nIn,
unsigned int  nOut,
const std::string  layout 
)

Definition at line 43 of file MLP.cc.

References edm::hlt::Exception, i, InitWeights(), inUse, layers, layout, LearnAlloc(), MLP_SetNet(), setLearn(), and PhysicsTools::split().

43  :
44  initialized(false), layers(0), layout(0), epoch(0)
45 {
46  if (inUse)
47  throw cms::Exception("MLP")
48  << "mlpfit doesn't support more than one instance."
49  << std::endl;
50 
51  std::vector<std::string> parsed = split(layout_, ':');
52  if (parsed.size() < 1)
53  throw cms::Exception("MLP")
54  << "Invalid layout." << std::endl;
55 
56  layout = new int[parsed.size() + 2];
57 
58  layers = parsed.size();
59  layout[0] = (int)nIn;
60  for(int i = 0; i < layers; i++) {
61  std::istringstream ss(parsed[i]);
62  int nodes;
63  ss >> nodes;
64  if (nodes < 1)
65  throw cms::Exception("MLP")
66  << "Invalid layout." << std::endl;
67 
68  layout[i + 1] = nodes;
69  }
70  layout[layers + 1] = (int)nOut;
71  layers += 2;
72 
73  inUse = true;
74 
75  MLP_SetNet(&layers, layout);
76  setLearn();
77  LearnAlloc();
78  InitWeights();
79 }
int i
Definition: DBlmapReader.cc:9
void InitWeights()
Definition: mlp_gen.cc:2145
int MLP_SetNet(int *nl, int *nn)
Definition: mlp_gen.cc:3635
static bool inUse
Definition: MLP.h:32
unsigned int epoch
Definition: MLP.h:31
int layers
Definition: MLP.h:28
bool initialized
Definition: MLP.h:27
int LearnAlloc()
Definition: mlp_gen.cc:2683
void setLearn(void)
Definition: MLP.cc:102
int * layout
Definition: MLP.h:29
static std::vector< std::string > split(const std::string line, char delim)
Definition: MLP.cc:18
PhysicsTools::MLP::~MLP ( )

Definition at line 81 of file MLP.cc.

References clear(), inUse, layout, and LearnFree().

82 {
83  clear();
84 
85  LearnFree();
86  inUse = false;
87  delete[] layout;
88 }
void LearnFree()
Definition: mlp_gen.cc:2638
static bool inUse
Definition: MLP.h:32
int * layout
Definition: MLP.h:29
void clear()
Definition: MLP.cc:90

Member Function Documentation

void PhysicsTools::MLP::clear ( void  )

Definition at line 90 of file MLP.cc.

References FreePatterns(), initialized, and PAT.

Referenced by ~MLP().

91 {
92  if (!initialized)
93  return;
94  initialized = false;
95 
96  FreePatterns(0);
97  free(PAT.Rin);
98  free(PAT.Rans);
99  free(PAT.Pond);
100 }
#define PAT
Definition: mlp_gen.h:45
bool initialized
Definition: MLP.h:27
int FreePatterns(int ifile)
Definition: mlp_gen.cc:3230
const double * PhysicsTools::MLP::eval ( double *  data) const

Definition at line 147 of file MLP.cc.

References layers, MLP_Out_T(), and NET.

148 {
149  MLP_Out_T(data);
150 
151  return &NET.Outn[layers - 1][0];
152 }
#define NET
Definition: mlp_gen.h:25
int layers
Definition: MLP.h:28
void MLP_Out_T(type_pat *rrin)
Definition: mlp_gen.cc:115
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int PhysicsTools::MLP::getEpoch ( ) const
inline

Definition at line 19 of file MLP.h.

References epoch.

19 { return epoch; }
unsigned int epoch
Definition: MLP.h:31
int PhysicsTools::MLP::getLayers ( ) const
inline

Definition at line 20 of file MLP.h.

References layers.

20 { return layers; }
int layers
Definition: MLP.h:28
const int* PhysicsTools::MLP::getLayout ( ) const
inline

Definition at line 21 of file MLP.h.

References layout.

21 { return layout; }
int * layout
Definition: MLP.h:29
void PhysicsTools::MLP::init ( unsigned int  rows)

Definition at line 122 of file MLP.cc.

References AllocPatterns(), initialized, layers, layout, and setNPattern().

123 {
124  setNPattern(rows);
125  AllocPatterns(0, rows, layout[0], layout[layers - 1], 0);
126  initialized = true;
127 }
void setNPattern(unsigned int size)
Definition: MLP.cc:114
int layers
Definition: MLP.h:28
bool initialized
Definition: MLP.h:27
int AllocPatterns(int ifile, int npat, int nin, int nout, int iadd)
Definition: mlp_gen.cc:3075
int * layout
Definition: MLP.h:29
void PhysicsTools::MLP::load ( const std::string  file)

Definition at line 161 of file MLP.cc.

References epoch, and LoadWeights().

162 {
163  int epoch_ = 0;
164  if (LoadWeights(const_cast<char*>(file.c_str()), &epoch_) < 0)
165  throw cms::Exception("MLP")
166  << "Error opening \"" << file << "\"." << std::endl;
167  epoch = (unsigned int)epoch_;
168 }
unsigned int epoch
Definition: MLP.h:31
int LoadWeights(char *filename, int *iepoch)
Definition: mlp_gen.cc:3020
void PhysicsTools::MLP::save ( const std::string  file) const

Definition at line 154 of file MLP.cc.

References epoch, edm::hlt::Exception, and SaveWeights().

155 {
156  if (SaveWeights(const_cast<char*>(file.c_str()), (int)epoch) < 0)
157  throw cms::Exception("MLP")
158  << "Error opening \"" << file << "\"." << std::endl;
159 }
int SaveWeights(char *filename, int iepoch)
Definition: mlp_gen.cc:2970
unsigned int epoch
Definition: MLP.h:31
void PhysicsTools::MLP::set ( unsigned int  row,
double *  data,
double *  target,
double  weight = 1.0 
)

Definition at line 129 of file MLP.cc.

References layers, layout, PAT, and CommonMethods::weight().

Referenced by betterConfigParser.BetterConfigParser::getGeneral().

130 {
131  int nIn = layout[0];
132  int nOut = layout[layers - 1];
133 
134  std::memcpy(&PAT.vRin[0][row*(nIn + 1) + 1], data, sizeof(double) * nIn);
135  std::memcpy(&PAT.Rans[0][row][0], target, sizeof(double) * nOut);
136  PAT.Pond[0][row] = weight;
137 }
#define PAT
Definition: mlp_gen.h:45
int layers
Definition: MLP.h:28
int * layout
Definition: MLP.h:29
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
void PhysicsTools::MLP::setLearn ( void  )
private

Definition at line 102 of file MLP.cc.

References LEARN.

Referenced by MLP().

103 {
104  LEARN.Meth = 7;
105  LEARN.Nreset = 50;
106  LEARN.Tau = 1.5;
107  LEARN.Decay = 1.0;
108  LEARN.eta = 0.1;
109  LEARN.Lambda = 1.0;
110  LEARN.delta = 0.0;
111  LEARN.epsilon = 0.2;
112 }
#define LEARN
Definition: mlp_gen.h:36
void PhysicsTools::MLP::setNPattern ( unsigned int  size)
private

Definition at line 114 of file MLP.cc.

References layers, layout, and PAT.

Referenced by init().

115 {
116  PAT.Npat[0] = (int)size;
117  PAT.Npat[1] = 0;
118  PAT.Nin = layout[0];
119  PAT.Nout = layout[layers - 1];
120 }
#define PAT
Definition: mlp_gen.h:45
int layers
Definition: MLP.h:28
int * layout
Definition: MLP.h:29
tuple size
Write out results.
double PhysicsTools::MLP::train ( )

Definition at line 139 of file MLP.cc.

References epoch, and MLP_Epoch().

140 {
141  double alpMin;
142  int nTest;
143 
144  return MLP_Epoch(++epoch, &alpMin, &nTest);
145 }
dbl MLP_Epoch(int iepoch, dbl *alpmin, int *Ntest)
Definition: mlp_gen.cc:709
unsigned int epoch
Definition: MLP.h:31

Member Data Documentation

unsigned int PhysicsTools::MLP::epoch
private

Definition at line 31 of file MLP.h.

Referenced by getEpoch(), load(), save(), and train().

bool PhysicsTools::MLP::initialized
private

Definition at line 27 of file MLP.h.

Referenced by clear(), and init().

bool PhysicsTools::MLP::inUse = false
staticprivate

Definition at line 32 of file MLP.h.

Referenced by MLP(), and ~MLP().

int PhysicsTools::MLP::layers
private

Definition at line 28 of file MLP.h.

Referenced by eval(), getLayers(), init(), MLP(), set(), and setNPattern().

int* PhysicsTools::MLP::layout
private