(****************************************************************** [LibNN - Neural Networks Library] http://libnn.org Copyright (C) 2002 - 2003 LAGACHERIE Matthieu RICORDEAU Olivier This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. SPECIAL NOTE (the beerware clause): This software is free software. However, it also falls under the beerware special category. That is, if you find this software useful, or use it every day, or want to grant us for our modest contribution to the free software community, feel free to send us a beer from one of your local brewery. Our preference goes to Belgium abbey beers and irish stout (Guiness for strength!), but we like to try new stuffs. Authors: LAGACHERIE Matthieu Paper mail : 7 rue Delescluzes 94280 LE KREMLIN BICETRE, FRANCE E-mail : matthieu@libnn.org RICORDEAU Olivier Paper mail : 69 avenue d'Italie 75013 PARIS, FRANCE E-mail : olivier@libnn.org *****************************************************************) (** The initMlpNNVisitor class @author Matthieu Lagacherie @author Olivier Ricordeau @since 10/08/2003 *) open Random open Nn open InitVisitor open DefaultVisitor open MlpNN (** Initializes the output activation. *) let initOutputActivation network = let outputActivation = Array.make network#getLayerNb [||] in for i = 0 to network#getLayerNb - 1 do outputActivation.(i) <- Array.make (network#getNeuronsPerLayer i) 0.0 done; network#setOutputActivation outputActivation (** Initializes the the input sum. *) let initInputSum network = let inputSum = Array.make network#getLayerNb [||] in for i = 0 to network#getLayerNb - 1 do inputSum.(i) <- Array.create (network#getNeuronsPerLayer i) 0.0 done; network#setInputSum inputSum (** Initializes the error. *) let initError network = let error = Array.make network#getLayerNb [||] in for i = 0 to network#getLayerNb - 1 do error.(i) <- Array.make (network#getNeuronsPerLayer i) 0.0 done; network#setError error (** Initializes the weights (using random numbers). *) let initWeights network = let weights = Array.make (network#getLayerNb - 1) [|[||]|] in for i = 0 to network#getLayerNb - 2 do weights.(i) <- Array.make (network#getNeuronsPerLayer i) [||]; for j = 0 to (network#getNeuronsPerLayer i) - 1 do weights.(i).(j) <- Array.make (network#getNeuronsPerLayer (i + 1)) (Random.float (Env.getEnv())#getRandLimit) done; done; network#setWeights weights (** Initializes the gradients. *) let initGradients network = let gradients = Array.make (network#getLayerNb - 1) [|[||]|] in for i = 0 to network#getLayerNb - 2 do gradients.(i) <- Array.create (network#getNeuronsPerLayer i) [||]; for j = 0 to (network#getNeuronsPerLayer i) - 1 do gradients.(i).(j) <- Array.create (network#getNeuronsPerLayer (i + 1)) 0.0 done; done; network#setGradients gradients class initMlpnnVisitor = object inherit [mlpNN] initVisitor (** The method which initializes the networks. It uses the Random module to initialize the weights. @see Using the Random module (provided in the standard OCaml distribution). @see Used to initialize the random number generator. *) method visit (network : mlpNN) = (** Initialize the random number generator. *) Random.self_init(); (** Initialize everything *) initOutputActivation network; initInputSum network; initError network; initGradients network; initWeights network end