neuralnet.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Neural Network Framework. *
3  * Copyright (C) 2005-2011 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #ifndef NEURALNET_H
21 #define NEURALNET_H
22 
28 #include "nnfwconfig.h"
29 #include <parametersettable.h>
30 #include "cluster.h"
31 #include "linker.h"
32 
33 namespace farsa {
34 
40 public:
42  virtual ~NeuralNetObserver() { }
44  virtual void onStepDone() { };
45 };
46 
221 class FARSA_NNFW_API NeuralNet : public ParameterSettableWithConfigureFunction {
222 public:
224  NeuralNet();
226  ~NeuralNet();
231  void setName( QString name ) {
232  namev = name;
233  };
235  QString name() {
236  return namev;
237  };
239  ParameterSettableUI* getUIManager();
241  void addObserver( NeuralNetObserver* observer );
243  void removeObserver( NeuralNetObserver* observer );
247  void addCluster( Cluster* c, bool isInput = false, bool isOutput = false );
251  addCluster( c, true, false );
252  };
256  addCluster( c, false, true );
257  };
259  bool removeCluster( Cluster* c );
261  void markAsInput( Cluster* c );
263  void markAsOutput( Cluster* c );
266  void unmark( Cluster* c );
268  void unmarkAll();
270  bool isIsolated( Cluster* c ) const;
272  ClusterList clusters() const;
274  ClusterList inputClusters() const;
276  ClusterList outputClusters() const;
278  ClusterList hiddenClusters() const;
280  void addLinker( Linker* l );
282  bool removeLinker( Linker* );
284  LinkerList linkers() const;
286  LinkerList linkers( Cluster* c, bool out = false ) const;
288  void setOrder( Updatable* updatables[], unsigned int dim );
290  void setOrder( const UpdatableList& );
292  UpdatableList order() const {
293  return ups;
294  };
296  void step() {
297  for( unsigned int i=0; i<dimUps; i++ ) {
298  ups[i]->update();
299  }
300  foreach( NeuralNetObserver* obs, observers ) {
301  obs->onStepDone();
302  }
303  };
309  void randomize( double min, double max );
328  template<class PointerTo>
329  PointerTo byName( QString aName, PointerTo& aPointer ) {
330  aPointer = dynamic_cast<PointerTo>( getByName(aName) );
331  return aPointer;
332  };
338  Updatable* getByName( QString );
341  bool find( const Cluster* ) const;
344  bool find( const Linker* ) const;
347  bool find( const Updatable* ) const;
358  virtual void configure(ConfigurationParameters& params, QString prefix);
366  virtual void save(ConfigurationParameters& params, QString prefix);
368  static void describe( QString type );
369 protected:
371  QString namev;
373  ClusterList clustersv;
375  ClusterList inclusters;
377  ClusterList outclusters;
379  ClusterList hidclusters;
381  LinkerList linkersv;
382 
383  typedef QMap<QString, Cluster*> ClustersMap;
385  ClustersMap clsMap;
386 
387  typedef QMap<Cluster*, LinkerList> LinkVecMap;
389  LinkVecMap inLinks;
391  LinkVecMap outLinks;
392 
393  typedef QMap<QString, Linker*> LinkersMap;
395  LinkersMap lksMap;
396 
398  UpdatableList ups;
399  unsigned int dimUps;
400 
402  QList<NeuralNetObserver*> observers;
403 };
404 
405 }
406 
407 #endif
408 
This file contains the common type defitions used on the whole framework.
QString namev
name of this NeuralNet
Definition: neuralnet.h:371
ClusterList outclusters
Output Clusters.
Definition: neuralnet.h:377
ClusterList clustersv
Clusters.
Definition: neuralnet.h:373
virtual ~NeuralNetObserver()
virtual destructor
Definition: neuralnet.h:42
ClustersMap clsMap
map name -> Cluster*
Definition: neuralnet.h:385
ClusterList inclusters
Input Clusters.
Definition: neuralnet.h:375
LinkerList linkersv
Linkers.
Definition: neuralnet.h:381
FARSA_UTIL_TEMPLATE const T max(const T &t1, const U &t2)
virtual void onStepDone()
called just after a complete step has been done
Definition: neuralnet.h:44
Updatables objects.
Definition: updatable.h:37
QString name()
return the name of the NeuralNet
Definition: neuralnet.h:235
void step()
Step.
Definition: neuralnet.h:296
LinkersMap lksMap
map name -> Linker*
Definition: neuralnet.h:395
void addInputCluster(Cluster *c)
Add a Cluster and mark it as Input Behave exactly the same of addCluster( c, true, false )
Definition: neuralnet.h:250
This file contains the declaration of the linkers implemented.
ClusterList hidclusters
unmarked Clusters
Definition: neuralnet.h:379
Define the common interface among Clusters.
Definition: cluster.h:73
PointerTo byName(QString aName, PointerTo &aPointer)
Search into the net for the presence of an Updatable with name aName; on success set the pointer aPoi...
Definition: neuralnet.h:329
The Neural Network Class.
Definition: neuralnet.h:221
An observer interface called during NeuralNet operations.
Definition: neuralnet.h:39
LinkVecMap outLinks
map of outgoing linkers (cluster -> vettore linkers uscenti)
Definition: neuralnet.h:391
Abstract Linker Class.
Definition: linker.h:38
void addOutputCluster(Cluster *c)
Add a Cluster and mark it as Output Behave exactly the same of addCluster( c, false, true )
Definition: neuralnet.h:255
This file contains the declarations of the Cluster class.
FARSA_UTIL_TEMPLATE const T min(const T &t1, const U &t2)
void setName(QString name)
Set the name of the NeuralNet It's useful when loading from ConfigurationParameters more than NeuralN...
Definition: neuralnet.h:231
UpdatableList ups
Array of Updateables ordered as specified.
Definition: neuralnet.h:398
UpdatableList order() const
Return the order.
Definition: neuralnet.h:292
QList< NeuralNetObserver * > observers
the List of Observers
Definition: neuralnet.h:402
LinkVecMap inLinks
mappa dei linkers entranti (cluster -> vettore linkers entranti)
Definition: neuralnet.h:389