Home » Archimedes archive » Archimedes World » archimedes_world_volume_14_issue_12_scp.adf » !AcornAns_AcornAns » Box1

Box1

This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.

Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.

Tape/disk: Home » Archimedes archive » Archimedes World » archimedes_world_volume_14_issue_12_scp.adf » !AcornAns_AcornAns
Filename: Box1
Read OK:
File size: 08D6 bytes
Load address: 0000
Exec address: 0000
File contents
Data structures                 General
===============                 =======
typedef struct {                general parameters determining size of neural net and nature of training,
  unit error_threshold;         used by many functions
  int  start_iter;
  int  no_of_inputs,
       no_of_h1_nodes,
       no_of_outputs;
  BOOL sigmoid_out;
  unit alpha,
       learning_rate,
       norm_in_min,
       norm_in_range;
} ff_setup_rec;
                                we will use a 16 bit fixed point format for all our net data,
typedef int unit;               where an int i represents value i/65536
typedef unit *vector;           ptr to a dynamically allocated array of units
typedef vector *weights;        ptr to a dynamic array of vectors, giving a dynamic two dimensional array

                                our neural net is stored in two parts � the collection of network nodes
                                & the collection of weights between nodes:

typedef struct {                the network structure � essentially just three arrays comprising
  BOOL allocated;               the input, output and hidden layer nodes
  vector x_inp, y_out;
  vector h1;
  int si, so, sh;               a record of the size of each of the three vectors
} network_rec;

typedef struct {                the weights structure � two dynamic two dimensional arrays of weight data
  BOOL allocated;               wi pointing to input weights, those between input and hidden layer nodes
  weights wi, wo;               wo pointing to output weights, those between hidden layer and output nodes
  int si, so, sh;               wi has si*sh elements, wo has sh*so elements
} weights_rec;

typedef struct {                a record of network performance kept during network training
  int high_water, count_max,
       last_right, last_wrong,
       right_count, wrong_count,
       nbr_tr_items;
  int iter;
} display_rec;


                                Brolly specific
                                ===============
typedef struct {                in our brolly example, the following data, as well as force
  unit x_pos,                   applied to brolly, comprise our five items of network input
       x_dot,
       theta,
       theta_dot;
} state_rec;

