View Javadoc

1   /*
2    * Created on 16-feb-2005
3    */
4   package yawn.envs.synthetic;
5   
6   import org.apache.commons.math.random.RandomData;
7   import org.apache.commons.math.random.RandomDataImpl;
8   
9   import yawn.util.Pattern;
10  
11  /***
12   * This is yawn.envs.synthetic.XOrDataEnvironment part of the yawn project.
13   * 
14   * <p>$Id: XOrDataEnvironment.java,v 1.5 2005/05/09 11:04:56 supermarti Exp $</p>
15   * 
16   * @author Luis Mart&iacute; (luis dot marti at uc3m dot es)
17   * @version $Revision: 1.5 $
18   */
19  public class XOrDataEnvironment extends SyntheticDataEnvironment {
20      protected static final double[][] inputSpace = { { 0, 0 }, { 0, 1 }, { 1, 0 }, { 1, 1 } };
21  
22  	/***
23  	 * 
24  	 * @uml.property name="randomer"
25  	 * @uml.associationEnd multiplicity="(1 1)"
26  	 */
27  	private RandomData randomer = new RandomDataImpl();
28  
29      protected static final double[] ONE_PAT = { 1 };
30  
31      protected static final double[] ZERO_PAT = { 0 };
32  
33      /*
34       * (non-Javadoc)
35       * 
36       * @see yawn.envs.synthetic.SyntheticDataEnvironment#generateRandomInput()
37       */
38      protected Pattern generateRandomInput() {
39          return new Pattern(inputSpace[randomer.nextSecureInt(0, inputSpace.length)]);
40      }
41  
42      /***
43       * (non-Javadoc)
44       * 
45       * @see yawn.envs.synthetic.SyntheticDataEnvironment#synthetizeOutput(yawn.util.Pattern)
46       */
47      protected Pattern synthetizeOutput(Pattern input) {
48          if ((input.norm1() > 0) && (input.norm1() < 2)) {
49              return new Pattern(ONE_PAT);
50          }
51          return new Pattern(ZERO_PAT);
52      }
53  }