/[marvin]/marvin/src/libnn/propagate/propagateTdnnVisitor.ml
ViewVC logotype

Diff of /marvin/src/libnn/propagate/propagateTdnnVisitor.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by matthieu, Wed Sep 10 21:20:10 2003 UTC revision 1.6 by matthieu, Sat Sep 13 15:32:32 2003 UTC
# Line 1  Line 1 
1  (******************************************************************  (******************************************************************
2    [LibNN - Neural Networks Library]     [LibNN - Neural Networks Library]
3    http://libnn.org     http://libnn.org
4    Copyright (C) 2002 - 2003  LAGACHERIE Matthieu RICORDEAU Olivier     Copyright (C) 2002 - 2003  LAGACHERIE Matthieu RICORDEAU Olivier
5    
6    This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
8    as published by the Free Software Foundation; either version 2     as published by the Free Software Foundation; either version 2
9    of the License, or (at your option) any later version. This     of the License, or (at your option) any later version. This
10    program is distributed in the hope that it will be useful,     program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of     but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13    GNU General Public License for more details. You should have     GNU General Public License for more details. You should have
14    received a copy of the GNU General Public License     received a copy of the GNU General Public License
15    along with this program; if not, write to the Free Software     along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
17    USA.     USA.
18    
19    SPECIAL NOTE (the beerware clause):     SPECIAL NOTE (the beerware clause):
20    This software is free software. However, it also falls under the beerware     This software is free software. However, it also falls under the beerware
21    special category. That is, if you find this software useful, or use it     special category. That is, if you find this software useful, or use it
22    every day, or want to grant us for our modest contribution to the     every day, or want to grant us for our modest contribution to the
23    free software community, feel free to send us a beer from one of     free software community, feel free to send us a beer from one of
24    your local brewery. Our preference goes to Belgium abbey beers and     your local brewery. Our preference goes to Belgium abbey beers and
25    irish stout (Guiness for strength!), but we like to try new stuffs.     irish stout (Guiness for strength!), but we like to try new stuffs.
26    
27    Authors:     Authors:
28    LAGACHERIE Matthieu     LAGACHERIE Matthieu
29    Paper mail : 7 rue Delescluzes 94280 LE KREMLIN BICETRE, FRANCE     Paper mail : 7 rue Delescluzes 94280 LE KREMLIN BICETRE, FRANCE
30    E-mail : matthieu@libnn.org     E-mail : matthieu@libnn.org
31    
32    RICORDEAU Olivier     RICORDEAU Olivier
33    Paper mail : 69 avenue d'Italie 75013 PARIS, FRANCE     Paper mail : 69 avenue d'Italie 75013 PARIS, FRANCE
34    E-mail : olivier@libnn.org     E-mail : olivier@libnn.org
35    
36  *****************************************************************)   *****************************************************************)
37    
38  (**  (**
39    The propagateTdnnVisitor class     The propagateTdnnVisitor class
40    Propagates a learning example through the neural network.     Propagates a learning example through the neural network.
41    
42    @author Matthieu Lagacherie     @author Matthieu Lagacherie
43    @author Olivier Ricordeau     @since 08/10/2003
44    @since 10/08/2003   *)
 *)  
