InputGeneratorXOR.hpp

Go to the documentation of this file.
00001 #ifndef __INPUTGENERATORXOR_H
00002 #define __INPUTGENERATORXOR_H
00003 
00004 #include "IInputGenerator.hpp"
00005 
00010 class InputGeneratorXOR : public IInputGenerator
00011 {
00012 public: 
00013   InputGeneratorXOR()
00014   {
00015     m_dimension = 2;
00016     m_min = 0.0;
00017     m_max = 1.0;
00018 
00019     m_input.push_back(0.0);
00020     m_input.push_back(0.0);
00021     m_output.push_back(0.0);
00022   }
00023 
00027   virtual Vector GetInput()
00028   {    
00029     if(Random::RandomizePositive() < 0.5)
00030       m_input[0] = 0.0;
00031     else 
00032       m_input[0] = 1.0;
00033 
00034     if(Random::RandomizePositive() < 0.5)
00035       m_input[1] = 0.0;
00036     else 
00037       m_input[1] = 1.0;
00038     
00039     if(m_input[0] + m_input[1] == 1.0) // xor
00040       m_output[0] = 1.0;
00041     else 
00042       m_output[0] = 0.0;
00043 
00044     return m_input;
00045   }
00046     
00050   virtual Vector GetOutput()
00051   {
00052     return m_output;
00053   }
00054 
00058   virtual Vector const & GetLastInput() const { return m_input; }  
00059 
00063   virtual unsigned int GetDimension() const { return m_dimension; }
00064 
00068   virtual GeneratorType GetGeneratorType() const { return FunctionGenerator; }
00069   
00070 protected:
00071   unsigned int m_dimension;
00072   double m_min;
00073   double m_max;
00074   Vector m_input;  
00075 };
00076 
00077 
00081 class InputRepresentationXOR : public IGLInputRepresentation
00082 {
00083 public:
00084   InputRepresentationXOR(InputGeneratorXOR * i) : m_inputGenerator(*i) {}
00085     ~InputRepresentationXOR() {}
00086 
00087   virtual void GLOutputDistribution() const
00088   {
00089     glBegin(GL_POINTS);
00090     {           
00091       glColor4f(0.6, 0.6, 0.6, 1.0);
00092       glVertex2d(0, 1);
00093       glVertex2d(1, 0);
00094       glColor4f(0.8, 0.8, 0.8, 1.0);
00095       glVertex2d(1, 1);
00096       glVertex2d(0, 0);
00097     }    
00098     glEnd();
00099   }
00100   
00101   virtual void GLOutputSignal() const 
00102   {    
00103     Vector const & v = m_inputGenerator.GetLastInput();
00104     glBegin(GL_POINTS);
00105     {           
00106       glVertex2d(v[0], v[1]);
00107     }    
00108     glEnd();
00109   }
00110   
00111 private:
00112   InputGeneratorXOR & m_inputGenerator;
00113 };
00114 
00115 
00116 #endif

Generated on Mon Mar 22 16:40:48 2004 for GNG_GL by doxygen 1.3.6