HOG2
LogisticRegression.h
Go to the documentation of this file.
1 //
2 // LogisticRegression.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 5/19/14.
6 // Copyright (c) 2014 University of Denver. All rights reserved.
7 //
8 
9 #ifndef __hog2_glut__LogisticRegression__
10 #define __hog2_glut__LogisticRegression__
11 
12 #include "FPUtil.h"
13 #include "FunctionApproximator.h"
14 #include "LinearRegression.h"
15 
17 public:
18  LogisticRegression(int _inputs, int _outputs, double learnrate);
20  LogisticRegression(char *);
23 
24  void setUseBinary(bool binary) { useBinary = binary; }
25 
26  void resizeInputs(int newSize, double newVal);
27  void resizeInputs(int newSize);
28 
29  void save(const char *);
30  void save(FILE *);
31  void load(const char *);
32  void load(FILE *);
33  void load(const FunctionApproximator *fa) { load((LogisticRegression*)fa); }
34  void load(const LogisticRegression *);
35  static bool validSaveFile(char *fname);
36 
37  double train(std::vector<double> &input, std::vector<double> &output2);
38  double *test(const std::vector<double> &input);
39  double train(std::vector<unsigned int> &input, std::vector<double> &output2);
40  double *test(const std::vector<unsigned int> &input);
41 
42  void Print();
43 
44  int getNumInputs() { return inputs; }
45  void setInputWeight(double value, unsigned int weightNum, unsigned int whichOutput=0);
46  double getInputWeight(int inp, int outp=0) { return weight[outp][inp]; }
47  void getWeightUpdateVariance(std::vector<double> &var, unsigned int which=0);
48  double getWeightUpdateVariance(unsigned int weightNum, unsigned int whichOutput=0);
49 
50  void getWeightUpdateAverage(std::vector<double> &var, unsigned int which=0);
51  double getWeightUpdateAverage(unsigned int weightNum, unsigned int whichOutput=0);
52 
53  void getWeightUpdateSum(std::vector<double> &var, unsigned int which=0);
54  double getWeightUpdateSum(unsigned int weightNum, unsigned int whichOutput=0);
55  void resetWeightVariance(unsigned int weightNum, unsigned int whichOutput=0);
56  void resetWeightVariance();
57 
58  int getWeightFrequency(unsigned int weightNum, unsigned int whichOutput=0);
59 
60  double GetInput(std::vector<double> &input, const std::vector<double> &target)
61  { assert(!"Unimplemented"); }
62 private:
63  void allocateMemory();
64  void freeMemory();
65 
66  double g(double a);
67  double dg(double a);
68  double outputerr(std::vector<double> &output, std::vector<double> &expected, int which);
69 
70  double error(double* output);
71  std::vector<std::vector<double> > weight;
72  std::vector<std::vector<updateData> > updates;
73  //std::vector<double > weight;
74  std::vector<double> output;
75  //double** weight;
76  //double* output;
78  bool useBinary;
79 };
80 
81 #endif /* defined(__hog2_glut__LogisticRegression__) */
LogisticRegression::setInputWeight
void setInputWeight(double value, unsigned int weightNum, unsigned int whichOutput=0)
Definition: LogisticRegression.cpp:517
LogisticRegression::GetInput
double GetInput(std::vector< double > &input, const std::vector< double > &target)
Definition: LogisticRegression.h:60
LogisticRegression::updates
std::vector< std::vector< updateData > > updates
Definition: LogisticRegression.h:72
FunctionApproximator.h
LogisticRegression::resetWeightVariance
void resetWeightVariance()
Definition: LogisticRegression.cpp:501
FPUtil.h
LogisticRegression::getWeightUpdateAverage
void getWeightUpdateAverage(std::vector< double > &var, unsigned int which=0)
Definition: LogisticRegression.cpp:453
LogisticRegression::getNumInputs
int getNumInputs()
Definition: LogisticRegression.h:44
LogisticRegression::resizeInputs
void resizeInputs(int newSize, double newVal)
Definition: LogisticRegression.cpp:79
LogisticRegression::inputs
int inputs
Definition: LogisticRegression.h:77
LogisticRegression::LogisticRegression
LogisticRegression(int _inputs, int _outputs, double learnrate)
Definition: LogisticRegression.cpp:22
LogisticRegression::getWeightFrequency
int getWeightFrequency(unsigned int weightNum, unsigned int whichOutput=0)
Definition: LogisticRegression.cpp:512
LogisticRegression::weight
std::vector< std::vector< double > > weight
Definition: LogisticRegression.h:71
LogisticRegression::load
void load(const FunctionApproximator *fa)
Definition: LogisticRegression.h:33
FunctionApproximator
Definition: FunctionApproximator.h:25
LogisticRegression::validSaveFile
static bool validSaveFile(char *fname)
Definition: LogisticRegression.cpp:265
LogisticRegression::setUseBinary
void setUseBinary(bool binary)
Definition: LogisticRegression.h:24
LogisticRegression::outputerr
double outputerr(std::vector< double > &output, std::vector< double > &expected, int which)
Definition: LogisticRegression.cpp:338
LogisticRegression::getInputWeight
double getInputWeight(int inp, int outp=0)
Definition: LogisticRegression.h:46
LogisticRegression::output
std::vector< double > output
Definition: LogisticRegression.h:74
LogisticRegression::getWeightUpdateVariance
void getWeightUpdateVariance(std::vector< double > &var, unsigned int which=0)
Definition: LogisticRegression.cpp:428
LogisticRegression::outputs
int outputs
Definition: LogisticRegression.h:77
LinearRegression.h
LogisticRegression::load
void load(const char *)
Definition: LogisticRegression.cpp:168
LogisticRegression::useBinary
bool useBinary
Definition: LogisticRegression.h:78
LogisticRegression::g
double g(double a)
Definition: LogisticRegression.cpp:327
LogisticRegression::error
double error(double *output)
LogisticRegression::getWeightUpdateSum
void getWeightUpdateSum(std::vector< double > &var, unsigned int which=0)
Definition: LogisticRegression.cpp:478
LogisticRegression::train
double train(std::vector< double > &input, std::vector< double > &output2)
Definition: LogisticRegression.cpp:374
LogisticRegression::~LogisticRegression
~LogisticRegression()
Definition: LogisticRegression.cpp:74
LogisticRegression::save
void save(const char *)
Definition: LogisticRegression.cpp:288
LogisticRegression
Definition: LogisticRegression.h:16
LogisticRegression::Print
void Print()
Definition: LogisticRegression.cpp:523
LogisticRegression::dg
double dg(double a)
Definition: LogisticRegression.cpp:332
LogisticRegression::freeMemory
void freeMemory()
Definition: LogisticRegression.cpp:154
LogisticRegression::allocateMemory
void allocateMemory()
Definition: LogisticRegression.cpp:137
LogisticRegression::test
double * test(const std::vector< double > &input)
Definition: LogisticRegression.cpp:414