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

Box2

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: Box2
Read OK:
File size: 08C3 bytes
Load address: 0000
Exec address: 0000
File contents
User functions
==============
This group of functions will need to be heavily modified to suit your application.
The first two functions should be called during your initialisation routine.

BOOL network_initialise_parameters(void)
initialises a global ff_setup_rec

BOOL create_max_min_data(void)
establishes range that data can take in your state_rec, so that . . .

void get_network_input(state_rec *s, vector x_in, unit force, ff_setup_rec *setup)
. . . can transform the state of your system into normalised net input � nb in more general applications
the force argument wouldn�t be present �  as used by . . .

void get_network_input_output(vector x_in, vector desired_out, ff_setup_rec *setup)
. . . a function, called by backpropagation_training, to supply a training input/output vector pair.
It must read from file, or create by simulation, raw data for your system (both sample input & desired output),
& normalise this, passing results back via vectors x_in & desired_out. This function is of type get_data_proc,
where we have:

typedef void (*get_data_proc) (vector x_in, vector desired_out, ff_setup_rec *setup);



General network creation/training functions
===========================================
network_rec *allocate_network(network_rec *network, ff_setup_rec *setup)
allocate network nodes storage, network size specified within ff_setup_rec

void free_network(network_rec *network)
free up network node storage

weights_rec *initialise_weights(weights_rec *w, BOOL random_init, ff_setup_rec *setup)
creates storage for (if necessary) and initialises weights � random_init should always be TRUE (false is for internal purposes)

void free_network_weights(weights_rec *w)
discards the weight arrays

BOOL feedforward(network_rec *n, weights_rec *w, ff_setup_rec *s)
used to generate net output, via weights and net input, both at final run-time of a trained net and during training

BOOL backpropagation_training(network_rec *net, weights_rec *wts, int no_of_training_items, 
get_data_proc get_network_input_output, BOOL verbose, ff_setup_rec *setup)
the backbone of any net application � it takes an initialised random (or partially trained) weights_rec, & trains it, providing graphical feedback of training progress

