home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / AI-90-10.ZIP / CONNECTI.CPP < prev    next >
C/C++ Source or Header  |  1990-10-01  |  1KB  |  58 lines

  1. #include "neural.hpp"
  2. #include <stdlib.h>
  3. #include <iostream.h>
  4.  
  5. void Connection::adjust(void)
  6. {
  7.     //If samad Coefficient == 0 this is "classic" backprop
  8.     //If samad Coefficient == 1 this is original "fast backprop"
  9.     //If samad Coefficient is something else, you will usually get significant 
  10.     //changes in learning rate.  The range 0.5 - 2.0 seems to work well 
  11.     delta = learningConstant * n2->error * (n1->output + samadCoefficient * n1->error) + delta * momentum;
  12.     weight += delta;
  13. }
  14.  
  15. void Connection::displaySelf(void)
  16. {
  17.     cout<<"Connection delta: "<<delta<<" weight: "<<weight<<"\n";
  18. }
  19.  
  20.  
  21. void Connection::feedForward(void)
  22. {
  23.     n2->input += n1->output * weight;
  24. }
  25.  
  26. void Connection::set(Neuron* nLow, Neuron* nHigh)
  27. {
  28.     n1 = nLow;
  29.     n2 = nHigh;
  30. }
  31.  
  32. void Connection::setRandom(float lC, float m, float sC)
  33. {
  34.     weight = (((float)rand()/RAND_MAX) - 0.5) / 5;
  35.     delta = 0;
  36.     learningConstant = lC;
  37.     momentum = m;
  38.     samadCoefficient = sC;
  39. }
  40.  
  41.  
  42. int Connection::firstNeuronIs(Neuron* n)
  43. {
  44.  
  45.     if(n == n1)
  46.         return 1;
  47.     else
  48.         return 0;
  49. }
  50.  
  51. int Connection::secondNeuronIs(Neuron* n)
  52. {
  53.     if(n == n2)
  54.         return 1;
  55.     else
  56.         return 0;
  57. }
  58.