include/neuralnet.h

Go to the documentation of this file.
00001 /********************************************************************************
00002  *  Neural Network Framework.                                                   *
00003  *  Copyright (C) 2005-2008 Gianluca Massera <emmegian@yahoo.it>                *
00004  *                                                                              *
00005  *  This program is free software; you can redistribute it and/or modify        *
00006  *  it under the terms of the GNU General Public License as published by        *
00007  *  the Free Software Foundation; either version 2 of the License, or           *
00008  *  (at your option) any later version.                                         *
00009  *                                                                              *
00010  *  This program is distributed in the hope that it will be useful,             *
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of              *
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               *
00013  *  GNU General Public License for more details.                                *
00014  *                                                                              *
00015  *  You should have received a copy of the GNU General Public License           *
00016  *  along with this program; if not, write to the Free Software                 *
00017  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA  *
00018  ********************************************************************************/
00019 
00020 #ifndef NEURALNET_H
00021 #define NEURALNET_H
00022 
00031 #include "types.h"
00032 #include "clonable.h"
00033 #include "cluster.h"
00034 #include "linker.h"
00035 #include <map>
00036 #include <string>
00037 
00038 namespace nnfw {
00039 
00046 class NNFW_API BaseNeuralNet : public Clonable {
00047 public:
00050 
00053     BaseNeuralNet();
00054 
00057     ~BaseNeuralNet();
00058 
00060 
00062 
00067     void addCluster( Cluster* c, bool isInput = false, bool isOutput = false );
00068 
00072     void addInputCluster( Cluster* c ) {
00073         addCluster( c, true, false );
00074     };
00075 
00079     void addOutputCluster( Cluster* c ) {
00080         addCluster( c, false, true );
00081     };
00082 
00085     bool removeCluster( Cluster* c );
00086 
00089     void markAsInput( Cluster* c );
00090 
00093     void markAsOutput( Cluster* c );
00094 
00098     void unmark( Cluster* c );
00099 
00102     void unmarkAll();
00103 
00105     bool isIsolated( Cluster* c ) const;
00106 
00108     const ClusterVec& clusters() const;
00109 
00111     const ClusterVec& inputClusters() const;
00112 
00114     const ClusterVec& outputClusters() const;
00115 
00117     const ClusterVec& hiddenClusters() const;
00118 
00120     void addLinker( Linker* l );
00121 
00124     bool removeLinker( Linker* );
00125 
00128     const LinkerVec& linkers() const;
00129 
00132     const LinkerVec& linkers( Cluster* c, bool out = false ) const;
00133 
00136     void setOrder( Updatable* updatables[], u_int dim );
00137 
00140     void setOrder( const UpdatableVec& );
00141 
00144     const UpdatableVec& order() const {
00145         return ups;
00146     };
00147 
00150     void step() {
00151         for( u_int i=0; i<dimUps; i++ ) {
00152             ups[i]->update();
00153         }
00154     };
00155 
00161     void randomize( Real min, Real max );
00162 
00181     template<class PointerTo>
00182     PointerTo byName( const char* aName, PointerTo& aPointer ) {
00183         aPointer = dynamic_cast<PointerTo>( getByName(aName) );
00184         return aPointer;
00185     };
00186 
00192     Updatable* getByName( const char* );
00193 
00196     bool find( const Cluster* ) const;
00197 
00200     bool find( const Linker* ) const;
00201 
00204     bool find( const Updatable* ) const;
00205 
00207     BaseNeuralNet* clone() const;
00208 
00210 
00211 protected:
00213     ClusterVec clustersv;
00215     ClusterVec inclusters;
00217     ClusterVec outclusters;
00219     ClusterVec hidclusters;
00221     LinkerVec  linkersv;
00222 
00223     typedef std::map<std::string, Cluster*> ClustersMap;
00225     ClustersMap clsMap;
00226     class ids4t {
00227     public:
00228         int& operator[]( int i ) { return ids[i]; };
00229         int ids[4];
00230     };
00231     //typedef int ids4t [4];
00232     typedef std::map<Cluster*, ids4t> IdsMap;
00234     IdsMap clsIdsMap;
00235 
00236     typedef std::map<Cluster*, LinkerVec> LinkVecMap;
00238     LinkVecMap inLinks;
00240     LinkVecMap outLinks;
00241 
00242     typedef std::map<std::string, Linker*> LinkersMap;
00244     LinkersMap lksMap;
00245     typedef std::map<Linker*, ids4t> IdsMapL;
00246     IdsMapL lksIdsMap;
00247 
00249     UpdatableVec ups;
00250     unsigned int dimUps;
00251 };
00252 
00253 }
00254 
00255 #endif
00256 
BerliOS Developer Logo Valid XHTML 1.0 Transitional Valid CSS!