예제 #1
0
static void
zero_reseau(void)
{
  if (neurbase!=NIL) {
#ifndef NONEURTYPE
    int i;
    for (i=0; i<neurmax; i++)
      set_neurtype(neuraddress[i], NULL, NULL);
#endif
    free((char *)neurbase);
    neurbase = NIL;
    neurnombre = neurmax = 0;
  }
  if (synbase!=NIL) {
    free((char *)synbase);
    synbase = NIL;
    synnombre = synmax = 0;
  }
#ifdef ITERATIVE
  if (weightbase!=NIL) {
    weightbase = NIL;
    weightnombre = weightmax = 0;
  }
  if (w_matrix != NIL) {
    unprotect(w_matrix);
    if (w_matrix_var)
      var_SET(w_matrix_var,NIL);
  }
#endif
  if (neuraddress!=NIL)
    free((char *)neuraddress);
  if (netconvert != NIL)
    free((char *)netconvert);
}
예제 #2
0
파일: dump.c 프로젝트: barak/lush
void undump(char *s)
{
   at *atf = OPEN_READ(s,0);
   FILE *f = Gptr(atf);

   int magic = readmagic32(f);
   int version = read32(f);
   if ( magic != DUMPMAGIC )
      error(NIL, "incorrect dump file format", NIL);
   if ( version > DUMPVERSION )
      error(NIL, "dump file format version not supported", NIL);
   
   /* The macro character map */
   size_t sr = fread(char_map,1,256,f);
   if (sr < 256 || feof(f) || ferror(f))
      error(NIL, "corrupted dump file (1)",NIL);
   
   /* The unified list */
   at *val, *sym, *p = bread(f, NIL);
   while (CONSP(p)) {
      if (CONSP(Car(p))) {
         sym = Caar(p);
         val = Cdar(p);
         ifn (SYMBOLP(sym))
            error(NIL, "corrupted dump file (4)", NIL);
         var_SET(sym, val);
      } else if (SYMBOLP(Car(p)))
         var_lock(Car(p));
      val = p;
      p = Cdr(p);
      Cdr(val) = NIL;
   }
   /* define special symbols */
   at_NULL = var_get(named("NULL"));
}
예제 #3
0
static int 
netalloc(int n1, int n2)
#endif
{
  int c;
  neurone *n;
  typedef neurone *neuronePtr;
  
#ifdef ITERATIVE
  if (n3>n2)
    error(NIL,"you never need more weights than connections",NIL);
#endif
  zero_reseau();
  neurbase = (neurone *)malloc(n1 * sizeof(neurone));
  neurmax = n1;
  synbase = (synapse *)malloc(n2 * sizeof(synapse));
  synmax  = n2;
#ifdef ITERATIVE
  { 
    int dim[2];
    struct index *arr;
    dim[0] = n3;
    dim[1] = sizeof(weight) / sizeof(flt);
    w_matrix = F_matrix(2,dim);
    protect(w_matrix);
    UNLOCK(w_matrix);
    if (w_matrix_var)
      var_SET(w_matrix_var,w_matrix);
    arr = w_matrix->Object;
    weightbase = arr->st->srg.data;
    weightmax = n3;
  }
#endif
  neuraddress = (neurone **)malloc(n1 * sizeof( neuronePtr ));
  netconvert = (int *)malloc(n1 * sizeof(int));
  if ( neurbase==NIL || synbase==NIL || 
      neuraddress==NIL || netconvert ==NIL ) {
    zero_reseau();
    error(NIL,"not enough memory",NIL);
  };
  memset(neurbase, 0, n1*sizeof(neurone));
  memset(synbase, 0, n2*sizeof(synapse));
  neurnombre = 1;
  neurbase[0].Nval=fptoF(1.0);    /* neurone 0 = seuil */
  for (c=0, n=neurbase ; c<neurmax; c++, n++)
    neuraddress[c]=n;
  set_vars();
#ifdef ITERATIVE
  return ( n3*sizeof(weight) + n2*sizeof(synapse) + n1*sizeof(neurone) );
#else
  return ( n2*sizeof(synapse) + n1*sizeof(neurone) );
#endif
}
예제 #4
0
/* set_vars
   sets the lisp variables
   Nnum,Snum,Wnum,Nmax,Smax,Nmax
*/
void 
set_vars(void)
{
  at *p;
  
  p = NEW_NUMBER(neurnombre);
  var_SET(var_Nnum,p);
  UNLOCK(p);
  p = NEW_NUMBER(synnombre);
  var_SET(var_Snum,p);
  UNLOCK(p);
  p = NEW_NUMBER(neurmax);
  var_SET(var_Nmax,p);
  UNLOCK(p);
  p = NEW_NUMBER(synmax);
  var_SET(var_Smax,p);
  UNLOCK(p);
#ifdef ITERATIVE
  p = NEW_NUMBER(weightnombre);
  var_SET(var_Wnum,p);
  UNLOCK(p);
  p = NEW_NUMBER(weightmax);
  var_SET(var_Wmax,p);
  UNLOCK(p);
#endif
}