00000000  44 61 74 61 20 73 74 72  75 63 74 75 72 65 73 20  |Data structures |
00000010  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000020  47 65 6e 65 72 61 6c 0a  3d 3d 3d 3d 3d 3d 3d 3d  |General.========|
00000030  3d 3d 3d 3d 3d 3d 3d 20  20 20 20 20 20 20 20 20  |=======         |
00000040  20 20 20 20 20 20 20 20  3d 3d 3d 3d 3d 3d 3d 0a  |        =======.|
00000050  74 79 70 65 64 65 66 20  73 74 72 75 63 74 20 7b  |typedef struct {|
00000060  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000070  67 65 6e 65 72 61 6c 20  70 61 72 61 6d 65 74 65  |general paramete|
00000080  72 73 20 64 65 74 65 72  6d 69 6e 69 6e 67 20 73  |rs determining s|
00000090  69 7a 65 20 6f 66 20 6e  65 75 72 61 6c 20 6e 65  |ize of neural ne|
000000a0  74 20 61 6e 64 20 6e 61  74 75 72 65 20 6f 66 20  |t and nature of |
000000b0  74 72 61 69 6e 69 6e 67  2c 0a 20 20 75 6e 69 74  |training,.  unit|
000000c0  20 65 72 72 6f 72 5f 74  68 72 65 73 68 6f 6c 64  | error_threshold|
000000d0  3b 20 20 20 20 20 20 20  20 20 75 73 65 64 20 62  |;         used b|
000000e0  79 20 6d 61 6e 79 20 66  75 6e 63 74 69 6f 6e 73  |y many functions|
000000f0  0a 20 20 69 6e 74 20 20  73 74 61 72 74 5f 69 74  |.  int  start_it|
00000100  65 72 3b 0a 20 20 69 6e  74 20 20 6e 6f 5f 6f 66  |er;.  int  no_of|
00000110  5f 69 6e 70 75 74 73 2c  0a 20 20 20 20 20 20 20  |_inputs,.       |
00000120  6e 6f 5f 6f 66 5f 68 31  5f 6e 6f 64 65 73 2c 0a  |no_of_h1_nodes,.|
00000130  20 20 20 20 20 20 20 6e  6f 5f 6f 66 5f 6f 75 74  |       no_of_out|
00000140  70 75 74 73 3b 0a 20 20  42 4f 4f 4c 20 73 69 67  |puts;.  BOOL sig|
00000150  6d 6f 69 64 5f 6f 75 74  3b 0a 20 20 75 6e 69 74  |moid_out;.  unit|
00000160  20 61 6c 70 68 61 2c 0a  20 20 20 20 20 20 20 6c  | alpha,.       l|
00000170  65 61 72 6e 69 6e 67 5f  72 61 74 65 2c 0a 20 20  |earning_rate,.  |
00000180  20 20 20 20 20 6e 6f 72  6d 5f 69 6e 5f 6d 69 6e  |     norm_in_min|
00000190  2c 0a 20 20 20 20 20 20  20 6e 6f 72 6d 5f 69 6e  |,.       norm_in|
000001a0  5f 72 61 6e 67 65 3b 0a  7d 20 66 66 5f 73 65 74  |_range;.} ff_set|
000001b0  75 70 5f 72 65 63 3b 0a  20 20 20 20 20 20 20 20  |up_rec;.        |
000001c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000001d0  20 20 20 20 20 20 20 20  77 65 20 77 69 6c 6c 20  |        we will |
000001e0  75 73 65 20 61 20 31 36  20 62 69 74 20 66 69 78  |use a 16 bit fix|
000001f0  65 64 20 70 6f 69 6e 74  20 66 6f 72 6d 61 74 20  |ed point format |
00000200  66 6f 72 20 61 6c 6c 20  6f 75 72 20 6e 65 74 20  |for all our net |
00000210  64 61 74 61 2c 0a 74 79  70 65 64 65 66 20 69 6e  |data,.typedef in|
00000220  74 20 75 6e 69 74 3b 20  20 20 20 20 20 20 20 20  |t unit;         |
00000230  20 20 20 20 20 20 77 68  65 72 65 20 61 6e 20 69  |      where an i|
00000240  6e 74 20 69 20 72 65 70  72 65 73 65 6e 74 73 20  |nt i represents |
00000250  76 61 6c 75 65 20 69 2f  36 35 35 33 36 0a 74 79  |value i/65536.ty|
00000260  70 65 64 65 66 20 75 6e  69 74 20 2a 76 65 63 74  |pedef unit *vect|
00000270  6f 72 3b 20 20 20 20 20  20 20 20 20 20 20 70 74  |or;           pt|
00000280  72 20 74 6f 20 61 20 64  79 6e 61 6d 69 63 61 6c  |r to a dynamical|
00000290  6c 79 20 61 6c 6c 6f 63  61 74 65 64 20 61 72 72  |ly allocated arr|
000002a0  61 79 20 6f 66 20 75 6e  69 74 73 0a 74 79 70 65  |ay of units.type|
000002b0  64 65 66 20 76 65 63 74  6f 72 20 2a 77 65 69 67  |def vector *weig|
000002c0  68 74 73 3b 20 20 20 20  20 20 20 20 70 74 72 20  |hts;        ptr |
000002d0  74 6f 20 61 20 64 79 6e  61 6d 69 63 20 61 72 72  |to a dynamic arr|
000002e0  61 79 20 6f 66 20 76 65  63 74 6f 72 73 2c 20 67  |ay of vectors, g|
000002f0  69 76 69 6e 67 20 61 20  64 79 6e 61 6d 69 63 20  |iving a dynamic |
00000300  74 77 6f 20 64 69 6d 65  6e 73 69 6f 6e 61 6c 20  |two dimensional |
00000310  61 72 72 61 79 0a 0a 20  20 20 20 20 20 20 20 20  |array..         |
00000320  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000330  20 20 20 20 20 20 20 6f  75 72 20 6e 65 75 72 61  |       our neura|
00000340  6c 20 6e 65 74 20 69 73  20 73 74 6f 72 65 64 20  |l net is stored |
00000350  69 6e 20 74 77 6f 20 70  61 72 74 73 20 99 20 74  |in two parts . t|
00000360  68 65 20 63 6f 6c 6c 65  63 74 69 6f 6e 20 6f 66  |he collection of|
00000370  20 6e 65 74 77 6f 72 6b  20 6e 6f 64 65 73 0a 20  | network nodes. |
00000380  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
00000390  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 26  |               &|
000003a0  20 74 68 65 20 63 6f 6c  6c 65 63 74 69 6f 6e 20  | the collection |
000003b0  6f 66 20 77 65 69 67 68  74 73 20 62 65 74 77 65  |of weights betwe|
000003c0  65 6e 20 6e 6f 64 65 73  3a 0a 0a 74 79 70 65 64  |en nodes:..typed|
000003d0  65 66 20 73 74 72 75 63  74 20 7b 20 20 20 20 20  |ef struct {     |
000003e0  20 20 20 20 20 20 20 20  20 20 20 74 68 65 20 6e  |           the n|
000003f0  65 74 77 6f 72 6b 20 73  74 72 75 63 74 75 72 65  |etwork structure|
00000400  20 99 20 65 73 73 65 6e  74 69 61 6c 6c 79 20 6a  | . essentially j|
00000410  75 73 74 20 74 68 72 65  65 20 61 72 72 61 79 73  |ust three arrays|
00000420  20 63 6f 6d 70 72 69 73  69 6e 67 0a 20 20 42 4f  | comprising.  BO|
00000430  4f 4c 20 61 6c 6c 6f 63  61 74 65 64 3b 20 20 20  |OL allocated;   |
00000440  20 20 20 20 20 20 20 20  20 20 20 20 74 68 65 20  |            the |
00000450  69 6e 70 75 74 2c 20 6f  75 74 70 75 74 20 61 6e  |input, output an|
00000460  64 20 68 69 64 64 65 6e  20 6c 61 79 65 72 20 6e  |d hidden layer n|
00000470  6f 64 65 73 0a 20 20 76  65 63 74 6f 72 20 78 5f  |odes.  vector x_|
00000480  69 6e 70 2c 20 79 5f 6f  75 74 3b 0a 20 20 76 65  |inp, y_out;.  ve|
00000490  63 74 6f 72 20 68 31 3b  0a 20 20 69 6e 74 20 73  |ctor h1;.  int s|
000004a0  69 2c 20 73 6f 2c 20 73  68 3b 20 20 20 20 20 20  |i, so, sh;      |
000004b0  20 20 20 20 20 20 20 20  20 61 20 72 65 63 6f 72  |         a recor|
000004c0  64 20 6f 66 20 74 68 65  20 73 69 7a 65 20 6f 66  |d of the size of|
000004d0  20 65 61 63 68 20 6f 66  20 74 68 65 20 74 68 72  | each of the thr|
000004e0  65 65 20 76 65 63 74 6f  72 73 0a 7d 20 6e 65 74  |ee vectors.} net|
000004f0  77 6f 72 6b 5f 72 65 63  3b 0a 0a 74 79 70 65 64  |work_rec;..typed|
00000500  65 66 20 73 74 72 75 63  74 20 7b 20 20 20 20 20  |ef struct {     |
00000510  20 20 20 20 20 20 20 20  20 20 20 74 68 65 20 77  |           the w|
00000520  65 69 67 68 74 73 20 73  74 72 75 63 74 75 72 65  |eights structure|
00000530  20 99 20 74 77 6f 20 64  79 6e 61 6d 69 63 20 74  | . two dynamic t|
00000540  77 6f 20 64 69 6d 65 6e  73 69 6f 6e 61 6c 20 61  |wo dimensional a|
00000550  72 72 61 79 73 20 6f 66  20 77 65 69 67 68 74 20  |rrays of weight |
00000560  64 61 74 61 0a 20 20 42  4f 4f 4c 20 61 6c 6c 6f  |data.  BOOL allo|
00000570  63 61 74 65 64 3b 20 20  20 20 20 20 20 20 20 20  |cated;          |
00000580  20 20 20 20 20 77 69 20  70 6f 69 6e 74 69 6e 67  |     wi pointing|
00000590  20 74 6f 20 69 6e 70 75  74 20 77 65 69 67 68 74  | to input weight|
000005a0  73 2c 20 74 68 6f 73 65  20 62 65 74 77 65 65 6e  |s, those between|
000005b0  20 69 6e 70 75 74 20 61  6e 64 20 68 69 64 64 65  | input and hidde|
000005c0  6e 20 6c 61 79 65 72 20  6e 6f 64 65 73 0a 20 20  |n layer nodes.  |
000005d0  77 65 69 67 68 74 73 20  77 69 2c 20 77 6f 3b 20  |weights wi, wo; |
000005e0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 77 6f  |              wo|
000005f0  20 70 6f 69 6e 74 69 6e  67 20 74 6f 20 6f 75 74  | pointing to out|
00000600  70 75 74 20 77 65 69 67  68 74 73 2c 20 74 68 6f  |put weights, tho|
00000610  73 65 20 62 65 74 77 65  65 6e 20 68 69 64 64 65  |se between hidde|
00000620  6e 20 6c 61 79 65 72 20  61 6e 64 20 6f 75 74 70  |n layer and outp|
00000630  75 74 20 6e 6f 64 65 73  0a 20 20 69 6e 74 20 73  |ut nodes.  int s|
00000640  69 2c 20 73 6f 2c 20 73  68 3b 20 20 20 20 20 20  |i, so, sh;      |
00000650  20 20 20 20 20 20 20 20  20 77 69 20 68 61 73 20  |         wi has |
00000660  73 69 2a 73 68 20 65 6c  65 6d 65 6e 74 73 2c 20  |si*sh elements, |
00000670  77 6f 20 68 61 73 20 73  68 2a 73 6f 20 65 6c 65  |wo has sh*so ele|
00000680  6d 65 6e 74 73 0a 7d 20  77 65 69 67 68 74 73 5f  |ments.} weights_|
00000690  72 65 63 3b 0a 0a 74 79  70 65 64 65 66 20 73 74  |rec;..typedef st|
000006a0  72 75 63 74 20 7b 20 20  20 20 20 20 20 20 20 20  |ruct {          |
000006b0  20 20 20 20 20 20 61 20  72 65 63 6f 72 64 20 6f  |      a record o|
000006c0  66 20 6e 65 74 77 6f 72  6b 20 70 65 72 66 6f 72  |f network perfor|
000006d0  6d 61 6e 63 65 20 6b 65  70 74 20 64 75 72 69 6e  |mance kept durin|
000006e0  67 20 6e 65 74 77 6f 72  6b 20 74 72 61 69 6e 69  |g network traini|
000006f0  6e 67 0a 20 20 69 6e 74  20 68 69 67 68 5f 77 61  |ng.  int high_wa|
00000700  74 65 72 2c 20 63 6f 75  6e 74 5f 6d 61 78 2c 0a  |ter, count_max,.|
00000710  20 20 20 20 20 20 20 6c  61 73 74 5f 72 69 67 68  |       last_righ|
00000720  74 2c 20 6c 61 73 74 5f  77 72 6f 6e 67 2c 0a 20  |t, last_wrong,. |
00000730  20 20 20 20 20 20 72 69  67 68 74 5f 63 6f 75 6e  |      right_coun|
00000740  74 2c 20 77 72 6f 6e 67  5f 63 6f 75 6e 74 2c 0a  |t, wrong_count,.|
00000750  20 20 20 20 20 20 20 6e  62 72 5f 74 72 5f 69 74  |       nbr_tr_it|
00000760  65 6d 73 3b 0a 20 20 69  6e 74 20 69 74 65 72 3b  |ems;.  int iter;|
00000770  0a 7d 20 64 69 73 70 6c  61 79 5f 72 65 63 3b 0a  |.} display_rec;.|
00000780  0a 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |..              |
00000790  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000007a0  20 20 42 72 6f 6c 6c 79  20 73 70 65 63 69 66 69  |  Brolly specifi|
000007b0  63 0a 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |c.              |
000007c0  20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
000007d0  20 20 3d 3d 3d 3d 3d 3d  3d 3d 3d 3d 3d 3d 3d 3d  |  ==============|
000007e0  3d 0a 74 79 70 65 64 65  66 20 73 74 72 75 63 74  |=.typedef struct|
000007f0  20 7b 20 20 20 20 20 20  20 20 20 20 20 20 20 20  | {              |
00000800  20 20 69 6e 20 6f 75 72  20 62 72 6f 6c 6c 79 20  |  in our brolly |
00000810  65 78 61 6d 70 6c 65 2c  20 74 68 65 20 66 6f 6c  |example, the fol|
00000820  6c 6f 77 69 6e 67 20 64  61 74 61 2c 20 61 73 20  |lowing data, as |
00000830  77 65 6c 6c 20 61 73 20  66 6f 72 63 65 0a 20 20  |well as force.  |
00000840  75 6e 69 74 20 78 5f 70  6f 73 2c 20 20 20 20 20  |unit x_pos,     |
00000850  20 20 20 20 20 20 20 20  20 20 20 20 20 20 61 70  |              ap|
00000860  70 6c 69 65 64 20 74 6f  20 62 72 6f 6c 6c 79 2c  |plied to brolly,|
00000870  20 63 6f 6d 70 72 69 73  65 20 6f 75 72 20 66 69  | comprise our fi|
00000880  76 65 20 69 74 65 6d 73  20 6f 66 20 6e 65 74 77  |ve items of netw|
00000890  6f 72 6b 20 69 6e 70 75  74 0a 20 20 20 20 20 20  |ork input.      |
000008a0  20 78 5f 64 6f 74 2c 0a  20 20 20 20 20 20 20 74  | x_dot,.       t|
000008b0  68 65 74 61 2c 0a 20 20  20 20 20 20 20 74 68 65  |heta,.       the|
000008c0  74 61 5f 64 6f 74 3b 0a  7d 20 73 74 61 74 65 5f  |ta_dot;.} state_|
000008d0  72 65 63 3b 0a 0a                                 |rec;..|
000008d6