InputGeneratorFour.hpp

Go to the documentation of this file.
00001 //-----------------------------------------------------------------------------
00002 // Author: Jim Holmström
00003 // Date:   2002-02-13
00004 //-----------------------------------------------------------------------------
00005 
00006 #ifndef __INPUTGENERATORFOUR_H
00007 #define __INPUTGENERATORFOUR_H
00008 
00009 #include <Random.hpp>
00010 #include "IInputGenerator.hpp"
00011 #include <GNGRepresentation/IGLInputRepresentation.hpp>
00012 
00013 #include <cstdlib>
00014 #include <cmath>
00015 #include <GL/glut.h>
00016 
00020 class InputGeneratorFour : public IInputGenerator
00021 {
00022 public:
00023   InputGeneratorFour(IInputGenerator * ig, double scale) : m_inputGenerator(*ig)
00024   {
00025     m_dimension = m_inputGenerator.GetDimension();
00026     if(m_dimension != 2)
00027       throw Exception("FourInput::Constructor:: Illegal dimension. Must be 2");
00028 
00029     m_scale = scale;
00030     
00031     m_vector.push_back(0.0);
00032     m_vector.push_back(0.0);
00033 
00034     Vector v = ig->GetOutput();
00035     unsigned int theSize = 4*v.size();
00036     for(unsigned int i=0; i<theSize; i++)
00037         m_output.push_back(0.0);    
00038   }
00039 
00040   virtual ~InputGeneratorFour() 
00041   { 
00042     delete &m_inputGenerator; 
00043   }
00044   
00048   virtual Vector GetInput()
00049   {
00050     Vector v(m_dimension);
00051 
00052     // Get an input signal from the IG. and scale it.
00053     v = m_inputGenerator.GetInput() * m_scale;
00054         
00055     // Decide which quadrant it should be in and create the translation
00056     double quadrant = Random::RandomizePositive();
00057     Vector translation(m_dimension);
00058     
00059     Vector output = m_inputGenerator.GetOutput();
00060     unsigned int theClass = 0;
00061     unsigned int outputSize = output.size();
00062     
00063     for(unsigned int i=0; i<m_output.size(); i++)
00064       m_output[i] = 0.0;            
00065       
00066     for(unsigned int i=0; i<outputSize; i++)
00067     {
00068       if(output[i] == 1.0)
00069       {
00070         theClass = i;
00071         break;
00072       }
00073     }
00074  
00075 
00076     //quadrant 0
00077     if(quadrant < 0.25)
00078     {
00079       translation[0] = 1 - m_scale;
00080       translation[1] = 1 - m_scale;
00081       m_output[theClass] = 1.0;            
00082     }    
00083     else
00084     //quadrant 1
00085     if(quadrant < 0.50)
00086     {
00087       translation[0] = -1 + m_scale;
00088       translation[1] = 1 - m_scale;
00089       m_output[1 * outputSize + theClass] = 1.0;            
00090     }    
00091     else
00092     //quadrant 2
00093     if(quadrant < 0.75)
00094     {
00095       translation[0] = -1 + m_scale;
00096       translation[1] = -1 + m_scale;
00097       m_output[2 * outputSize + theClass] = 1.0;            
00098     }    
00099     else
00100     //quadrant 3
00101     if(quadrant <= 1.0)
00102     {
00103       translation[0] = 1 - m_scale;
00104       translation[1] = -1 + m_scale;
00105       m_output[3 * outputSize + theClass] = 1.0;            
00106     }    
00107        
00108     m_vector = v + translation;     
00109     return m_vector;
00110   }
00111   
00112     virtual Vector GetOutput() 
00113     { 
00114         return m_output; 
00115     }
00116 
00120   virtual Vector const & GetLastInput() const { return m_vector; }
00121 
00125   virtual unsigned int GetDimension() const { return m_inputGenerator.GetDimension(); }
00126 
00130   double GetScale() { return m_scale; }
00131 
00135   virtual GeneratorType GetGeneratorType() const { return ClassesGenerator; }
00136 
00137 protected:
00138   unsigned int         m_dimension;
00139   double               m_scale;
00140   IInputGenerator &    m_inputGenerator;
00141   Vector               m_vector;
00142 };
00143 
00144 
00148 class InputRepresentationFour : public IGLInputRepresentation
00149 {
00150 public:
00151   InputRepresentationFour(InputGeneratorFour * i, IGLInputRepresentation * r) 
00152   : m_inputGenerator(*i), m_inputRepresentation(*r) {}
00153 
00154     virtual ~InputRepresentationFour()
00155     {
00156         delete &m_inputRepresentation;
00157     }
00158   
00159   virtual void GLOutputDistribution() const
00160   {
00161     // draw the areas of the distribution.
00162     double d = m_inputGenerator.GetScale();
00163 
00164     // quadrant 0
00165     glPushMatrix();
00166      glTranslatef(-1+d,1-d,0);
00167      glScalef(d,d,0);
00168      m_inputRepresentation.GLOutputDistribution();
00169     glPopMatrix();
00170     // quadrant 1
00171     glPushMatrix();
00172      glTranslatef(-1+d,-1+d,0);
00173      glScalef(d,d,0);
00174      m_inputRepresentation.GLOutputDistribution();
00175     glPopMatrix();
00176     // quadrant 2
00177     glPushMatrix();
00178      glTranslatef(1-d,-1+d,0);
00179      glScalef(d,d,0);
00180      m_inputRepresentation.GLOutputDistribution();
00181     glPopMatrix();
00182     // quadrant 3
00183     glPushMatrix();
00184      glTranslatef(1-d,1-d,0);
00185      glScalef(d,d,0);
00186      m_inputRepresentation.GLOutputDistribution();
00187     glPopMatrix();
00188   }
00189   
00190   virtual void GLOutputSignal() const
00191   {
00192     // draw the last input point.
00193     Vector const & v = m_inputGenerator.GetLastInput();
00194     glBegin(GL_POINTS);
00195     {           
00196       glVertex2d(v[0], v[1]);
00197     }    
00198     glEnd();
00199   }
00200   
00201 private:
00202   InputGeneratorFour &       m_inputGenerator;
00203   IGLInputRepresentation &   m_inputRepresentation;
00204 };
00205 
00206 #endif
00207 

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