markh@csd4.milw.wisc.edu (Mark William Hopkins) (02/18/88)
>From wyle@solaris.ifi.ethz.ch@relay.cs.net (Mitchell Wyle) > >Subject: Neural-network simulator "Brain" >Keywords: modula-2, connectionist, neural networks, brain, simulator >Date: 26 Jan 88 10:50:59 GMT >Organization: SOT sun cluster, ETH Zuerich > >This is a neural networks simulator in Modula-2. It runs on all >versions of the Sun Modula-2 compiler, but I haven't tried to port >it anywhere else. ... ... >Enjoy, and please send comments, corrections, flames, etc to: > >wyle@ethz.uucp (or faster:) wyle%ifi.ethz.ch@relay.cs.net There were a lot of hand-coded loops in TestParser. I offer a more compact version that does the same thing: IMPORTS are all the same ... VAR declarations remain the same except for the addition of Accum : CARDINAL; The two WHILE loops for converting back and forth between bit strings and ascii code can probably be joined into one, with a FOR k := 1 to 2 loop. BEGIN Open (source, 'Brain.txt', textMode, readOnly, state); Open (test , 'Brain.tst', textMode, readOnly, state); Create (log , 'Brain.log', textMode, replace , state); Open (log , 'Brain.log', textMode, readWrite, state); Create (out , 'Brain.out', textMode, replace , state); Open (out , 'Brain.out', textMode, readWrite, state); InitParser (source, log); Parse; CloseParser; Activity (500,500); ReadString (test, I, state); ReadLn (test, state); WriteString (log, I, state); WriteLn (log, state); WHILE (I[0] <> '.') DO FOR i := 0 TO 8 DO Accum := ORD(I[i]); I[i] := 0C; FOR j := 7 TO 0 BY (-1) DO Ib[i*8 + j] := 800*(Accum MOD 2); (*** Convert I ***) Accum := Accum DIV 2 (*** to a binary word Ib ***) END END Input (Ib, 72); Tick; Output (Ob, 48); FOR i := 0 TO 5 DO Accum := 0; FOR j := 7 TO 0 BY (-1) DO Accum := Accum * 2; IF Ob[i*8 + j] > 0 THEN Accum := Accum + 1; WriteChar(log,'1',state) (*** Convert binary word Ob ***) ELSE (*** to a character O ***) WriteChar(log,'0',state) END; END; IF NOT(Accum IN {ORD('A')..ORD('Z')}) THEN O[i] := '.' ELSE O[i] := CHR(Accum) END; WriteChar (log,',', state) END; WriteChar (log,' ', state); FOR i := 0 TO 5 DO WriteChar (log, O[i], state) END; WriteLn (log, state); ReadString(test, I, state); ReadLn(test,state); WriteString(log, I, state); WriteLn(log, state) END; teaching := FALSE; WriteLn (log, state); WriteLn (log, state); ReadString (test, I, state); ReadLn (test, state); WriteString (log, I, state); WriteLn (log, state); WHILE (I[0] <> '.') DO FOR i := 0 TO 2 DO Accum := ORD(I[i]); I[i] := 0C; FOR j := 7 TO 0 BY (-1) DO Ib[i*i + j] := 800*(Accum MOD 2); Accum := Accum DIV 2 END END; FOR i := 3 TO 8 DO I[i] := 0C; FOR j := 0 TO 7 DO Ib[i*8 + j] := 0 END END; Input (Ib, 72); Tick; Output (Ob, 48); FOR i := 0 TO 5 DO Accum := 0; FOR j := 7 TO 0 BY (-1) DO Accum := Accum * 2; IF Ob[i*8 + j] > 0 THEN Accum := Accum + 1; WriteChar(log,'1',state) ELSE WriteChar(log,'0',state) END; END; IF NOT( Accum IN {ORD('A')..ORD('Z')} ) THEN O[i] := '.' ELSE O[i] := CHR(Accum) END; WriteChar (log,',', state) END; WriteChar (log,' ', state); FOR i := 0 TO 5 DO WriteChar (log, O[i], state) END; WriteLn (log, state) ReadString(test, I, state); ReadLn(test, state); WriteString(log, I, state); WriteLn(log, state) END; Save(out); Close(source, state); Close(test , state); Close(log , state); Close(out , state) END TestParser. SHAR_EOF fi
markh@csd4.milw.wisc.edu (Mark William Hopkins) (02/26/88)
>From wyle@solaris.ifi.ethz.ch@relay.cs.net (Mitchell Wyle) > >Subject: Neural-network simulator "Brain" >Keywords: modula-2, connectionist, neural networks, brain, simulator >Date: 26 Jan 88 10:50:59 GMT >Organization: SOT sun cluster, ETH Zuerich > More comments: Where is the program module?