API documentation
Neural network class and accessors
Functions
neural-network| Superclasses | (t) |
| Metaclass | standard-class |
| Default Initargs | nil |
Class for neural networks
layoutNumber of neurons in each layer of the networkAllocation instance Type listInitarg :layoutInitform (error "Specify number of neurons in each layer")Readers (neural-network-layout)activation-funcsList of activation functions.Allocation instance Type listInitarg :activation-funcsInitform nilAccessors (neural-network-activation-funcs)weightsWeight matrices for each layerAllocation instance Type listAccessors (neural-network-weights)biasesBias vectors for each layerAllocation instance Type listAccessors (neural-network-biases)input-transFunction which translates an input object to a vectorAllocation instance Type functionInitarg :input-transInitform (function identity)Accessors (neural-network-input-trans)output-transFunction which translates an output vector to a label.Allocation instance Type functionInitarg :output-transInitform (function identity)Accessors (neural-network-output-trans)input-trans%Function which translates an input object to a vector (used for training)Allocation instance Type functionInitarg :input-trans%Initform (function identity)Accessors (neural-network-input-trans%)label-transFunction which translates a label to a vectorAllocation instance Type functionInitarg :label-transInitform (function identity)Accessors (neural-network-label-trans)
make-neural-network(layout &key input-trans output-trans input-trans% label-trans activation-funcs)Create a new neural network.
layoutis a list of positive integers which describes a number of neurons in each layer (starting from input layer).activation-funcsis a list all the elements of which are objects of typeactivation. The length of this list must be equal to the length oflayoutminus one because the input layer does not have an activation function. The last element must be of typeoutput-layer-activationand the all elements but last must be of typehidden-layer-activation.input-transis a function which is applied to an object passed tocalculateto transform it into an input column (that is a matrix with the typemagicl:matrix/single-floatand the shapeNx1, whereNis the first number in thelayout). For example, if we are recognizing digits from the MNIST set, this function can take a number of an image in the set and return784x1matrix.output-transis a function which is applied to the output ofcalculatefunction (that is a matrix with the typemagicl:matrix/single-floatand the shape Mx1, where M is the last number in thelayout) to return some object with user-defined meaning (called a label). Again, if we are recognizing digits, this function transforms10x1matrix to a number from 0 to 9.input-trans%is just likeinput-trans, but is used while training. It can include additional transformations to extend your training set (e.g. it can add some noise to input data, rotate an input picture by a small random angle, etc.).label-transis a function which is applied to a label to get a column (that is a matrix with the typemagicl:matrix/single-floatand the shapeMx1, whereMis the last number in thelayout) which is the optimal output from the network for this object. With digits recognition, this function may take a digitnand return10x1matrix of all zeros with exception forn-th element which would be1f0.
identity.calculate(neural-network object)Calculate output from the network
neural-network for the object
object. The input transformation function (specified by
:input-trans when creating a network) is applied to the object
and the output transformation function (specified by
:output-trans) is applied to output Nx1 matrix from the network.train-epoch(neural-network generator &key (optimizer (make-instance (quote sgd-optimizer))))Perform training of
neural-network on every object returned
by the generator generator. Each item returned by generator
must be in the form (data-object . label) cons
pair. input-trans% and label-trans functions passes to
make-neural-network are applied to car and cdr of each
pair respectively.rate(neural-network generator &key (test (function eql)))Calculate accuracy of the
neural-network(ratio of correctly
guessed samples to all samples) using testing data from the generator
generator. Each item returned by generator must be a cons pair
in the form (data-object . label), as with train-epoch
function. test is a function used to compare the expected label
with the label returned by the network.idx-abs-max(matrix)Returns index of first element with maximal absolute value by
calling isamax() function from BLAS. Works only for rows or
columns.