home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / SNNSV32.ZIP / SNNSv3.2 / tools / sources / feedback-gennet.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-25  |  5.8 KB  |  173 lines

  1. /*****************************************************************************
  2.   FILE           : feedback-gennet.c
  3.   SHORTNAME      : feedback-gennet.c
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : Generate a SNNS network file for fully recurrent networks
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Martin Reczko 
  10.   DATE           : 1.3.93
  11.   VERSION        : 1.0                                         
  12.  
  13.   CHANGED BY     : 
  14.   IDENTIFICATION : @(#)feedback-gennet.c    1.3 2/28/94
  15.   SCCS VERSION   : 1.3
  16.   LAST CHANGE    : 2/28/94
  17.  
  18.  
  19.           This part is Copyright 1992,93 by Martin Reczko, DKFZ Heidelberg
  20.  
  21.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  22.  
  23. ******************************************************************************/
  24.  
  25. /*
  26.   Generate a SNNS network file for fully recurrent networks.
  27.   The network has the following structure:
  28.     - input layer with no intra layer connections
  29.     - fully recurrent hidden layer
  30.     - output layer: connections from each hidden unit to each output unit AND
  31.      OPTIONALLY fully recurrent intra layer connections in the output layer AND
  32.      OPTIONALLY feedback connections from each output unit to each hidden unit
  33.   The activation function of the output units can be set to
  34.   sigmoidal or linear. All weights are initialized with 0.0 .
  35.   Other initializations should be performed by the init functions in SNNS.
  36. */
  37. #include <ctype.h>
  38. #include <stdio.h>
  39. #include <string.h>
  40. #include <stdlib.h>
  41.  
  42. FILE *in,*out;
  43. float amplitude;
  44.  
  45. double drand48()
  46. {
  47.  return 0.0;
  48. }
  49.  
  50. void main ()
  51. {
  52.  int i,j,k;
  53.  int nin,nhid,nout,nconnections;
  54.  char netname[1024];
  55.  char in2out,out2out,linout,out2hid;
  56.  int last_output_source;
  57.  
  58.  printf("Enter # input units:");
  59.  scanf("%d",&nin);
  60.  printf("Enter # hidden units:");
  61.  scanf("%d",&nhid);
  62.  printf("Enter # output units:");
  63.  scanf("%d",&nout);
  64.  printf("INTRA layer connections in the output layer (y/n):");
  65.  scanf("\n%c",&out2out);
  66.  printf("feedback connections from output to hidden units (y/n):"),
  67.  scanf("\n%c",&out2hid);
  68.  printf("Linear output activation function (y/n):");
  69.  scanf("\n%c",&linout);
  70.  printf("Enter name of network file:");
  71.  scanf("\n%s",netname);
  72.  
  73.  printf("working...");
  74.  if (out2out=='y') {
  75.    last_output_source=nout;
  76.    if (out2hid=='y')
  77.      nconnections = nhid *(nin+nhid+nout);
  78.    else
  79.      nconnections = nhid *(nin+nhid);
  80.     nconnections += nout *(nhid+nout);
  81.  } else {
  82.    last_output_source=0;
  83.    if (out2hid=='y')
  84.      nconnections = nhid *(nin+nhid+nout);
  85.    else
  86.      nconnections = nhid *(nin+nhid);
  87.    nconnections += nout * nhid;
  88.  }
  89.  if ((out = fopen(netname, "w")) ==  NULL)
  90.    {  
  91.      fprintf (stderr, "error:  can't create file %s\n", netname) ;
  92.      exit(0);
  93.    } 
  94.  
  95.  fprintf(out,"SNNS network definition file V1.4-3D\n");
  96.  fprintf(out,"generated at Sat Jan 23 16:55:30 1992\n");
  97.  fprintf(out,"\n");
  98.  fprintf(out,"network name : rec-gennet\n");
  99.  fprintf(out,"source files :\n");
  100.  fprintf(out,"no. of units : %d\n",nin+nhid+nout);
  101.  fprintf(out,"no. of connections : %d\n",nconnections);
  102.  fprintf(out,"no. of unit types : 0\n");
  103.  fprintf(out,"no. of site types : 0\n");
  104.  fprintf(out,"\n");
  105.  fprintf(out,"learning function : QPTT\n");
  106.  fprintf(out,"update function   : BPTT_Order\n");
  107.  fprintf(out,"\n");
  108.  fprintf(out,"unit default section :\n");
  109.  fprintf(out,"\n");
  110.  fprintf(out,"---------|----------|----|--------|-------|--------------|-------------\n");
  111.  fprintf(out," 0.00000 |  0.00000 | h  |      0 |     1 | Act_Logistic | Out_Identity \n");
  112.  fprintf(out,"---------|----------|----|--------|-------|--------------|-------------\n");
  113.  fprintf(out,"\n");
  114.  fprintf(out,"unit definition section :\n");
  115.  fprintf(out,"\n");
  116.  fprintf(out,"----|----------|----------|----------|----------|----|----------|--------------|--------------|-------\n");
  117.  
  118.  for (i=1;i<=nin;i++) fprintf(out,
  119. "%4d|          |          |  0.00000 |  0.00000 | i  | %2d, 1, 2 |              |              | \n",i,i);
  120.  for (i=1;i<=nhid;i++) fprintf(out,
  121. "%4d|          |          |  0.00000 |  0.00000 | h  | %2d, 2, 2 |              |              | \n",i+nin,i);
  122.  for (i=1;i<=nout;i++) if (linout=='y') fprintf(out,
  123. "%4d|          |          |  0.00000 |  0.00000 | o  | %2d, 3, 2 | Act_Identity |              | \n",i+nin+nhid,i); else fprintf(out,
  124. "%4d|          |          |  0.00000 |  0.00000 | o  | %2d, 3, 2 |              |              | \n",i+nin+nhid,i);
  125.  fprintf(out,
  126. "----|----------|----------|----------|----------|----|----------|--------------|--------------|-------\n\n");
  127.  fprintf(out,"connection definition section :\n\n");
  128.  fprintf(out,"target | site | source:weight\n");
  129.  fprintf(out,
  130. "-------|------|----------------------------------------------------------------------------------------------------------------\n");
  131.   if (out2hid=='y')
  132.   for (j=1;j<=nhid;j++){
  133.    for (i=1;i<=(nin+nhid+nout);i++) {
  134.      if (i==1)
  135.        fprintf(out,"  %4d |      |",j+nin);
  136.      else
  137.        if ( ( (i-1) % 8) == 0) fprintf(out,"\n               ");
  138.      fprintf(out," %3d:%8.5f",i,drand48());
  139.      if (i < (nin+nhid+nout)) fprintf(out,",");
  140.    }
  141.    fprintf(out,"\n");
  142.  }
  143.  else
  144.  for (j=1;j<=nhid;j++){
  145.    for (i=1;i<=(nin+nhid);i++) {
  146.      if (i==1)
  147.        fprintf(out,"  %4d |      |",j+nin);
  148.      else
  149.        if ( ( (i-1) % 8) == 0) fprintf(out,"\n               ");
  150.      fprintf(out," %3d:%8.5f",i,drand48());
  151.      if (i < (nin+nhid)) fprintf(out,",");
  152.    }
  153.    fprintf(out,"\n");
  154.  }
  155.  
  156.  for (j=1;j<=nout;j++){
  157.    for (i=1;i<=(nhid+last_output_source);i++) {
  158.      if (i==1)
  159.        fprintf(out,"  %4d |      |",j+nin+nhid);
  160.      else
  161.        if ( ( (i-1) % 8) == 0) fprintf(out,"\n               ");
  162.      fprintf(out," %3d:%8.5f",i+nin,drand48());
  163.      if (i < (nhid+last_output_source)) fprintf(out,",");
  164.    }
  165.    fprintf(out,"\n");
  166.  }
  167.  fprintf(out,
  168. "-------|------|----------------------------------------------------------------------------------------------------------------\n");
  169.  fclose(out);
  170.  printf("\ngenerated %s\n",netname);
  171. }
  172.  
  173.