Genann

  1. Genann
    1. Introduction
    2. Genann API
    3. Added procedures
    4. Examples

Introduction

Genann is an chicken egg that provides bindings to the 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

[procedure] (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.

[procedure] (genann-copy genann)

Return a new copy of genann.

[procedure] (genann-free! genann)

Free the memory used by genann.

[procedure] (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.

[procedure] (genann-run genann inputs)

Runs the feedforward algorithm to calculate the ann's output from f64vector inputs. Returns outputs as an f64vector.

[procedure] (genann-randomize genann)

Sets the weights in genann randomly. This is called by genann-init.

[procedure] (genann-read #!optional port)

Read a genann record from file port port.

[procedure] (genann-write #!optional port)

Write a genann to file port port.

Added procedures

[procedure] (genann-init* inputs hidden-layers hidden-neurons outputs)
[procedure] (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*.

[procedure] (genann-copy* genann)

Like genann-copy, but sets genann-free! as a finalizer to the returned genann so it can be properly garbage collected.

[procedure] (genann-inputs genann)
[procedure] (genann-hidden-layers genann)
[procedure] (genann-hidden-neurons genann)
[procedure] (genann-outputs genann)
[procedure] (genann-total-weights genann)
[procedure] (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
[procedure] (genann-weight-set! genann i x)
[procedure] (genann-weight-ref genann i)

Set or get the ith 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 example2.scm.

Examples