neuralNetwork.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*******************************************************************
  2. * addapted by Trevor Standley for use as a function approximator
  3. * Addapted from:
  4. * Basic Feed Forward Neural Network Class
  5. * ------------------------------------------------------------------
  6. * Bobby Anguelov - takinginitiative.wordpress.com (2008)
  7. * MSN & email: [email protected]
  8. ********************************************************************/
  9. #ifndef NEURAL_NETWORK_H
  10. #define NEURAL_NETWORK_H
  11. //standard includes
  12. #include <iostream>
  13. #include <vector>
  14. #include <fstream>
  15. #include <cmath>
  16. #include <limits>
  17. class neuralNetwork
  18. {
  19. private:
  20. //number of neurons
  21. int nInput, nHidden1, nHidden2, nOutput;
  22. //neurons
  23. double* inputNeurons;
  24. double* hiddenNeurons1;
  25. double* hiddenNeurons2;
  26. double* outputNeurons;
  27. //weights
  28. double** wInputHidden;
  29. double** wHidden2Hidden;
  30. double** wHiddenOutput;
  31. public:
  32. //constructor & destructor
  33. neuralNetwork(int numInput, int numHidden1, int numHidden2, int numOutput);
  34. neuralNetwork(const neuralNetwork&);
  35. neuralNetwork();
  36. void operator = (const neuralNetwork&);
  37. ~neuralNetwork();
  38. //weight operations
  39. double* feedForwardPattern( double* pattern );
  40. void backpropigate(double* pattern, double OLR, double H2LR, double H1LR );
  41. void tweakWeights(double howMuch);
  42. void mate(const neuralNetwork&n1,const neuralNetwork&n2);
  43. private:
  44. void initializeWeights();
  45. inline double activationFunction( double x );
  46. void feedForward( double* pattern );
  47. };
  48. std::istream & operator >> (std::istream &, neuralNetwork & ann);
  49. std::ostream & operator << (std::ostream &, const neuralNetwork & ann);
  50. #endif