== Genann [[toc:]] === Introduction Genann is an chicken egg that provides bindings to the [[https://github.com/codeplea/genann|genann]] ANSI C neural network library. The C library is written only in standard C, the egg is written only in 'standard' Chicken 5 (what comes included with C5, no eggs). === Genann API (genann-init inputs hidden-layers hidden-neurons outputs) Creates and returns a genann record. Each argument is an integer specifying how many of that the genann should have. {{hidden-neurons}} is the number of hidden neurons ''per hidden layer.'' (genann-copy genann) Return a new copy of {{genann}}. (genann-free! genann) Free the memory used by {{genann}}. (genann-train genann inputs desired-outputs learning-rate) Does a single backpropagation update on {{genann}}, where {{inputs}} and {{desired-outputs}} are f64vectors and {{learning-rate}} is a flonum. (genann-run genann inputs) Runs the feedforward algorithm to calculate the ann's output from f64vector {{inputs}}. Returns outputs as an f64vector. (genann-randomize genann) Sets the weights in {{genann}} randomly. This is called by {{genann-init}}. (genann-read #!optional port) Read a genann record from file port {{port}}. (genann-write #!optional port) Write a genann to file port {{port}}. === Added procedures (genann-init* inputs hidden-layers hidden-neurons outputs) (make-genann ...) Like {{genann-init}}, but sets {{genann-free!}} as a finalizer to the returned genann so it can be properly garbage collected. {{make-genann}} is the same procedure as {{genann-init*}}. (genann-copy* genann) Like {{genann-copy}}, but sets {{genann-free!}} as a finalizer to the returned genann so it can be properly garbage collected. (genann-inputs genann) (genann-hidden-layers genann) (genann-hidden-neurons genann) (genann-outputs genann) (genann-total-weights genann) (genann-weights genann) Returns number of inputs, hidden layers, hidden neurons per layer, and outputs, respectively, in {{genann}}. These are more or less equivalent to the following in C: // genann is created with genann_init genann->inputs genann->hidden_layers genann->hidden genann->outputs genann->total_weights gennan->weight (genann-weight-set! genann i x) (genann-weight-ref genann i) Set or get the {{i}}th weight of {{genann}}, with the former being a setter for the latter, so you can use {{set!}} with {{genann-weight-ref}}. Useful for training with random search, as in [[https://github.com/dieggsy/genann/blob/master/example2.scm|example2.scm]]. === Examples * [[https://github.com/dieggsy/genann/blob/master/example1.scm|Training using backpropagation]] * [[https://github.com/dieggsy/genann/blob/master/example2.scm|Training using random search]] * [[https://github.com/dieggsy/genann/blob/master/example3.scm|Loading a saved ANN]] * [[https://github.com/dieggsy/genann/blob/master/example4.scm|Training on the IRIS dataset using backpropagation]]