BOOL NNLayer::load_model (FILE *f) {
    assert(f != NULL);
    free_space();

    ignore_comment(f);
    if (fscanf(f, "%u %u %lf %lf\n",
               &n_input, &n_neuron, &winit_min, &winit_max) != 4)
        return FALSE;
    if (winit_min >= winit_max) return FALSE;

    if (n_input <= 0 || n_neuron <= 0)
        return FALSE;

    alloc_space();

    for (size_t i = 0; i < n_neuron; i++)
        for (size_t j = 0; j <= n_input; j++)
            if (fscanf(f, "%lf", &weight[i][j]) != 1)
                return FALSE;
    return TRUE;
}
Ejemplo n.º 2
0
PRIVATE char *get_array1(int *arr, int size)
{
  int    i, p, pos, pp, r, last;
  char  *line, buf[16];


  i = last = 0;
  while( i<size ) {
    line = get_line(fp);
    if (!line) vrna_message_error("unexpected end of file in get_array1");
    ignore_comment(line);
    pos=0;
    while ((i<size)&&(sscanf(line+pos,"%15s%n", buf, &pp)==1)) {
      pos += pp;
      if (buf[0]=='*') {i++; continue;}
      else if (buf[0]=='x') { /* should only be used for loop parameters */
        if (i==0) vrna_message_error("can't extrapolate first value");
        p = arr[last] + (int) (0.5+ lxc37*log(((double) i)/(double)(last)));
      }
      else if (strcmp(buf,"DEF") == 0) p = DEF;
      else if (strcmp(buf,"INF") == 0) p = INF;
      else if (strcmp(buf,"NST") == 0) p = NST;
      else {
        r=sscanf(buf,"%d", &p);
        if (r!=1) {
          return line+pos;
          fprintf(stderr, "can't interpret `%s' in get_array1\n", buf);
          exit(1);
        }
        last = i;
      }
      arr[i++]=p;
    }
    free(line);
  }

  return NULL;
}