View Javadoc

1   /***
2    * 
3    */
4   package yawn.nn.fuzzyartmap;
5   
6   import java.lang.reflect.InvocationTargetException;
7   
8   import org.apache.commons.beanutils.BeanUtils;
9   import org.apache.commons.logging.Log;
10  import org.apache.commons.logging.LogFactory;
11  import org.jgap.Chromosome;
12  import org.jgap.Gene;
13  import org.jgap.impl.BooleanGene;
14  import org.jgap.impl.DoubleGene;
15  
16  import yawn.YawnRuntimeException;
17  import yawn.config.NeuralNetworkConfig;
18  import yawn.nn.NeuralNetwork;
19  import yawn.nn.committee.NetworkCommittee;
20  import yawn.nn.committee.functions.Popularity;
21  import yawn.optim.genetic.JGapAdapter;
22  
23  /***
24   * This is yawn.nn.fuzzyartmap.FuzzyArtMapJGapAdapter, part of the yawn project.
25   * 
26   * <p>$Id: FuzzyArtMapJGapAdapter.java,v 1.3 2005/04/20 18:55:15 supermarti Exp $</p>
27   * 
28   * @author Luis Mart&iacute; (luis dot marti at uc3m dot es)
29   * @version $Revision: 1.3 $
30   */
31  public class FuzzyArtMapJGapAdapter extends JGapAdapter {
32  
33      private static final Log log = LogFactory.getLog(FuzzyArtMapJGapAdapter.class);
34  
35      /***
36       * 
37       */
38      private static final long serialVersionUID = 3257002159559226420L;
39  
40      /***
41       * 
42       */
43      public FuzzyArtMapJGapAdapter(FuzzyArtMapConfig config) {
44          super(config);
45      }
46  
47      /*
48       * (non-Javadoc)
49       * 
50       * @see yawn.optim.JGapBrigde#getSampleChromosome()
51       */
52      public Chromosome getSampleChromosome() {
53          Gene alphaAGene = new DoubleGene(0.0000000001, 1);
54          Gene alphaBGene = new DoubleGene(0.0000000001, 1);
55          Gene betaAGene = new DoubleGene(0, 1);
56          Gene betaBGene = new DoubleGene(0, 1);
57          Gene vigilanceAGene = new DoubleGene(0, 1);
58          Gene vigilanceBGene = new DoubleGene(0, 1);
59          // Gene epsilonGene = new DoubleGene(0.0000000001, 1);
60          Gene complementCodingGene = new BooleanGene();
61  
62          // Gene[] genes = { alphaAGene, alphaBGene, betaAGene, betaBGene,
63          // epsilonGene, complementCodingGene };
64          Gene[] genes = { vigilanceAGene/*,
65                  vigilanceBGene */};
66  
67          Chromosome res = new Chromosome(genes);
68          return res;
69      }
70  
71      protected NeuralNetworkConfig prepareConfig() {
72          FuzzyArtMapConfig res = new FuzzyArtMapConfig();
73  
74          try {
75              BeanUtils.copyProperties(res, templateConfig);
76          } catch (IllegalAccessException e) {
77              log.debug(e);
78              throw new YawnRuntimeException(e);
79          } catch (InvocationTargetException e) {
80              log.debug(e);
81              throw new YawnRuntimeException(e);
82          }
83          return res;
84      }
85  
86      protected NeuralNetwork buildNeuralNetworkFromChromosome(Chromosome chromosome) {
87          FuzzyArtMapConfig config = (FuzzyArtMapConfig) prepareConfig();
88          Gene[] genes = chromosome.getGenes();
89          //config.setAlphaArtA(((DoubleGene) genes[0]).doubleValue());
90          //config.setAlphaArtB(((DoubleGene) genes[1]).doubleValue());
91          //config.setBetaArtA(((DoubleGene) genes[2]).doubleValue());
92          //config.setBetaArtB(((DoubleGene) genes[3]).doubleValue());
93          config.setVigilanceArtA(((DoubleGene) genes[0]).doubleValue());
94          //config.setVigilanceArtB(((DoubleGene) genes[1]).doubleValue());
95          // config.setEpsilon(((DoubleGene) genes[4]).doubleValue());
96          // config.setUseComplementCoding(((BooleanGene)
97          // genes[0]).booleanValue());
98  		
99          NetworkCommittee com = new NetworkCommittee(new Popularity());
100         
101         for (int i = 0; i < COMMITTEE_SIZE; i++){
102 			com.addCommitteeMembers(config.configuredNetworkFactory());
103         }
104         com.setSerialProcessing(false);
105         return com;
106     }
107 	
108 	private static final int COMMITTEE_SIZE= 3;
109 }