nnfw/include/neuralnet.h
Go to the documentation of this file.
00001 /******************************************************************************** 00002 * Neural Network Framework. * 00003 * Copyright (C) 2005-2011 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 00028 #include "nnfwconfig.h" 00029 #include <parametersettable.h> 00030 #include "cluster.h" 00031 #include "linker.h" 00032 00033 namespace farsa { 00034 00209 class FARSA_NNFW_API NeuralNet : public ParameterSettableWithConfigureFunction { 00210 public: 00212 NeuralNet(); 00214 ~NeuralNet(); 00219 void setName( QString name ) { 00220 namev = name; 00221 }; 00223 QString name() { 00224 return namev; 00225 }; 00229 void addCluster( Cluster* c, bool isInput = false, bool isOutput = false ); 00232 void addInputCluster( Cluster* c ) { 00233 addCluster( c, true, false ); 00234 }; 00237 void addOutputCluster( Cluster* c ) { 00238 addCluster( c, false, true ); 00239 }; 00241 bool removeCluster( Cluster* c ); 00243 void markAsInput( Cluster* c ); 00245 void markAsOutput( Cluster* c ); 00248 void unmark( Cluster* c ); 00250 void unmarkAll(); 00252 bool isIsolated( Cluster* c ) const; 00254 ClusterList clusters() const; 00256 ClusterList inputClusters() const; 00258 ClusterList outputClusters() const; 00260 ClusterList hiddenClusters() const; 00262 void addLinker( Linker* l ); 00264 bool removeLinker( Linker* ); 00266 LinkerList linkers() const; 00268 LinkerList linkers( Cluster* c, bool out = false ) const; 00270 void setOrder( Updatable* updatables[], unsigned int dim ); 00272 void setOrder( const UpdatableList& ); 00274 UpdatableList order() const { 00275 return ups; 00276 }; 00278 void step() { 00279 for( unsigned int i=0; i<dimUps; i++ ) { 00280 ups[i]->update(); 00281 } 00282 }; 00288 void randomize( double min, double max ); 00307 template<class PointerTo> 00308 PointerTo byName( QString aName, PointerTo& aPointer ) { 00309 aPointer = dynamic_cast<PointerTo>( getByName(aName) ); 00310 return aPointer; 00311 }; 00317 Updatable* getByName( QString ); 00320 bool find( const Cluster* ) const; 00323 bool find( const Linker* ) const; 00326 bool find( const Updatable* ) const; 00337 virtual void configure(ConfigurationParameters& params, QString prefix); 00345 virtual void save(ConfigurationParameters& params, QString prefix); 00347 static void describe( QString type ); 00348 protected: 00350 QString namev; 00352 ClusterList clustersv; 00354 ClusterList inclusters; 00356 ClusterList outclusters; 00358 ClusterList hidclusters; 00360 LinkerList linkersv; 00361 00362 typedef QMap<QString, Cluster*> ClustersMap; 00364 ClustersMap clsMap; 00365 00366 typedef QMap<Cluster*, LinkerList> LinkVecMap; 00368 LinkVecMap inLinks; 00370 LinkVecMap outLinks; 00371 00372 typedef QMap<QString, Linker*> LinkersMap; 00374 LinkersMap lksMap; 00375 00377 UpdatableList ups; 00378 unsigned int dimUps; 00379 }; 00380 00381 } 00382 00383 #endif 00384