Example #1
0
/* 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
    }
}
Example #2
0
  // assembles FEA matrices for the various elements into global matrices for the structure
  // EIx, EA etc. are arrays of length nodes-1
  // matrix are of size DOF*nodes x DOF*nodes
  void FEMAssembly(int nodes, const Vector &z, const PolyVec &EIx, const PolyVec &EIy, 
		   const PolyVec &EA, const PolyVec &GJ, const PolyVec &rhoA, const PolyVec &rhoJ, 
		   const PolyVec &Px, const PolyVec &Py, const PolyVec &Pz,
		   Matrix &K, Matrix &M, Matrix &Nother, Matrix &N, Vector &F){
    
    //using namespace boost::numeric::ublas;
    
    // initialize
    F.setZero();
    K.setZero();
    M.setZero();
    N.setZero();
    Nother.setZero();
    
    Matrix Ksub(2*DOF, 2*DOF);
    Matrix Msub(2*DOF, 2*DOF);
    Matrix Ndist_sub(2*DOF, 2*DOF);
    Matrix Nconst_sub(2*DOF, 2*DOF);
    Vector Fsub(2*DOF);
        
    std::vector<int> r(2*DOF);
    //range r;
    
    
    // integrate distributed axial loads
    PolyVec FzFromPz;
    integrateDistributedCompressionLoads(z, Pz, FzFromPz);
    
    for (int i = 0; i < nodes-1; i++) {
        
      double L = z[i+1] - z[i];
        
      // compute submatrix
      beamMatrix(L, EIx[i], EIy[i], EA[i], GJ[i], rhoA[i], rhoJ[i], Px[i], Py[i], FzFromPz[i],
		 Ksub, Msub, Ndist_sub, Nconst_sub, Fsub);

      // insert into global matrix
      for (int k=0; k<2*DOF; k++) r[k] = i*DOF + k;
      //r = range(i*DOF, i*DOF + 2*DOF);

	
      for (int ii=0; ii<2*DOF; ii++) {
	F(r[ii]) += Fsub(ii);
	for (int jj=0; jj<2*DOF; jj++) {
	  K(r[ii], r[jj]) += Ksub(ii,jj);
	  M(r[ii], r[jj]) += Msub(ii,jj);
	  Nother(r[ii], r[jj]) += Ndist_sub(ii,jj);
	  N(r[ii], r[jj]) += Nconst_sub(ii,jj);
	}
      }
      //project(K, r, r) += Ksub;
      //project(M, r, r) += Msub;
      //project(Nother, r, r) += Ndist_sub;
      //project(N, r, r) += Nconst_sub;
      //project(F, r) += Fsub;
        
    }
       
  }
Example #3
0
File: iac.c Project: barak/lush
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)) );
}
Example #4
0
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  );
    }
  }
}
Example #5
0
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;
    }
  }
}
Example #6
0
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);
}
Example #7
0
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);
}
Example #8
0
/* compute the instantaneous 
 * 2nd-derivative (without the input) 
 */
void 
updN_ggrad(neurone *n)
{
#ifndef NONEURTYPE
  if (n->type && n->type->updN_ggrad)
    {
      (*n->type->updN_ggrad)(n);
    }
  else
#endif
  {
    flt x = CALLDNLF(n->Nsum);
    n->Nggrad = Fsub(Fmul( n->Nsqbacksum, Fmul(x,x) ),
		     Fmul( n->Nbacksum, CALLDDNLF(n->Nsum)) );
  }
}
Example #9
0
File: iac.c Project: barak/lush
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)) ));
  }
}
Example #10
0
File: calc.c Project: jhallen/farb
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;
}
Example #11
0
    static double Fsub(FloatConstant* a, double b) {
		return Fsub(a->Value(), b, a->GetType()->GetSubtype());
	}
Example #12
0
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 */

}