45    
46  open Nn  open Nn
47  open PropagateVisitor  open PropagateVisitor
# Line 50  open DefaultVisitor Line 49  open DefaultVisitor
49  open TdNN  open TdNN
50    
51  class propagateTdnnVisitor =  class propagateTdnnVisitor =
52  object    object
53    inherit [tdNN] propagateVisitor      inherit [tdNN] propagateVisitor
54    val mutable _transfertFunction = function x -> (1. /. (1. +. exp (-.x)))      val mutable _transfertFunction = function x -> (1. /. (1. +. exp (-.x)))
55    method visit (network : tdNN) =      method visit (network : tdNN) =
56      let transFun = _transfertFunction and        let transFun = _transfertFunction and
57          outputActivation = network#getOutputActivation and            outputActivation = network#getOutputActivation and
58          inputSum = network#getInputSum and            inputSum = network#getInputSum and
59          weights = network#getWeights and            weights = network#getWeights and
60          delay = network#getDelay and            delay = network#getDelay and
61          timeNb = network#getTimeNb and            timeNb = network#getTimeNb and
62          featuresNb = network#getFeaturesNb and            featuresNb = network#getFeaturesNb and
63          stepDelay = ref 0 in            fieldSize = network#getFieldSize and
64      begin            stepDelay = ref 0 in
65        (**        begin
66           Activation of the input layer.          (**
67         *)             Activation of the input layer.
68        for i = 0 to featuresNb.(0) - 1 do           *)
69          for j = 0 to timeNb.(0) - 1 do          for i = 0 to featuresNb.(0) - 1 do
70            !outputActivation.(0).(i).(j) <- transFun !inputSum.(0).(i).(j)            for j = 0 to timeNb.(0) - 1 do
71          done              !outputActivation.(0).(i).(j) <- transFun !inputSum.(0).(i).(j)
72        done;            done
73        (**          done;
74           Propagation of the activation.          (**
75           l the layer             Propagation of the activation.
76           i neuron of the layer l + 1 in the feature direction             l the layer
77           j neuron of the layer l + 1 in the time direction             i neuron of the layer l + 1 in the feature direction
78           k neuron of the layer l in the feature direction             j neuron of the layer l + 1 in the time direction
79           m neuron of the layer l in the time direction             k neuron of the layer l in the feature direction
80           stepDelay used to keep the delay concept             m neuron of the layer l in the time direction
81          *)             stepDelay used to keep the delay concept
82        for l = 0 to network#getLayerNb - 2 do           *)
83          for i = 0 to featuresNb.(l + 1) - 1 do          for l = 0 to network#getLayerNb - 2 do
84            for j = 0 to timeNb.(l + 1) - 1 do            for j = 0 to timeNb.(l + 1) - 1 do
85              !inputSum.(l + 1).(i).(j) <- 0.;              for i = 0 to featuresNb.(l + 1) - 1 do
86              for k = 0 to featuresNb.(l) - 1 do  (**
87                for m = !stepDelay to (!stepDelay + !delay.(l)) - 1 do     We initialize the input sum of the layer l + 1.
88                  !inputSum.(l + 1).(i).(j) <- !inputSum.(l + 1).(i).(j)   *)
89                      +. !outputActivation.(l).(k).(l + !stepDelay)                !inputSum.(l + 1).(i).(j) <- 0.;
90                      *. !weights.(l).(i).(k).(j);                for k = 0 to featuresNb.(l) - 1 do
91                done                  for m = !stepDelay to (!stepDelay + fieldSize.(l)) - 1 do
92    (*                Printf.printf "Indices [l=%d] [i=%d] [j=%d] [k=%d] [m=%d] [stepDelay=%d]\n" l i j k m !stepDelay; *)
93                      !inputSum.(l + 1).(i).(j) <- !inputSum.(l + 1).(i).(j)
94                          +. !outputActivation.(l).(k).(m)
95                          *. !weights.(l).(k).(m - !stepDelay).(i);
96    (*                Printf.printf "Valeur !inputSum.(%d).(%d).(%d) <- " (l + 1) i j;
97                      Printf.printf "!inputSum.(%d).(%d).(%d)\n +. !outputActivation.(%d).(%d).(%d)\n *. !weights.(%d).(%d).(%d).(%d);\n" (l+1) i j l k m l k (m - !stepDelay) i;
98                      Printf.printf "\n = %f\n" !inputSum.(l + 1).(i).(j) *)
99                    done
100                done;                done;
101              !outputActivation.(l + 1).(i).(j) <- transFun !inputSum.(l + 1).(i).(j);                !outputActivation.(l + 1).(i).(j) <- transFun !inputSum.(l + 1).(i).(j);
102                done;
103              stepDelay := !stepDelay + !delay.(l)              stepDelay := !stepDelay + !delay.(l)
104            done;            done;
105            stepDelay := 0            stepDelay := 0
106          done;          done
         stepDelay := 0  
       done  
107        end        end
108  end    end

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26