View Javadoc

1   /*
2    * Created on 18-feb-2005
3    */
4   package yawn.nn.mlp.smart;
5   
6   import java.util.ArrayList;
7   import java.util.List;
8   
9   import yawn.config.NeuralNetworkConfig;
10  import yawn.config.ValidationException;
11  import yawn.nn.mlp.LayerElement;
12  import yawn.nn.mlp.PerceptronNode;
13  import yawn.util.MiscUtils;
14  
15  /***
16   * This is yawn.nn.mlp.smart.SmartiMultiLayerPerceptronConfig part of the yawn
17   * project.
18   * 
19   * <p>$Id: SmartMultiLayerPerceptronConfig.java,v 1.5 2005/05/09 11:04:56 supermarti Exp $</p>
20   * 
21   * @author Luis Mart&iacute; (luis dot marti at uc3m dot es)
22   * @version $Revision: 1.5 $
23   */
24  public class SmartMultiLayerPerceptronConfig extends NeuralNetworkConfig {
25  
26      /***
27       * 
28       */
29      public SmartMultiLayerPerceptronConfig() {
30          super();
31      }
32  
33      /***
34       * @see yawn.config.NeuralNetworkConfig#getBindedNetworkClass()
35       */
36      public Class getBindedNetworkClass() {
37          return SmartMultiLayerPerceptron.class;
38      }
39  
40  	/***
41  	 * 
42  	 */
43  	protected List layerConfigs = new ArrayList();
44  
45  	/***
46  	 * 
47  	 * @uml.property name="learningRate" 
48  	 */
49  	protected double learningRate;
50  
51  	/***
52  	 * 
53  	 * @uml.property name="momentumRate" 
54  	 */
55  	protected double momentumRate;
56  
57  	/***
58  	 * 
59  	 * @uml.property name="maxEpochs" 
60  	 */
61  	protected long maxEpochs;
62  
63  	/***
64  	 * 
65  	 * @uml.property name="predictionError" 
66  	 */
67  	protected double predictionError;
68  
69  
70      public void addHiddenLayerConfig(LayerElement le) {
71          layerConfigs.add(le);
72      }
73  
74  	/***
75  	 * @return Returns the layerElements.
76  	 * 
77  	 * @uml.property name="layerConfigs"
78  	 */
79  	public List getLayerConfigs() {
80  		return layerConfigs;
81  	}
82  
83  	/***
84  	 * @param layers
85  	 *            The layers to set.
86  	 * 
87  	 * @uml.property name="layerConfigs"
88  	 */
89  	public void setLayerConfigs(List layers) {
90  		this.layerConfigs = layers;
91  	}
92  
93  
94      /***
95       * @see yawn.config.NeuralNetworkConfig#internalValidate()
96       */
97      protected void internalValidate() throws ValidationException {
98          if (layerConfigs.size() == 0) {
99              throw new ValidationException("no layers defined");
100         }
101 
102         if (getLearningRate() < 0) {
103             throw new ValidationException("learning rate must be a positive number");
104         }
105 
106         if (getMaxEpochs() < 0) {
107             throw new ValidationException("max epochs must be a positive number");
108         }
109 
110         if (getPredictionError() <= 0) {
111             throw new ValidationException("prediction error must be greater than zero");
112         }
113 
114         for (int i = 0; i < layerConfigs.size(); i++) {
115             LayerElement lc = (LayerElement) layerConfigs.get(i);
116 
117             // right dimension?
118             if (lc.getSize() < 1) {
119                 throw new ValidationException(lc.toString());
120             }
121 
122             // can load the node class?
123             Class nodeClass = null;
124             try {
125                 nodeClass = Class.forName(lc.getNodesClassName());
126             } catch (ClassNotFoundException e) {
127                 throw new ValidationException(lc.toString());
128             }
129 
130             if (!MiscUtils.isSuperClass(PerceptronNode.class, nodeClass)) {
131                 throw new ValidationException(lc.toString());
132             }
133         }
134 
135     }
136 
137 	/***
138 	 * @return Returns the learningRate.
139 	 * 
140 	 * @uml.property name="learningRate"
141 	 */
142 	public double getLearningRate() {
143 		return this.learningRate;
144 	}
145 
146 	/***
147 	 * @param learningRate
148 	 *            The learningRate to set.
149 	 * 
150 	 * @uml.property name="learningRate"
151 	 */
152 	public void setLearningRate(double learningRate) {
153 		this.learningRate = learningRate;
154 	}
155 
156 	/***
157 	 * @return Returns the maxEpochs.
158 	 * 
159 	 * @uml.property name="maxEpochs"
160 	 */
161 	public long getMaxEpochs() {
162 		return this.maxEpochs;
163 	}
164 
165 	/***
166 	 * @param maxEpochs
167 	 *            The maxEpochs to set.
168 	 * 
169 	 * @uml.property name="maxEpochs"
170 	 */
171 	public void setMaxEpochs(long maxEpochs) {
172 		this.maxEpochs = maxEpochs;
173 	}
174 
175 	/***
176 	 * @return Returns the predictionError.
177 	 * 
178 	 * @uml.property name="predictionError"
179 	 */
180 	public double getPredictionError() {
181 		return this.predictionError;
182 	}
183 
184 	/***
185 	 * @param predictionError
186 	 *            The predictionError to set.
187 	 * 
188 	 * @uml.property name="predictionError"
189 	 */
190 	public void setPredictionError(double predictionError) {
191 		this.predictionError = predictionError;
192 	}
193 
194 	/***
195 	 * @return Returns the momentumRate.
196 	 * 
197 	 * @uml.property name="momentumRate"
198 	 */
199 	public double getMomentumRate() {
200 		return this.momentumRate;
201 	}
202 
203 	/***
204 	 * @param momentumRate
205 	 *            The momentumRate to set.
206 	 * 
207 	 * @uml.property name="momentumRate"
208 	 */
209 	public void setMomentumRate(double momentumRate) {
210 		this.momentumRate = momentumRate;
211 	}
212 
213 	/* (non-Javadoc)
214 	 * @see yawn.config.NeuralNetworkConfig#createSampleInstance()
215 	 */
216 	public NeuralNetworkConfig createSampleInstance() {
217 		// TODO Auto-generated method stub
218 		return null;
219 	}
220 
221 }