00000000  55 73 65 72 20 66 75 6e  63 74 69 6f 6e 73 0a 3d  |User functions.=|
00000010  3d 3d 3d 3d 3d 3d 3d 3d  3d 3d 3d 3d 3d 0a 54 68  |=============.Th|
00000020  69 73 20 67 72 6f 75 70  20 6f 66 20 66 75 6e 63  |is group of func|
00000030  74 69 6f 6e 73 20 77 69  6c 6c 20 6e 65 65 64 20  |tions will need |
00000040  74 6f 20 62 65 20 68 65  61 76 69 6c 79 20 6d 6f  |to be heavily mo|
00000050  64 69 66 69 65 64 20 74  6f 20 73 75 69 74 20 79  |dified to suit y|
00000060  6f 75 72 20 61 70 70 6c  69 63 61 74 69 6f 6e 2e  |our application.|
00000070  0a 54 68 65 20 66 69 72  73 74 20 74 77 6f 20 66  |.The first two f|
00000080  75 6e 63 74 69 6f 6e 73  20 73 68 6f 75 6c 64 20  |unctions should |
00000090  62 65 20 63 61 6c 6c 65  64 20 64 75 72 69 6e 67  |be called during|
000000a0  20 79 6f 75 72 20 69 6e  69 74 69 61 6c 69 73 61  | your initialisa|
000000b0  74 69 6f 6e 20 72 6f 75  74 69 6e 65 2e 0a 0a 42  |tion routine...B|
000000c0  4f 4f 4c 20 6e 65 74 77  6f 72 6b 5f 69 6e 69 74  |OOL network_init|
000000d0  69 61 6c 69 73 65 5f 70  61 72 61 6d 65 74 65 72  |ialise_parameter|
000000e0  73 28 76 6f 69 64 29 0a  69 6e 69 74 69 61 6c 69  |s(void).initiali|
000000f0  73 65 73 20 61 20 67 6c  6f 62 61 6c 20 66 66 5f  |ses a global ff_|
00000100  73 65 74 75 70 5f 72 65  63 0a 0a 42 4f 4f 4c 20  |setup_rec..BOOL |
00000110  63 72 65 61 74 65 5f 6d  61 78 5f 6d 69 6e 5f 64  |create_max_min_d|
00000120  61 74 61 28 76 6f 69 64  29 0a 65 73 74 61 62 6c  |ata(void).establ|
00000130  69 73 68 65 73 20 72 61  6e 67 65 20 74 68 61 74  |ishes range that|
00000140  20 64 61 74 61 20 63 61  6e 20 74 61 6b 65 20 69  | data can take i|
00000150  6e 20 79 6f 75 72 20 73  74 61 74 65 5f 72 65 63  |n your state_rec|
00000160  2c 20 73 6f 20 74 68 61  74 20 2e 20 2e 20 2e 0a  |, so that . . ..|
00000170  0a 76 6f 69 64 20 67 65  74 5f 6e 65 74 77 6f 72  |.void get_networ|
00000180  6b 5f 69 6e 70 75 74 28  73 74 61 74 65 5f 72 65  |k_input(state_re|
00000190  63 20 2a 73 2c 20 76 65  63 74 6f 72 20 78 5f 69  |c *s, vector x_i|
000001a0  6e 2c 20 75 6e 69 74 20  66 6f 72 63 65 2c 20 66  |n, unit force, f|
000001b0  66 5f 73 65 74 75 70 5f  72 65 63 20 2a 73 65 74  |f_setup_rec *set|
000001c0  75 70 29 0a 2e 20 2e 20  2e 20 63 61 6e 20 74 72  |up).. . . can tr|
000001d0  61 6e 73 66 6f 72 6d 20  74 68 65 20 73 74 61 74  |ansform the stat|
000001e0  65 20 6f 66 20 79 6f 75  72 20 73 79 73 74 65 6d  |e of your system|
000001f0  20 69 6e 74 6f 20 6e 6f  72 6d 61 6c 69 73 65 64  | into normalised|
00000200  20 6e 65 74 20 69 6e 70  75 74 20 99 20 6e 62 20  | net input . nb |
00000210  69 6e 20 6d 6f 72 65 20  67 65 6e 65 72 61 6c 20  |in more general |
00000220  61 70 70 6c 69 63 61 74  69 6f 6e 73 0a 74 68 65  |applications.the|
00000230  20 66 6f 72 63 65 20 61  72 67 75 6d 65 6e 74 20  | force argument |
00000240  77 6f 75 6c 64 6e 91 74  20 62 65 20 70 72 65 73  |wouldn.t be pres|
00000250  65 6e 74 20 99 20 20 61  73 20 75 73 65 64 20 62  |ent .  as used b|
00000260  79 20 2e 20 2e 20 2e 0a  0a 76 6f 69 64 20 67 65  |y . . ...void ge|
00000270  74 5f 6e 65 74 77 6f 72  6b 5f 69 6e 70 75 74 5f  |t_network_input_|
00000280  6f 75 74 70 75 74 28 76  65 63 74 6f 72 20 78 5f  |output(vector x_|
00000290  69 6e 2c 20 76 65 63 74  6f 72 20 64 65 73 69 72  |in, vector desir|
000002a0  65 64 5f 6f 75 74 2c 20  66 66 5f 73 65 74 75 70  |ed_out, ff_setup|
000002b0  5f 72 65 63 20 2a 73 65  74 75 70 29 0a 2e 20 2e  |_rec *setup).. .|
000002c0  20 2e 20 61 20 66 75 6e  63 74 69 6f 6e 2c 20 63  | . a function, c|
000002d0  61 6c 6c 65 64 20 62 79  20 62 61 63 6b 70 72 6f  |alled by backpro|
000002e0  70 61 67 61 74 69 6f 6e  5f 74 72 61 69 6e 69 6e  |pagation_trainin|
000002f0  67 2c 20 74 6f 20 73 75  70 70 6c 79 20 61 20 74  |g, to supply a t|
00000300  72 61 69 6e 69 6e 67 20  69 6e 70 75 74 2f 6f 75  |raining input/ou|
00000310  74 70 75 74 20 76 65 63  74 6f 72 20 70 61 69 72  |tput vector pair|
00000320  2e 0a 49 74 20 6d 75 73  74 20 72 65 61 64 20 66  |..It must read f|
00000330  72 6f 6d 20 66 69 6c 65  2c 20 6f 72 20 63 72 65  |rom file, or cre|
00000340  61 74 65 20 62 79 20 73  69 6d 75 6c 61 74 69 6f  |ate by simulatio|
00000350  6e 2c 20 72 61 77 20 64  61 74 61 20 66 6f 72 20  |n, raw data for |
00000360  79 6f 75 72 20 73 79 73  74 65 6d 20 28 62 6f 74  |your system (bot|
00000370  68 20 73 61 6d 70 6c 65  20 69 6e 70 75 74 20 26  |h sample input &|
00000380  20 64 65 73 69 72 65 64  20 6f 75 74 70 75 74 29  | desired output)|
00000390  2c 0a 26 20 6e 6f 72 6d  61 6c 69 73 65 20 74 68  |,.& normalise th|
000003a0  69 73 2c 20 70 61 73 73  69 6e 67 20 72 65 73 75  |is, passing resu|
000003b0  6c 74 73 20 62 61 63 6b  20 76 69 61 20 76 65 63  |lts back via vec|
000003c0  74 6f 72 73 20 78 5f 69  6e 20 26 20 64 65 73 69  |tors x_in & desi|
000003d0  72 65 64 5f 6f 75 74 2e  20 54 68 69 73 20 66 75  |red_out. This fu|
000003e0  6e 63 74 69 6f 6e 20 69  73 20 6f 66 20 74 79 70  |nction is of typ|
000003f0  65 20 67 65 74 5f 64 61  74 61 5f 70 72 6f 63 2c  |e get_data_proc,|
00000400  0a 77 68 65 72 65 20 77  65 20 68 61 76 65 3a 0a  |.where we have:.|
00000410  0a 74 79 70 65 64 65 66  20 76 6f 69 64 20 28 2a  |.typedef void (*|
00000420  67 65 74 5f 64 61 74 61  5f 70 72 6f 63 29 20 28  |get_data_proc) (|
00000430  76 65 63 74 6f 72 20 78  5f 69 6e 2c 20 76 65 63  |vector x_in, vec|
00000440  74 6f 72 20 64 65 73 69  72 65 64 5f 6f 75 74 2c  |tor desired_out,|
00000450  20 66 66 5f 73 65 74 75  70 5f 72 65 63 20 2a 73  | ff_setup_rec *s|
00000460  65 74 75 70 29 3b 0a 0a  0a 0a 47 65 6e 65 72 61  |etup);....Genera|
00000470  6c 20 6e 65 74 77 6f 72  6b 20 63 72 65 61 74 69  |l network creati|
00000480  6f 6e 2f 74 72 61 69 6e  69 6e 67 20 66 75 6e 63  |on/training func|
00000490  74 69 6f 6e 73 0a 3d 3d  3d 3d 3d 3d 3d 3d 3d 3d  |tions.==========|
000004a0  3d 3d 3d 3d 3d 3d 3d 3d  3d 3d 3d 3d 3d 3d 3d 3d  |================|
*
000004c0  3d 0a 6e 65 74 77 6f 72  6b 5f 72 65 63 20 2a 61  |=.network_rec *a|
000004d0  6c 6c 6f 63 61 74 65 5f  6e 65 74 77 6f 72 6b 28  |llocate_network(|
000004e0  6e 65 74 77 6f 72 6b 5f  72 65 63 20 2a 6e 65 74  |network_rec *net|
000004f0  77 6f 72 6b 2c 20 66 66  5f 73 65 74 75 70 5f 72  |work, ff_setup_r|
00000500  65 63 20 2a 73 65 74 75  70 29 0a 61 6c 6c 6f 63  |ec *setup).alloc|
00000510  61 74 65 20 6e 65 74 77  6f 72 6b 20 6e 6f 64 65  |ate network node|
00000520  73 20 73 74 6f 72 61 67  65 2c 20 6e 65 74 77 6f  |s storage, netwo|
00000530  72 6b 20 73 69 7a 65 20  73 70 65 63 69 66 69 65  |rk size specifie|
00000540  64 20 77 69 74 68 69 6e  20 66 66 5f 73 65 74 75  |d within ff_setu|
00000550  70 5f 72 65 63 0a 0a 76  6f 69 64 20 66 72 65 65  |p_rec..void free|
00000560  5f 6e 65 74 77 6f 72 6b  28 6e 65 74 77 6f 72 6b  |_network(network|
00000570  5f 72 65 63 20 2a 6e 65  74 77 6f 72 6b 29 0a 66  |_rec *network).f|
00000580  72 65 65 20 75 70 20 6e  65 74 77 6f 72 6b 20 6e  |ree up network n|
00000590  6f 64 65 20 73 74 6f 72  61 67 65 0a 0a 77 65 69  |ode storage..wei|
000005a0  67 68 74 73 5f 72 65 63  20 2a 69 6e 69 74 69 61  |ghts_rec *initia|
000005b0  6c 69 73 65 5f 77 65 69  67 68 74 73 28 77 65 69  |lise_weights(wei|
000005c0  67 68 74 73 5f 72 65 63  20 2a 77 2c 20 42 4f 4f  |ghts_rec *w, BOO|
000005d0  4c 20 72 61 6e 64 6f 6d  5f 69 6e 69 74 2c 20 66  |L random_init, f|
000005e0  66 5f 73 65 74 75 70 5f  72 65 63 20 2a 73 65 74  |f_setup_rec *set|
000005f0  75 70 29 0a 63 72 65 61  74 65 73 20 73 74 6f 72  |up).creates stor|
00000600  61 67 65 20 66 6f 72 20  28 69 66 20 6e 65 63 65  |age for (if nece|
00000610  73 73 61 72 79 29 20 61  6e 64 20 69 6e 69 74 69  |ssary) and initi|
00000620  61 6c 69 73 65 73 20 77  65 69 67 68 74 73 20 99  |alises weights .|
00000630  20 72 61 6e 64 6f 6d 5f  69 6e 69 74 20 73 68 6f  | random_init sho|
00000640  75 6c 64 20 61 6c 77 61  79 73 20 62 65 20 54 52  |uld always be TR|
00000650  55 45 20 28 66 61 6c 73  65 20 69 73 20 66 6f 72  |UE (false is for|
00000660  20 69 6e 74 65 72 6e 61  6c 20 70 75 72 70 6f 73  | internal purpos|
00000670  65 73 29 0a 0a 76 6f 69  64 20 66 72 65 65 5f 6e  |es)..void free_n|
00000680  65 74 77 6f 72 6b 5f 77  65 69 67 68 74 73 28 77  |etwork_weights(w|
00000690  65 69 67 68 74 73 5f 72  65 63 20 2a 77 29 0a 64  |eights_rec *w).d|
000006a0  69 73 63 61 72 64 73 20  74 68 65 20 77 65 69 67  |iscards the weig|
000006b0  68 74 20 61 72 72 61 79  73 0a 0a 42 4f 4f 4c 20  |ht arrays..BOOL |
000006c0  66 65 65 64 66 6f 72 77  61 72 64 28 6e 65 74 77  |feedforward(netw|
000006d0  6f 72 6b 5f 72 65 63 20  2a 6e 2c 20 77 65 69 67  |ork_rec *n, weig|
000006e0  68 74 73 5f 72 65 63 20  2a 77 2c 20 66 66 5f 73  |hts_rec *w, ff_s|
000006f0  65 74 75 70 5f 72 65 63  20 2a 73 29 0a 75 73 65  |etup_rec *s).use|
00000700  64 20 74 6f 20 67 65 6e  65 72 61 74 65 20 6e 65  |d to generate ne|
00000710  74 20 6f 75 74 70 75 74  2c 20 76 69 61 20 77 65  |t output, via we|
00000720  69 67 68 74 73 20 61 6e  64 20 6e 65 74 20 69 6e  |ights and net in|
00000730  70 75 74 2c 20 62 6f 74  68 20 61 74 20 66 69 6e  |put, both at fin|
00000740  61 6c 20 72 75 6e 2d 74  69 6d 65 20 6f 66 20 61  |al run-time of a|
00000750  20 74 72 61 69 6e 65 64  20 6e 65 74 20 61 6e 64  | trained net and|
00000760  20 64 75 72 69 6e 67 20  74 72 61 69 6e 69 6e 67  | during training|
00000770  0a 0a 42 4f 4f 4c 20 62  61 63 6b 70 72 6f 70 61  |..BOOL backpropa|
00000780  67 61 74 69 6f 6e 5f 74  72 61 69 6e 69 6e 67 28  |gation_training(|
00000790  6e 65 74 77 6f 72 6b 5f  72 65 63 20 2a 6e 65 74  |network_rec *net|
000007a0  2c 20 77 65 69 67 68 74  73 5f 72 65 63 20 2a 77  |, weights_rec *w|
000007b0  74 73 2c 20 69 6e 74 20  6e 6f 5f 6f 66 5f 74 72  |ts, int no_of_tr|
000007c0  61 69 6e 69 6e 67 5f 69  74 65 6d 73 2c 20 0a 67  |aining_items, .g|
000007d0  65 74 5f 64 61 74 61 5f  70 72 6f 63 20 67 65 74  |et_data_proc get|
000007e0  5f 6e 65 74 77 6f 72 6b  5f 69 6e 70 75 74 5f 6f  |_network_input_o|
000007f0  75 74 70 75 74 2c 20 42  4f 4f 4c 20 76 65 72 62  |utput, BOOL verb|
00000800  6f 73 65 2c 20 66 66 5f  73 65 74 75 70 5f 72 65  |ose, ff_setup_re|
00000810  63 20 2a 73 65 74 75 70  29 0a 74 68 65 20 62 61  |c *setup).the ba|
00000820  63 6b 62 6f 6e 65 20 6f  66 20 61 6e 79 20 6e 65  |ckbone of any ne|
00000830  74 20 61 70 70 6c 69 63  61 74 69 6f 6e 20 99 20  |t application . |
00000840  69 74 20 74 61 6b 65 73  20 61 6e 20 69 6e 69 74  |it takes an init|
00000850  69 61 6c 69 73 65 64 20  72 61 6e 64 6f 6d 20 28  |ialised random (|
00000860  6f 72 20 70 61 72 74 69  61 6c 6c 79 20 74 72 61  |or partially tra|
00000870  69 6e 65 64 29 20 77 65  69 67 68 74 73 5f 72 65  |ined) weights_re|
00000880  63 2c 20 26 20 74 72 61  69 6e 73 20 69 74 2c 20  |c, & trains it, |
00000890  70 72 6f 76 69 64 69 6e  67 20 67 72 61 70 68 69  |providing graphi|
000008a0  63 61 6c 20 66 65 65 64  62 61 63 6b 20 6f 66 20  |cal feedback of |
000008b0  74 72 61 69 6e 69 6e 67  20 70 72 6f 67 72 65 73  |training progres|
000008c0  73 0a 0a                                          |s..|
000008c3