Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma hdrstop
- #pragma argsused
- #ifdef _WIN32
- #include <tchar.h>
- #else
- typedef char _TCHAR;
- #define _tmain main
- #endif
- #include <stdio.h>
- //short tryout
- double tin[2][2], tout[2];
- double nodea_activation, nodeb_activation, nodec_activation, nodeu_activation, nodew_activation;
- double nodeb_input, nodew_input,nodec_input;
- double weighta, weightb, weightc, weightu, weightw;
- double nodea_input, nodeu_input;
- double y,w,r,i;
- double Cderivative;
- int j;
- int _tmain(int argc, _TCHAR* argv[])
- {
- tin[0][0]=50; tin[0][1]=60; tout[0]=160;
- tin[1][0]=70; tin[1][1]=37; tout[1]=177;
- // b
- // (node a)O---------O----------\
- // \
- // x O (node c)
- // /
- // (node u)O---------O----------/
- // w
- weighta = 0.22;
- weightb = 0.32;
- weightc = 0.35;
- weightu = 0.42;
- weightw = 0.12;
- r = 0.00001;
- for (j=0; j <= 1; j++) {
- nodea_input = tin[j][0];
- nodeu_input = tin[j][1];
- y = tout[j]; //desired output
- //forward propagation
- for (i = 1; i < 30; i++) {
- //nodea/nodeu input stays same for now
- nodea_activation = nodea_input*weighta;
- nodeu_activation = nodeu_input*weightu;
- nodeb_input = nodea_activation + nodeu_activation;
- nodeb_activation = nodeb_input * weightb;
- nodew_input = nodea_activation + nodeu_activation;
- nodew_activation = nodew_input * weightw;
- nodec_input = nodew_activation + nodeb_activation;
- nodec_activation = nodec_input * weightc;
- //calculate error
- //backward propagation
- Cderivative = 2*(nodec_activation-y);
- weightc = weightc - r * (nodec_input*Cderivative);
- weightb = weightb - r * (nodeb_input*Cderivative) * weightc;
- weightw = weightw - r * (nodew_input*Cderivative) * weightc;
- weighta = weighta - r * (nodea_input*Cderivative) * weightc * weightb * weightw;
- weightu = weightu - r * (nodeu_input*Cderivative) * weightc * weightb * weightw;
- printf("\nweights %lf %lf %lf %lf %lf",weightc, weightb, weightw, weighta, weightu);
- printf("\n %d output %lf desired %lf",j,nodec_activation, y);
- } //for i
- }//for j
- scanf("%d",&i);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement