Hexadroid

Untitled

Sep 16th, 2020
549
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma hdrstop
  2. #pragma argsused
  3.  
  4. #ifdef _WIN32
  5. #include <tchar.h>
  6. #else
  7.   typedef char _TCHAR;
  8.   #define _tmain main
  9. #endif
  10.  
  11. #include <stdio.h>
  12.  
  13. //short tryout
  14. double tin[2][2], tout[2];
  15. double nodea_activation, nodeb_activation, nodec_activation, nodeu_activation, nodew_activation;
  16. double nodeb_input, nodew_input,nodec_input;
  17. double weighta, weightb, weightc, weightu, weightw;
  18. double nodea_input, nodeu_input;
  19. double y,w,r,i;
  20. double Cderivative;
  21. int j;
  22.  
  23. int _tmain(int argc, _TCHAR* argv[])
  24. {
  25.     tin[0][0]=50; tin[0][1]=60; tout[0]=160;
  26.     tin[1][0]=70; tin[1][1]=37; tout[1]=177;
  27.  
  28.     //                          b
  29.     //      (node a)O---------O----------\
  30.     //                                    \
  31.     //                   x                 O (node c)
  32.     //                                    /
  33.     //      (node u)O---------O----------/
  34.     //                        w
  35.  
  36.    weighta = 0.22;
  37.    weightb = 0.32;
  38.    weightc = 0.35;
  39.    weightu = 0.42;
  40.    weightw = 0.12;
  41.  
  42.    r = 0.00001;
  43.  
  44.    for (j=0; j <= 1; j++) {
  45.  
  46.  
  47.  
  48.    nodea_input = tin[j][0];
  49.    nodeu_input =  tin[j][1];
  50.    y = tout[j]; //desired output
  51.  
  52.  
  53.    //forward propagation
  54.  
  55.    for (i = 1; i < 30; i++) {
  56.  
  57.  
  58.  
  59.     //nodea/nodeu input stays same for now
  60.    nodea_activation = nodea_input*weighta;
  61.    nodeu_activation = nodeu_input*weightu;
  62.  
  63.    nodeb_input = nodea_activation + nodeu_activation;
  64.    nodeb_activation = nodeb_input * weightb;
  65.  
  66.    nodew_input =  nodea_activation + nodeu_activation;
  67.    nodew_activation = nodew_input * weightw;
  68.  
  69.    nodec_input =  nodew_activation + nodeb_activation;
  70.    nodec_activation =  nodec_input * weightc;
  71.    //calculate error
  72.       //backward propagation
  73.      Cderivative = 2*(nodec_activation-y);
  74.  
  75.    weightc = weightc - r * (nodec_input*Cderivative);
  76.    weightb = weightb - r * (nodeb_input*Cderivative) * weightc;
  77.    weightw = weightw - r * (nodew_input*Cderivative) * weightc;
  78.    weighta = weighta - r * (nodea_input*Cderivative) * weightc * weightb * weightw;
  79.    weightu = weightu - r * (nodeu_input*Cderivative) * weightc * weightb * weightw;
  80.  
  81.    printf("\nweights %lf %lf %lf %lf %lf",weightc, weightb, weightw, weighta, weightu);
  82.    printf("\n %d output %lf desired %lf",j,nodec_activation, y);
  83.                     } //for i
  84.    }//for j
  85.  
  86.  
  87.  
  88.     scanf("%d",&i);
  89.     return 0;
  90. }
RAW Paste Data