void updS_delta(weight *nptr) { int i, iend; weight *w; flt unmoinsalpha; if (nptr==NULL) { w=weightbase; iend=weightnombre; } else { w=nptr; iend=1; } if (alpha != Flt0) { unmoinsalpha=Fsub(Flt1, alpha); for ( i=0; i<iend; i++, w++ ) { w->Wdelta=Fadd(Fmul( alpha, w->Wdelta ), Fmul( unmoinsalpha, w->Wacc ) ); } } else { for ( i=0; i<iend; i++, w++ ) { w->Wdelta= w->Wacc; } } }
/* compute the backward sum of the * 2nd-derivative weighted by the squared weights */ static void updN_sqbacksum(neurone *n) { if (n->FSaval != NIL) { #ifndef NONEURTYPE synapse *s = n->FSaval; n->Nsqbacksum = Fzero; while (s) { neurtype *taval = s->Naval->type; if (taval && taval->updN_sqbacksum_term) s = (*taval->updN_sqbacksum_term)(n, s); else { flt sum, prod; Fclr(sum); for (; s && s->Naval->type==taval; s=s->NSamont ) { prod = Fmul( Fmul(s->Sval,s->Sval), s->Naval->Nggrad ); sum = Fadd( sum,prod ); } n->Nsqbacksum = Fadd(n->Nsqbacksum, sum); } } #else synapse *s; flt sum , prod; Fclr(sum); for ( s=n->FSaval; s!=NIL; s=s->NSamont ) { prod = Fmul( Fmul(s->Sval,s->Sval), s->Naval->Nggrad ); sum = Fadd( sum,prod ); } n->Nsqbacksum=sum; #endif } }
void updS_acc(neurone *nptr) { int iend; synapse *s; neurone *amont, *aval; int i; #ifndef SYNEPSILON flt preprod; #endif flt eps; #ifndef NONEURTYPE /* Type dependent procedure */ if (nptr==NULL) { aval=neurbase; iend=neurnombre; for ( i=0; i<iend; i++, aval++ ) updS_acc(aval); return; } if (nptr->type && nptr->type->updS_acc) { (*nptr->type->updS_acc)(nptr); return; } #endif /* Optimized procedure */ if (nptr==NULL) { aval=neurbase; iend=neurnombre; } else { aval=nptr; iend=1; } #ifdef SYNEPSILON for ( i=0; i<iend; i++, aval++ ) { for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { eps=s->Sepsilon; amont=s->Namont; s->Sacc = Fadd(s->Sacc, Fmul(amont->Nval, Fmul(aval->Ngrad, eps) ) ); } } #else /* NOT SYNEPSILON */ for ( i=0; i<iend; i++, aval++ ) { eps=aval->Nepsilon; preprod=Fmul( aval->Ngrad, eps ); for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; s->Sacc = Fadd( s->Sacc, Fmul( amont->Nval, preprod ) ); } } #endif /* SYNEPSILON */ }
static void updN_sum(neurone *n) { #ifndef NONEURTYPE if (n->type && n->type->updN_sum) { (*n->type->updN_sum)(n); } else #endif { synapse *s; flt sum,prod; Fclr(sum); for ( s=n->FSamont; s!=NIL; s=s->NSaval ) { prod = Fmul( s->Sval, s->Namont->Nval ); sum = Fadd( sum,prod ); } if (theta != Flt0) { prod=Fmul(Fgauss(),theta); sum=Fadd( sum,prod ); } n->Nsum=sum; } }
static void iniN_lms_grad(neurone *n, neurone *ideal) { flt x; x = Fsub( ideal->Nval, n->Nval ); energie=Fadd(energie,Fmul(FltHalf,Fmul(x,x))); n->Nbacksum = x; updN_grad(n); }
/* compute the instantaneous * 2nd-derivative (without the input) */ void updN_lmggrad(neurone *n) { #ifndef NONEURTYPE if (n->type && n->type->updN_lmggrad) { (*n->type->updN_lmggrad)(n); } else #endif { flt x = CALLDNLF(n->Nsum); n->Nggrad = Fmul( n->Nsqbacksum, Fmul(x,x) ); } }
static void iniN_thlms_grad(neurone *n, neurone *ideal) { flt x; x = Fsub( ideal->Nval, n->Nval ); if ( ideal->Nval > g_threshold) { if ( x < Flt0 ) x=Flt0; } else { if ( x > Flt0 ) x=Flt0; } energie=Fadd(energie,Fmul(FltHalf,Fmul(x,x))); n->Nbacksum = x; updN_grad(n); }
void updS_val(weight *nptr) { int i, iend; weight *w; flt unmoinsdecay; if (nptr==NULL) { w=weightbase; iend=weightnombre; } else { w=nptr; iend=1; } if (decay != Flt0) { unmoinsdecay=Fsub(Flt1, decay); for ( i=0; i<iend; i++, w++ ) { w->Wval=Fadd( Fmul( unmoinsdecay, w->Wval ), w->Wdelta ); } } else { for ( i=0; i<iend; i++, w++ ) { w->Wval=Fadd( w->Wval, w->Wdelta ); } } }
/* computes the average curvature * for a cell or the connection to a cell */ static void updN_sigma(neurone *n) { #ifndef NONEURTYPE if (n->type && n->type->updN_sigma) { (*n->type->updN_sigma)(n); } else #endif { #ifdef SYNEPSILON synapse *s; flt gammaggrad, oneminusgamma; oneminusgamma=Fsub(Flt1, mygamma); gammaggrad=Fmul(mygamma, n->Nggrad); for ( s=n->FSamont; s!=NIL; s=s->NSaval) { flt x = s->Namont->Nval; s->Ssigma = Fadd(Fmul(oneminusgamma, s->Ssigma), Fmul(gammaggrad, Fmul(x,x)) ); } #else n->Nsigma = Fadd(Fmul( Fsub(Flt1, mygamma), n->Nsigma), Fmul( Fmul(mygamma, n->Nggrad), mean_sq_input(n) )); #endif } }
static void updN_ART_activation(neurone *n) { flt net1,net2; if (Fsgn(n->Nval)>0) { net1 = Fadd(Fmul(n->Nval, iacgamma),Fmul(n->Nspare1,alpha)); net2 = Fmul(n->Nspare2,beta); } else { net1 = Fmul(n->Nspare1,alpha); net2 = Fadd(Fmul(n->Nval, iacgamma),Fmul(n->Nspare2,beta)); } n->Nsum = Fsub(Fadd(n->Nsum, Fadd(Fmul(net1,Fsub(max,n->Nsum)), Fmul(net2,Fsub(n->Nsum,min)))), Fmul(decay,Fsub(n->Nsum,rest)) ); }
/* returns the length of the weight-change of a cell */ static flt delta_sqr_norm(neurone *n, int *fan) { synapse *s; flt sum; Fclr(sum); for ( s=n->FSamont; s!=NIL; s=s->NSaval ) { (*fan)++; sum = Fadd(sum, Fmul(s->Sdelta, s->Sdelta)); } return sum; }
static void updN_deltastate(neurone *n) { #ifndef NONEURTYPE if (n->type && n->type->updN_deltastate) { (*n->type->updN_deltastate)(n); } else #endif { synapse *s; flt sum,prod; Fclr(sum); for ( s=n->FSamont; s!=NIL; s=s->NSaval ) { prod = Fmul( s->Sval, s->Namont->Ngrad ); sum = Fadd( sum, prod ); prod = Fmul( s->Sdelta, s->Namont->Nval ); sum = Fadd( sum, prod ); } n->Ngrad = Fmul(sum, CALLDNLF(n->Nsum) ); } }
static void updN_inhibition(neurone *n) { synapse *s; flt sum,prod; Fclr(sum); for (s=n->FSamont; s!=NIL; s=s->NSaval) if ( Fsgn(s->Sval) < 0 ) { prod = Fmul( s->Sval, s->Namont->Nval ); sum = Fadd( sum,prod ); }; n->Nspare2=sum; }
void updN_grad(neurone *n) { #ifndef NONEURTYPE if (n->type && n->type->updN_grad) { (*n->type->updN_grad)(n); } else #endif { n->Ngrad = Fmul( n->Nbacksum, CALLDNLF(n->Nsum) ); } }
static void updN_IAC_activation(neurone *n) { flt net; net = Fadd(Fmul(n->Nval, iacgamma), Fadd(Fmul(n->Nspare1,alpha), Fmul(n->Nspare2,beta) )); if (Fsgn(net)>0) { n->Nsum = Fadd(n->Nsum,Fsub(Fmul(net,Fsub(max,n->Nsum)), Fmul(decay,Fsub(n->Nsum,rest)) )); } else { n->Nsum = Fadd(n->Nsum,Fsub(Fmul(net,Fsub(n->Nsum,min)), Fmul(decay,Fsub(n->Nsum,rest)) )); } }
static flt mean_sq_input(neurone *n) { synapse *s; flt sum, nbre; Fclr(sum); Fclr(nbre); for ( s=n->FSamont; s!=NIL; s=s->NSaval ) { flt x = s->Namont->Nval; sum = Fadd( sum, Fmul(x,x) ); nbre=Fadd(nbre,Flt1); }; if (nbre>Flt0) return Fdiv(sum,nbre); else return Flt0; }
char *expr(int prec, struct var **rtv) { char *x = "0"; struct var *v = 0; while (*ptr == ' ' || *ptr == '\t') ++ptr; if ((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || *ptr == '_') { char *s = ptr, c; while ((*ptr >= 'a' && *ptr <= 'z') || (*ptr >= 'A' && *ptr <= 'Z') || *ptr == '_' || (*ptr >= '0' && *ptr <= '9')) ++ptr; c = *ptr; *ptr = 0; v = get(s); x = v->val; *ptr = c; if (v->func) { while (*ptr == ' ' || *ptr == '\t') ++ptr; if (*ptr == '(') { char *arg; ++ptr; arg = expr(0, &dumb); if (*ptr == ')') ++ptr; else { if (!err) err = "Missing )"; } x = v->func(arg); } else { if (!err) err = "Missing argument"; } } } else if ((*ptr >= '0' && *ptr <= '9') || *ptr == '.') { char *s = ptr; while ((*ptr >= '0' && *ptr <= '9') || *ptr == '.' || *ptr == 'e' || *ptr == 'E') ++ptr; x = (char *)malloc(ptr - s + 1); x[ptr - s] = 0; memcpy(x, s, ptr - s); } else if (*ptr == '(') { ++ptr; x = expr(0, &v); if (*ptr == ')') ++ptr; else { if (!err) err = "Missing )"; } } else if (*ptr == '-') { ++ptr; x = Fneg(expr(10, &dumb)); } loop: while (*ptr == ' ' || *ptr == '\t') ++ptr; /* if (*ptr == '^' && 6 >= prec) { ++ptr; x = pow(x, expr(6, &dumb)); goto loop; } else */ if (*ptr == '*' && 5 > prec) { ++ptr; x = Fmul(x, expr(5, &dumb)); goto loop; } else if (*ptr == '/' && 5 > prec) { ++ptr; x = Fdiv(x, expr(5, &dumb), precision); goto loop; } else if (*ptr == '+' && 4 > prec) { ++ptr; x = Fadd(x, expr(4, &dumb)); goto loop; } else if (*ptr == '-' && 4 > prec) { ++ptr; x = Fsub(x, expr(4, &dumb)); goto loop; } else if (*ptr == '=' && 2 >= prec) { ++ptr; x = expr(2, &dumb); if (v) v->val = x, v->set = 1; else { if (!err) err = "Left side of = is not an l-value"; } goto loop; } *rtv = v; return x; }
static double Fmul(FloatConstant* a, double b) { return Fmul(a->Value(), b, a->GetType()->GetSubtype()); }
static void updS_all(neurone *nptr) { synapse *s; neurone *amont, *aval; int i,iend; flt eps, delta; flt preprod, predecay; flt unmoinsalpha = Fsub(Flt1, alpha); #ifndef NONEURTYPE /* type dependent procedure */ if (nptr==NULL) { aval=neurbase; iend=neurnombre; for ( i=0; i<iend; i++, aval++ ) updS_all(aval); return; } if (nptr->type && nptr->type->updS_all) { (*nptr->type->updS_all)(nptr); return; } #endif /* Optimized procedure */ if (nptr==NULL) { aval=neurbase; iend=neurnombre; } else { aval=nptr; iend=1; } #ifdef SYNEPSILON if ((alpha==Flt0) && (decay==Flt0)) { for ( i=0; i<iend; i++, aval++ ) { for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; eps=s->Sepsilon; delta = Fmul( amont->Nval, Fmul(aval->Ngrad, eps) ); s->Sdelta=delta; s->Sval = Fadd( s->Sval, delta ); } } } /* end of alpha=0, decay=0 */ else if ((alpha != Flt0) && (decay==0)) { for ( i=0; i<iend; i++, aval++ ) { preprod=Fmul( unmoinsalpha, aval->Ngrad ); for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; eps=s->Sepsilon; delta = Fadd( Fmul(s->Sdelta, alpha), Fmul( amont->Nval, Fmul(preprod, eps) )); s->Sdelta=delta; s->Sval = Fadd( s->Sval, delta ); } } } /* end of alpha<>0, decay=0 */ else if ((alpha==Flt0) && (decay!=Flt0)) { for ( i=0; i<iend; i++, aval++ ) { for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; eps=s->Sepsilon; predecay=Fsub(Flt1, Fmul(eps, decay)); delta = Fmul( amont->Nval, Fmul(aval->Ngrad, eps) ); s->Sdelta=delta; s->Sval = Fadd( Fmul(predecay, s->Sval), delta ); } } } /* end of alpha=0, decay<>0 */ else if ((alpha!=Flt0) && (decay!=Flt0)) { for ( i=0; i<iend; i++, aval++ ) { preprod=Fmul( unmoinsalpha, aval->Ngrad ); for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; eps=s->Sepsilon; predecay=Fsub(Flt1, Fmul(eps, decay)); delta = Fadd(Fmul(s->Sdelta, alpha), Fmul( amont->Nval, Fmul(preprod, eps) )); s->Sdelta=delta; s->Sval = Fadd( Fmul(predecay, s->Sval), delta ); } } } /* end of alpha<>0, decay<>0 */ #else /* NOT SYNEPSILON */ if ((alpha==Flt0) && (decay==Flt0)) { for ( i=0; i<iend; i++, aval++ ) { eps=aval->Nepsilon; preprod=Fmul(aval->Ngrad, eps); for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; delta = Fmul( amont->Nval, preprod ); s->Sdelta=delta; s->Sval = Fadd( s->Sval, delta ); } } } /* end of alpha=0, decay=0 */ else if ((alpha != Flt0) && (decay==0)) { for ( i=0; i<iend; i++, aval++ ) { eps=aval->Nepsilon; preprod=Fmul(aval->Ngrad, eps); preprod=Fmul( unmoinsalpha, preprod ); for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; delta = Fadd( Fmul(s->Sdelta, alpha), Fmul( amont->Nval, preprod ) ); s->Sdelta=delta; s->Sval = Fadd( s->Sval, delta ); } } } /* end of alpha<>0, decay=0 */ else if ((alpha==Flt0) && (decay!=Flt0)) { for ( i=0; i<iend; i++, aval++ ) { eps=aval->Nepsilon; preprod=Fmul(aval->Ngrad, eps); predecay=Fsub(Flt1, Fmul(eps, decay)); for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; delta = Fmul( amont->Nval, preprod ); s->Sdelta=delta; s->Sval = Fadd( Fmul(predecay, s->Sval), delta ); } } } /* end of alpha=0, decay<>0 */ else if ((alpha!=Flt0) && (decay!=Flt0)) { for ( i=0; i<iend; i++, aval++ ) { eps=aval->Nepsilon; preprod=Fmul(aval->Ngrad, eps); preprod=Fmul( unmoinsalpha, preprod ); predecay=Fsub(Flt1, Fmul(eps, decay)); for ( s=aval->FSamont; s!=NIL; s=s->NSaval ) { amont=s->Namont; delta = Fadd( Fmul(s->Sdelta, alpha), Fmul( amont->Nval, preprod ) ); s->Sdelta=delta; s->Sval = Fadd( Fmul(predecay, s->Sval), delta ); } } } /* end of alpha<>0, decay<>0 */ #endif /* SYNEPSILON */ }