⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 int.c

📁 #ifdef INTEGER #include "ibp.h" #else #include "rbp.h" #endif /* built-in C functions */
💻 C
📖 第 1 页 / 共 2 页
字号:
   {
    w = (WTNODE *) u->wtlist;
    while (w != NULL)
     {
      if (w->inuse)
       {
        if (w->total > 0) temp2 = (INT32) (w->total + 512) >> 10;
        else temp2 = -((INT32) (512 - w->total) >> 10);
        dbarm1 = w->olddw;
        temp = (INT32) theta2 * temp2 + (INT32) theta1 * dbarm1;
        if (temp > 0) w->olddw = (INT32) (temp + 512) >> 10;
        else w->olddw = -((INT32) (512 - temp) >> 10);
        if (temp2 > 0 && dbarm1 > 0) w->eta = w->eta + rkappa;
        else if (temp2 < 0 && dbarm1 < 0) w->eta = w->eta + rkappa;
        else if (temp2 > 0 && dbarm1 < 0)w->eta = ((INT32) w->eta * rdecay) >> 10;
        else if (temp2 < 0 && dbarm1 > 0)w->eta = ((INT32) w->eta * rdecay) >> 10;
        if (w->eta > etamax) w->eta = etamax;
        temp = (INT32) temp2 * w->eta;
        if (temp > 0) temp2 = (INT32) (temp + 512) >> 10;
        else if (temp < 0) temp2 = -((INT32) (512 - temp) >> 10);

        else if (w->slope == 0)
           {if (w->total < 0) temp2 = noise; else temp2 = -noise;}
        w->slope = temp2;

        temp = (INT32) w->weight + temp2;
        if (temp > MAXSHORT)
         {
          wtlimithit = 1;
          w->weight = MAXSHORT;
         }
        else if (temp < MINSHORT)
         {
          wtlimithit = 1;
          w->weight = MINSHORT;
         }
        else w->weight = temp;
       };
      w = w->next;
     };
    u = u->next;
   };
  layer = layer->backlayer;
 };
}

void qp_update()
{
register INT32 temp, s, nextdw;
register WTNODE *w;
register short rmu, reta, shrinkfactor, rqpdecay, addslope;
register UNIT *u;
LAYER *layer;

rmu = mu;
shrinkfactor = ((INT32) rmu * 1024 + 512) / (1024 + rmu);
reta = qpeta;
if (qpslope == '+') addslope = 1; else addslope = 0;
layer = last;
while (layer->backlayer != NULL)
 {
  if (layer == last) rqpdecay = 1000000.0 * qpdecayo + 0.5;
  else rqpdecay = 1000000.0 * qpdecayh + 0.5;
  u = (UNIT *) layer->units;
  while (u != NULL)
   {
    w = (WTNODE *) u->wtlist;
    while (w != NULL)
     {
      if (w->inuse)
       {
        if (w->weight > 0)
           s = (((INT32) rqpdecay * w->weight + 512) >> 10) - w->total;
        else s = -(((INT32) 512 - (INT32) rqpdecay * w->weight) >> 10) - w->total;
        if (s > 0) s = (s + 512) >> 10;
        else s = -(((INT32) 512 - s) >> 10);
        if (w->olddw < 0)
         {
          if (s >= (((INT32) shrinkfactor * w->eta) >> 10))
             nextdw =  - (((INT32) 512 - (INT32) rmu * w->olddw) >> 10);
          else nextdw = ((INT32) w->olddw * s) / (w->eta - s);
          if (addslope && s > 0)
             nextdw = nextdw - (((INT32) reta * s + 512) >> 10);
         }
        else if (w->olddw > 0)
         {
          if (s <= (((INT32) shrinkfactor * w->eta) >> 10))
             nextdw = (((INT32) rmu * w->olddw + 512) >> 10);
          else nextdw = ((INT32) w->olddw * s) / (w->eta - s);
          if (addslope && s < 0)
             nextdw = nextdw + (((INT32) 512 - (INT32) reta * s) >> 10);
         }
        else
         {
          temp = (INT32) reta * s;
          if (temp > 0) nextdw = - ((temp + 512) >> 10);
          else if (temp < 0) nextdw = (((INT32) 512 - temp) >> 10);
          else if (s > 0) nextdw = qpnoise;
          else nextdw = -qpnoise;
         };
        if (nextdw > MAXSHORT) nextdw = MAXSHORT;
        else if (nextdw < MINSHORT) nextdw = MINSHORT;
        w->olddw = nextdw;
        temp = (INT32) w->weight + nextdw;
        if (temp > MAXSHORT)
         {
          wtlimithit = 1;
          w->weight = MAXSHORT;
         }
        else if (temp < MINSHORT)
         {
          wtlimithit = 1;
          w->weight = MINSHORT;
         }
        else w->weight = temp;
        if (s > MAXSHORT) w->eta = MAXSHORT;
        else if (s < MINSHORT) w->eta = MINSHORT;
        else w->eta = s;
       };
      w = w->next;
     };
    u = u->next;
   };
  layer = layer->backlayer;
 };
}

#else
void dbd_update() {};
void qp_update() {};
#endif

void tdupdate() {};       /* never programmed for the integer version */

