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