HOG2
NN.h
Go to the documentation of this file.
1 #ifndef NN_H
2 #define NN_H
3 
4 #include "FunctionApproximator.h"
5 #include <vector>
6 
7 class NN : public FunctionApproximator {
8 public:
9  NN(int inputs, int hiddens, int outputs, double learnrate);
10  NN(NN *);
12  NN(char *);
13  ~NN();
14  void load(const char *);
15  void load(FILE *);
16  void load(const NN *);
17  void load(const FunctionApproximator *fa) { load((NN*)fa); }
18  static bool validSaveFile(char *fname);
19  void save(const char *);
20  void save(FILE *);
21 
22  double train(std::vector<double> &input, std::vector<double> &target);
23  double *test(const std::vector<double> &input);
24  double GetInput(std::vector<double> &input, const std::vector<double> &target);
25  double train(std::vector<unsigned int> &input, std::vector<double> &target);
26  double *test(const std::vector<unsigned int> &input);
27 
28  int getNumInputs() { return inputs; }
29  double getInputWeight(int inp, int outp=0) { return weights[0][outp][inp]; }
30 
31  void Print();
32 private:
33  void allocateMemory(const NN *nn = 0);
34  void freeMemory();
35 
36  std::vector< std::vector< std::vector<double> > > weights;
37  std::vector< std::vector< std::vector<double> > > updatedweights;
38  std::vector< std::vector< std::vector<double> > > errors;
39  std::vector<double> hidden;
40  std::vector<double> output;
42 
43  double g(double a);
44  double dg(double a);
45  double outputerr(const std::vector<double> &output, const std::vector<double> &expected, int which);
46  double internalerr(const std::vector<double> &output, const std::vector<double> &expected, int which);
47  double internalinputerr(const std::vector<double> &output, const std::vector<double> &expected, int which);
48  double error(const std::vector<double> &outputs);
49 };
50 
51 
52 #endif
NN::errors
std::vector< std::vector< std::vector< double > > > errors
Definition: NN.h:38
NN::test
double * test(const std::vector< double > &input)
Definition: NN.cpp:429
NN::internalinputerr
double internalinputerr(const std::vector< double > &output, const std::vector< double > &expected, int which)
Definition: NN.cpp:323
NN::error
double error(const std::vector< double > &outputs)
Definition: NN.cpp:333
FunctionApproximator.h
NN::validSaveFile
static bool validSaveFile(char *fname)
Definition: NN.cpp:172
NN::load
void load(const FunctionApproximator *fa)
Definition: NN.h:17
NN::inputs
int inputs
Definition: NN.h:41
NN::load
void load(const char *)
Definition: NN.cpp:195
NN::GetInput
double GetInput(std::vector< double > &input, const std::vector< double > &target)
Definition: NN.cpp:413
NN::getNumInputs
int getNumInputs()
Definition: NN.h:28
NN
Definition: NN.h:7
NN::train
double train(std::vector< double > &input, std::vector< double > &target)
Definition: NN.cpp:344
NN::getInputWeight
double getInputWeight(int inp, int outp=0)
Definition: NN.h:29
NN::dg
double dg(double a)
Definition: NN.cpp:297
NN::hiddens
int hiddens
Definition: NN.h:41
NN::outputerr
double outputerr(const std::vector< double > &output, const std::vector< double > &expected, int which)
Definition: NN.cpp:303
FunctionApproximator
Definition: FunctionApproximator.h:25
NN::save
void save(const char *)
Definition: NN.cpp:254
NN::~NN
~NN()
Definition: NN.cpp:30
NN::outputs
int outputs
Definition: NN.h:41
NN::freeMemory
void freeMemory()
Definition: NN.cpp:119
NN::output
std::vector< double > output
Definition: NN.h:40
NN::updatedweights
std::vector< std::vector< std::vector< double > > > updatedweights
Definition: NN.h:37
NN::allocateMemory
void allocateMemory(const NN *nn=0)
Definition: NN.cpp:63
NN::Print
void Print()
Definition: NN.cpp:502
NN::internalerr
double internalerr(const std::vector< double > &output, const std::vector< double > &expected, int which)
Definition: NN.cpp:312
NN::g
double g(double a)
Definition: NN.cpp:292
NN::hidden
std::vector< double > hidden
Definition: NN.h:39
NN::NN
NN(int inputs, int hiddens, int outputs, double learnrate)
Definition: NN.cpp:22
NN::weights
std::vector< std::vector< std::vector< double > > > weights
Definition: NN.h:36