short cbackoutput()       /* The continuous update version of back- */
{                         /* propagation that changes upper level */
register short deltaj;    /* weights before passing back errors. */
register INT32 etadeltaj, temp, temp2;
register short temp3, adiff;
register UNIT *bunit;
register WTNODE *w;
register UNIT *u;
register short ralpha, reta, notclose, D;
PATNODE *target;
char actfun;
PATLIST *pl;

actfun = last->activation;
D = last->D;
ralpha = alpha;
reta = eta;
notclose = last->unitcount;
u = (UNIT *) last->units;
pl = last->currentpat[TRAIN];
target = pl->pats;
while (u != NULL)
 { 
  temp3 = u->oj;
  temp2 = target->val - temp3;
  target++;
  if (temp2 > 0) adiff = temp2; else adiff = -temp2;
  if (adiff < toler) notclose = notclose - 1;
  totaldiff = totaldiff + adiff;
  if (deriv == 'd') deltaj = temp2;
  else if (deriv == 'f')
   switch (actfun) {
   case 'l': deltaj = temp2 + 102;
             break;
   case 's': temp = (INT32) temp2 * ((INT32) 104448 +
                    (INT32) temp3 * ((short)(1024 - temp3)));
             if(temp > 0) deltaj = (INT32) (temp + 524288) >> 20;
             else deltaj = -(((INT32) 524288 - temp) >> 20);
             break;}
  etadeltaj = (INT32) deltaj * reta;
  w = (WTNODE *) u->wtlist;
#ifdef SYMMETRIC
   while (w->next != NULL)
#else
   while (w != NULL)
#endif
    { /* get a slope for each weight */
     bunit = (UNIT *) w->backunit;
     temp = (INT32) etadeltaj * bunit->oj;
     if(temp > 0) temp = (INT32) (temp + 524288) >> 20;
     else temp = -(((INT32) 524288 - temp) >> 20);
#ifdef SYMMETRIC
     temp2 = (INT32) ralpha * *(w->olddw);
#else
     temp2 = (INT32) ralpha * w->olddw;
#endif
     if (temp2 > 0) temp3 = temp + (((INT32) temp2 + 512) >> 10);
     else temp3 = temp - (((INT32) 512 - temp2) >> 10);
#ifdef SYMMETRIC
     *(w->olddw) = temp3;
#else
     w->olddw = temp3;
#endif
     /* w->weight = w->weight + w->olddw */
#ifdef SYMMETRIC
     temp = (INT32) *(w->weight) + temp3;
     if (temp > MAXSHORT)
      {
       wtlimithit = 1;
       *(w->weight) = MAXSHORT;
      }
     else if (temp < MINSHORT)
      {
       wtlimithit = 1;
       *(w->weight) = MINSHORT;
      }
     else *(w->weight) = temp;
#else
     temp = (INT32) w->weight + temp3;
     if (temp > MAXSHORT)
      {
       wtlimithit = 1;
       temp3 = MAXSHORT;
      }
     else if (temp < MINSHORT)
      {
       wtlimithit = 1;
       temp3 = MINSHORT;
      }
     else temp3 = temp;
     w->weight = temp3;
     if (bunit->layernumber > 1)
        bunit->error = bunit->error + (INT32) deltaj * temp3;
#endif
     w = w->next;
    };
  u = u->next;
 }
return(notclose);
}

#ifndef SYMMETRIC

void cbackinner()
{
register short deltaj;
register INT32 etadeltaj, temp, temp2;
register short temp3, reta, ralpha;
register UNIT *bunit;
register WTNODE *w;
register UNIT *u;
register WTTYPE D;
char actfun;
LAYER *layer;

reta = eta2;
ralpha = alpha;
layer = last->backlayer;
while (layer->backlayer != NULL)
 {
  actfun = layer->activation;
  D = layer->D;
  u = (UNIT *) layer->units;
  while (u != NULL)
   {
    temp3 = u->oj;
    switch (actfun) {
    case 'l': deltaj = u->error;
              break;
    case 's': temp = (((INT32) temp3*((short)(1024-temp3))+512) >> 10)
                * u->error;
              if (temp > 0) deltaj = (INT32) (temp + 524288) >> 20;
              else deltaj = -(((INT32) 524288 - temp) >> 20);
              break;}
    etadeltaj = (INT32) reta * deltaj;
    w = (WTNODE *) u->wtlist;
      while (w != NULL)
       {
        bunit = (UNIT *) w->backunit;
        temp = (INT32) etadeltaj * bunit->oj;
        if (temp > 0) temp = (INT32) (temp + 524288) >> 20;
        else temp = -(((INT32) 524288 - temp) >> 20);
        temp2 = (INT32) ralpha * w->olddw;
        if (temp2 > 0) temp3 = temp + ((INT32) (temp2 + 512) >> 10);
        else temp3 = temp - (((INT32) 512 - temp2) >> 10);
        w->olddw = temp3;
        temp = (INT32) w->weight + temp3;
        if (temp > MAXSHORT)
         {
          wtlimithit = 1;
          temp3 = MAXSHORT;
         }
        else if (temp < MINSHORT)
         {
          wtlimithit = 1;
          temp3 = MINSHORT;
         }
        else temp3 = temp;       
        w->weight = temp3;
        if (bunit->layernumber > 1)
           bunit->error = bunit->error + (INT32) deltaj * temp3;
        w = w->next;
       };
     u = u->next;
    };
   layer = layer->backlayer;
  };
}
#endif

void maze() {} /* never programmed for the integer version */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -