Module Ann_topology

module Ann_topology: sig .. end
Neural networks topology: units, layers, and connections.

Type describing the topology of a neural network

type nn_topology = {
   layers : (int * int) array; (*The network is organized in layers, each layer being described by its first and last unit.*)
   conn : (int * int) array; (*Array of connections (i,j), from unit i to unit j. Connections (and the corresponding weights) are stored in order of their destination unit.*)
   inc : int list array; (*Incoming connections: inc.(u) is the list of connections from other units to unit u.*)
   outc : int list array; (*Outcoming connections: outc.(u) is the list of connections from unit u to other units.*)
   bias_units : int list; (*List of bias units. Biases are considered as weights assigned to connections coming from special units (called "bias units"), The outputs of a bias units is a constant value 1. Bias units are inserted before the other units in each layer, except in the output layer where ther is no bias unit.*)
Description of the networks units, layers, and connections.

Read and write networks files

val fprint_list : out_channel -> int list -> unit
fprint_list ch l prints a list l of integer on channel ch
val fprint_short_topology : out_channel -> nn_topology -> unit
fprint_short_topology ch nn prints a short description of network nn on channel ch. Only the layers, connections and bias units are printed. *
val fprint_network : out_channel -> nn_topology -> unit
fprint_network ch nn prints the full description of network nn on channel ch.
val save_network : nn_topology -> string -> unit
save_network nn filename saves the network's topology nn into file filename
val read_network : string -> nn_topology
read_network filename reads a neural network's description (layers, connections, and bias units) from a file, and returns the network's topology.

Build a fully connected feed-forward neural network

val fully_connected : int array -> nn_topology
fully_connected raw_layers builds a fully connected feed-forward network. raw_layers describes the number of units in each layer, without the bias units. The bias units are automatically inserted by the function, at the beginning of each layer.

Useful functions

val hidden : (int * int) array -> (int * int) option
hidden layers returns option None when layers contains only one input and one output layer, and Some (u1,u2), where u1 and u2 are the first and last hidden units respectively, if there are some hidden layers. The function raises an exception if the size of layers is less than 2. layers is of the nn.layers type.
val outlayer : (int * int) array -> int * int
outlayer layers returns the first and last units of the output layer.
val bias_unit : nn_topology -> int -> bool
bias_units nn u returns true is u is a bias unit of nn, and false otherwise.
val source : nn_topology -> int -> int
source nn k returns the source unit of connection k of network nn.
val dest : nn_topology -> int -> int
dest nn k returns the destination unit of connection k of network nn.
val layer_of : nn_topology -> int -> int
layer_of nn u returns the number of the layer to which unit u belongs, according to the network's descriptin in nn.