View Javadoc

1   /*
2    * NeuralNetworkConfig.java
3    * Part of the yawn project
4    * Created on 06-oct-2004 by marti.
5    *
6    */
7   package yawn.config;
8   
9   import yawn.YawnRuntimeException;
10  import yawn.envs.Environment;
11  import yawn.nn.NeuralNetwork;
12  
13  /***
14   * This is yawn.nn.NeuralNetworkConfig, part of the yawn project.
15   * 
16   * <p>$Id: NeuralNetworkConfig.java,v 1.7 2005/05/09 11:04:58 supermarti Exp $</p>
17   * 
18   * @author Luis Mart&iacute; (luis dot marti at uc3m dot es)
19   * @version $Revision: 1.7 $
20   */
21  
22  public abstract class NeuralNetworkConfig extends ConfigElement {
23  
24      protected NeuralNetworkConfig() {
25      }
26  
27      /***
28       * A factory of ready to train (and use) neural networks
29       * 
30       * @return Returns a configured network.
31       */
32      public NeuralNetwork configuredNetworkFactory() {
33          try {
34              NeuralNetwork res = (NeuralNetwork) getBindedNetworkClass().newInstance();
35              res.setup(this);
36              return res;
37          } catch (ConfigurationException e) {
38              throw new YawnRuntimeException(e);
39          } catch (InstantiationException e) {
40              throw new YawnRuntimeException(e);
41          } catch (IllegalAccessException e) {
42              throw new YawnRuntimeException(e);
43          }
44      }
45  
46  	/***
47  	 * 
48  	 */
49  	public abstract Class getBindedNetworkClass();
50  
51  
52      /***
53       * By default throws <code>java.lang.UnsupportedOperationException</code>.
54       * 
55       * @see yawn.config.NeuralNetworkConfig#setBindedNetworkClass(java.lang.Class)
56       */
57      public void setBindedNetworkClass(Class clazz) {
58          // throw new UnsupportedOperationException("method not implemented");
59      }
60  
61      /***
62       * Validates the a NeuralNetworkConfig instance.
63       * 
64       * @throws ValidationException
65       *             if validation failed
66       */
67      public void validate() throws ValidationException {
68          environmentValidate();
69          internalValidate();
70      }
71  
72      protected abstract void internalValidate() throws ValidationException;
73  
74      protected void environmentValidate() throws ValidationException {
75          getEnvironment().validate();
76      }
77  
78  	/***
79  	 * The environment in which this network will be trained.
80  	 */
81  	protected Environment environment;
82  
83  	/***
84  	 * 
85  	 */
86  	public Environment getEnvironment() {
87  		return this.environment;
88  	}
89  
90  	/***
91  	 * 
92  	 */
93  	public void setEnvironment(Environment environment) {
94  		this.environment = environment;
95  	}
96  	
97  	public abstract NeuralNetworkConfig createSampleInstance(); 
98  
99  }