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 
209 class FARSA_NNFW_API NeuralNet : public ParameterSettableWithConfigureFunction {
210 public:
212  NeuralNet();
214  ~NeuralNet();
219  void setName( QString name ) {
220  namev = name;
221  };
223  QString name() {
224  return namev;
225  };
229  void addCluster( Cluster* c, bool isInput = false, bool isOutput = false );
233  addCluster( c, true, false );
234  };
238  addCluster( c, false, true );
239  };
241  bool removeCluster( Cluster* c );
243  void markAsInput( Cluster* c );
245  void markAsOutput( Cluster* c );
248  void unmark( Cluster* c );
250  void unmarkAll();
252  bool isIsolated( Cluster* c ) const;
254  ClusterList clusters() const;
256  ClusterList inputClusters() const;
258  ClusterList outputClusters() const;
260  ClusterList hiddenClusters() const;
262  void addLinker( Linker* l );
264  bool removeLinker( Linker* );
266  LinkerList linkers() const;
268  LinkerList linkers( Cluster* c, bool out = false ) const;
270  void setOrder( Updatable* updatables[], unsigned int dim );
272  void setOrder( const UpdatableList& );
274  UpdatableList order() const {
275  return ups;
276  };
278  void step() {
279  for( unsigned int i=0; i<dimUps; i++ ) {
280  ups[i]->update();
281  }
282  };
288  void randomize( double min, double max );
307  template<class PointerTo>
308  PointerTo byName( QString aName, PointerTo& aPointer ) {
309  aPointer = dynamic_cast<PointerTo>( getByName(aName) );
310  return aPointer;
311  };
317  Updatable* getByName( QString );
320  bool find( const Cluster* ) const;
323  bool find( const Linker* ) const;
326  bool find( const Updatable* ) const;
337  virtual void configure(ConfigurationParameters& params, QString prefix);
345  virtual void save(ConfigurationParameters& params, QString prefix);
347  static void describe( QString type );
348 protected:
350  QString namev;
352  ClusterList clustersv;
354  ClusterList inclusters;
356  ClusterList outclusters;
358  ClusterList hidclusters;
360  LinkerList linkersv;
361 
362  typedef QMap<QString, Cluster*> ClustersMap;
364  ClustersMap clsMap;
365 
366  typedef QMap<Cluster*, LinkerList> LinkVecMap;
368  LinkVecMap inLinks;
370  LinkVecMap outLinks;
371 
372  typedef QMap<QString, Linker*> LinkersMap;
374  LinkersMap lksMap;
375 
377  UpdatableList ups;
378  unsigned int dimUps;
379 };
380 
381 }
382 
383 #endif
384