View Javadoc

1   /*
2    * NetworkCommitteeConfig.java
3    * Part of the yawn project
4    * Created on 06-oct-2004 by marti.
5    *
6    */
7   package yawn.nn.committee;
8   
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  import yawn.config.NeuralNetworkConfig;
13  import yawn.config.ValidationException;
14  import yawn.nn.committee.functions.Average;
15  import yawn.nn.mlp.LayerElement;
16  import yawn.nn.mlp.MultiLayerPerceptronConfig;
17  
18  /***
19   * This is yawn.nn.committee.NetworkCommitteeConfig, part of the yawn project.
20   * 
21   * <p>
22   * $Id: NetworkCommitteeConfig.java,v 1.6 2005/05/09 11:04:54 supermarti Exp $
23   * </p>
24   * 
25   * @author Luis Mart&iacute; (luis dot marti at uc3m dot es)
26   * @version $Revision: 1.6 $
27   *  
28   */
29  public class NetworkCommitteeConfig extends NeuralNetworkConfig {
30  
31  	/***
32  	 * 
33  	 */
34  	protected List committeeElements;
35  
36  	/***
37  	 * 
38  	 */
39  	protected Class combinationFunctionClass;
40  
41  	/***
42  	 * 
43  	 */
44  	protected boolean serialProcessing;
45  
46  	/***
47  	 * @return Returns the serialProcessing.
48  	 */
49  	public boolean isSerialProcessing() {
50  		return serialProcessing;
51  	}
52  
53  	/***
54  	 * @param serialProcessing
55  	 *                      The serialProcessing to set.
56  	 */
57  	public void setSerialProcessing(boolean serialProcessing) {
58  		this.serialProcessing = serialProcessing;
59  	}
60  
61  	/***
62  	 * @return Returns the combinationFunctionClass.
63  	 */
64  	public Class getCombinationFunctionClass() {
65  		return combinationFunctionClass;
66  	}
67  
68  	/***
69  	 * @param combinationFunctionClass
70  	 *                      The combinationFunctionClass to set.
71  	 */
72  	public void setCombinationFunctionClassName(Class combinationFunctionClass) {
73  		this.combinationFunctionClass = combinationFunctionClass;
74  	}
75  
76  	/***
77  	 *  
78  	 */
79  	public NetworkCommitteeConfig() {
80  		super();
81  		committeeElements = new ArrayList();
82  	}
83  
84  	public void addCommitteeMember(CommitteeElement ce) {
85  		committeeElements.add(ce);
86  	}
87  
88  	/***
89  	 * @return Returns the committeeElements.
90  	 */
91  	public List getCommitteeElements() {
92  		return committeeElements;
93  	}
94  
95  	/***
96  	 * @param committeeElements
97  	 *                      The committeeElements to set.
98  	 */
99  	public void setCommitteeElements(List committeeElements) {
100 		this.committeeElements = committeeElements;
101 	}
102 
103 	/*
104 	 * (non-Javadoc)
105 	 * 
106 	 * @see yawn.nn.NeuralNetworkConfig#getBindedNetworkClass()
107 	 */
108 	public Class getBindedNetworkClass() {
109 		return NetworkCommittee.class;
110 	}
111 
112 	/***
113 	 * @see yawn.config.NeuralNetworkConfig#internalValidate()
114 	 */
115 	protected void internalValidate() throws ValidationException {
116 		for (int i = 0; i < committeeElements.size(); i++) {
117 			NeuralNetworkConfig comConf = ((CommitteeElement) committeeElements
118 					.get(i)).getNetworkConfig();
119 			if (comConf.getEnvironment() == null) {
120 				comConf.setEnvironment(this.getEnvironment());
121 			}
122 			comConf.validate();
123 		}
124 
125 		try {
126 			combinationFunctionClass.newInstance();
127 		} catch (InstantiationException e) {
128 			throw new ValidationException(e);
129 		} catch (IllegalAccessException e) {
130 			throw new ValidationException(e);
131 		}
132 	}
133 
134 	/*
135 	 * (non-Javadoc)
136 	 * 
137 	 * @see yawn.config.NeuralNetworkConfig#createSampleInstance()
138 	 */
139 	public NeuralNetworkConfig createSampleInstance() {
140 		NetworkCommitteeConfig mainConf = new NetworkCommitteeConfig();
141 
142 		MultiLayerPerceptronConfig conf = new MultiLayerPerceptronConfig();
143 
144 		conf.setMaxEpochs(500);
145 		conf.setLearningRate(0.5);
146 		conf.setPredictionError(0.1);
147 
148 		LayerElement hiddenLayer = new LayerElement();
149 		hiddenLayer.setNodesClassName("yawn.nn.mlp.SigmoidNode");
150 		hiddenLayer.setSize(20);
151 
152 		LayerElement outputLayer = new LayerElement();
153 		outputLayer.setNodesClassName("yawn.nn.mlp.LinearNode");
154 		outputLayer.setSize(8);
155 
156 		ArrayList layers = new ArrayList();
157 		layers.add(hiddenLayer);
158 		layers.add(outputLayer);
159 
160 		conf.setLayerConfigs(layers);
161 
162 		CommitteeElement ce = new CommitteeElement();
163 		ce.setNetworkConfig(conf);
164 		ce.setAmount(3);
165 
166 		mainConf.addCommitteeMember(ce);
167 		mainConf.setSerialProcessing(false);
168 		mainConf.setCombinationFunctionClassName(Average.class);
169 
170 		return mainConf;
171 	}
172 }