View Javadoc

1   package yawn.nn.gasart;
2   
3   import java.util.Vector;
4   
5   import yawn.nn.appart.RadialBasisFunctionsNeuralNode;
6   import yawn.util.Pattern;
7   
8   /***
9    * A neural node of the recognition (F2) layer of GasART networks
10   * 
11   * <p>$Id: GasRecognitionNode.java,v 1.9 2005/05/09 11:04:57 supermarti Exp $</p>
12   * 
13   * @author Luis Mart&iacute; (luis dot marti at uc3m dot es)
14   * @version $Revision: 1.9 $
15   */
16  public class GasRecognitionNode extends RadialBasisFunctionsNeuralNode {
17  
18  	/***
19  	 * 
20  	 * @uml.property name="defaultSigma"
21  	 * @uml.associationEnd multiplicity="(0 1)"
22  	 */
23  	protected Pattern defaultSigma; // se usara cuando no se tengan vecinos
24  
25  
26      protected boolean inserted;
27  
28  	/***
29  	 * 
30  	 * @uml.property name="resource" 
31  	 */
32  	protected double resource = 0.0;
33  
34  
35      protected boolean second;
36  
37  	/***
38  	 * 
39  	 * @uml.property name="activation" 
40  	 */
41  	// double sigma = 0.0; //uno unico y no uno para cada componente de la
42  	// entrada
43  	// TOCHECK
44  	protected double activation;
45  
46  	/***
47  	 * 
48  	 * @uml.property name="resetActivation" 
49  	 */
50  	protected double resetActivation;
51  
52  	/***
53  	 * 
54  	 * @uml.property name="toWhoIBelong"
55  	 * @uml.associationEnd multiplicity="(0 -1)" inverse="vertexA:yawn.nn.gasart.GasEdge"
56  	 */
57  	Vector toWhoIBelong = new Vector();
58  
59  
60      public boolean winner;
61  
62      public GasRecognitionNode(int inputSize, double aThreshold, int aCategoryIndex) {
63          super(inputSize, aThreshold, aCategoryIndex);
64          resource = 0.0;
65          inserted = true;
66          winner = false;
67          second = false;
68      }
69  
70      protected double activationFuntion(Pattern input) {
71          // TOCHECK
72          double denom = sigma != null ? sigma.getComponent(0) : defaultSigma.getComponent(0);
73          // el valor de sigma se actualiza en cada iteracion
74          // en dependencia de la media de las distancia hacia los vecinos
75          // por lo que se ha de garantizar el poner a 0.0
76          // el sigma de aquellos que no tengan vecinos y que en esta condicion
77          // usaran el por defecto
78          double netInput = 0;
79          for (int i = 0; i < input.size(); i++) {
80              netInput += Math.pow(input.getComponent(i) - mu.getComponent(i), 2.0);
81          }
82          return Math.exp(netInput / (-2 * denom * denom));
83      }
84  
85      public GasEdge edgeWith(GasRecognitionNode other) {
86          GasEdge result = null;
87          GasEdge aux;
88          int l = toWhoIBelong.size();
89          for (int i = 0; i < l; i++) {
90              aux = ((GasEdge) toWhoIBelong.elementAt(i));
91              result = (aux.vertexA == other || aux.vertexB == other) ? aux : null;
92              if (result != null)
93                  return result;
94          }
95          return result;// null
96      }
97  
98      public double getActivation() {
99          return 0;// TODO:
100     }
101 
102     public double getMu(int pos) {
103         return mu.getComponent(pos);
104     }
105 
106 	/***
107 	 * 
108 	 * @uml.property name="resource"
109 	 */
110 	public void incResource(double error) {
111 		resource += error * error;
112 	}
113 
114 
115     public void learn(double fact) {// adaptacion central
116         for (int i = 0; i < getInputSize(); i++)
117             mu.setComponent(fact * (input.getComponent(i) - mu.getComponent(i))
118                     + mu.getComponent(i), i);
119     }
120 
121 	/***
122 	 * 
123 	 * @uml.property name="defaultSigma"
124 	 */
125 	// referencias a las aristas a las que pertenece este nodo
126 	public void learnNewClass(Pattern gamma, int n) {
127 		categoryIndex = n;
128 		sigma = null; // this value will change as soon as this node becomes a
129 		// neighbor of others
130 		mu = (Pattern) input.clone();
131 		defaultSigma = (Pattern) gamma.clone();
132 		// TOCHECK despues que la llame deben cambiar los pesos alfa_kn y
133 		// beta_kn
134 	}
135 
136 
137     public Pattern position() {
138         return mu;
139     }
140 
141 	/***
142 	 * 
143 	 * @uml.property name="activation"
144 	 */
145 	public void setActivation(double act) {
146 		activation = act;
147 	}
148 
149 
150     public void setInput(double value, int pos) {
151         input.setComponent(value, pos);
152         // TOCHECK if (categoryIndex > 0) setInput(java.lang.Math.pow(val -
153         // mu[i], 2.0));
154     }
155 
156     public void setMu(double value, int pos) {
157         mu.setComponent(value, pos);
158     }
159 
160     public void setPenality(double er) {
161         resource += activation * er;
162     }
163 
164 	/***
165 	 * 
166 	 * @uml.property name="resetActivation"
167 	 */
168 	public void setResetActivation(double act) {
169 		resetActivation = act;
170 	}
171 
172     public void setSigma(double sig) {
173         sigma.setAllComponents(sig);
174     }
175 
176 }