nn_assoc.h

Go to the documentation of this file.
00001 #include <boost/numeric/ublas/matrix.hpp>
00002 #include <boost/numeric/ublas/vector.hpp>
00003 #include "object.h"
00004 #include "values.h"
00005 
00006 
00007 #ifndef NN_ASSOC_H
00008 #define NN_ASSOC_H
00009 
00010 namespace mimas {
00017   class nn_assoc: public object
00018 {
00019   public:
00020       typedef boost::numeric::ublas::matrix< double > Matrix;
00021       typedef boost::numeric::ublas::vector< double > Vector;
00022 
00023   private:
00024     Matrix weights;
00025     
00026 
00027    
00028   public:
00029     nn_assoc(void); 
00030     void train(Matrix& input_data, Matrix& target_data); 
00031       Vector recall(Vector& x); 
00032     void useWeights(Matrix& weight_matrix); 
00033     Matrix getWeights(void); 
00034 };
00035 
00036 
00037 nn_assoc::nn_assoc()
00038 {
00039 }
00040 
00041 void nn_assoc::train(Matrix& x, Matrix& y)
00042 {
00043   Matrix s, t, curweights;
00044 
00045    MMERROR( x.size1() == y.size1(), mimasexception, ,
00046             "nn_assoc::train - input/output matrix rows not equal" );
00047 
00048   // initialise weight matrix
00049   weights.resize( x.size2(), y.size2() );
00050   curweights.resize( x.size2(), y.size2() );
00051 
00052    // The following line was breaking charRecog (uninitialised matrix!).
00053    // weights = weights + prod( trans( x ), y );
00054    weights = prod( trans( x ), y );
00055 
00056   //weights.save("hebb.weights");
00057 }
00058 
00059 nn_assoc::Vector nn_assoc::recall(Vector& x)
00060 {
00061    MMERROR( x.size() == weights.size1(),
00062             mimasexception, ,
00063             "nn_assoc::recall - input vector has incorrect dimensions" );
00064 
00065   Vector y( prod( x, weights ) );
00066 
00067   double ymax=-1.0;
00068   double ymin=MAXDOUBLE;
00069 
00070   for (int i=0; i<(signed)y.size(); i++)
00071   {
00072     if ((ymax) < y(i)) ymax=y(i);
00073     if ((ymin) > y(i)) ymin=y(i);
00074   }
00075 
00076   return y;
00077   
00078   
00079 }
00080 
00081 
00082 // use the weights given by weight_matrix;
00083 void nn_assoc::useWeights(Matrix& weight_matrix)
00084 {
00085    //if (weights.initialised()) weights.clear();
00086   weights=weight_matrix;
00087 }
00088 
00089 
00090 // return the weights that are stored 
00091 nn_assoc::Matrix nn_assoc::getWeights(void)
00092 {
00093   return weights;
00094 }
00095 }
00096 #endif

[GNU/Linux] [Qt] [Mesa] [STL] [Lapack] [Boost] [Magick++] [Xalan-C and Xerces-C] [doxygen] [graphviz] [FFTW] [popt] [xine] [Gnuplot] [gnu-arch] [gcc] [gstreamer] [autoconf/automake/make] [freshmeat.net] [opensource.org] [sourceforge.net] [MMVL]
mimas 2.1 - Copyright Mon Oct 30 11:31:17 2006, Bala Amavasai, Stuart Meikle, Arul Selvan, Fabio Caparrelli, Jan Wedekind, Manuel Boissenin, ...