outputfunction.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 OUTPUTFUNCTION_H
21 #define OUTPUTFUNCTION_H
22 
28 #include "nnfwconfig.h"
29 #include <parametersettable.h>
30 #include <configurationparameters.h>
31 #include <QRegExp>
32 
33 namespace farsa {
34 
39 class FARSA_NNFW_TEMPLATE OutputFunction : public ParameterSettableWithConfigureFunction {
40 public:
42  OutputFunction() : clusterv(NULL), tmp1(1), tmp2(1) { /*nothing to do*/ };
44  virtual ~OutputFunction() { /*nothing to do*/ };
46  virtual void apply( DoubleVector& inputs, DoubleVector& outputs ) = 0;
48  double apply( double input ) {
49  tmp1[0] = input;
50  apply( tmp1, tmp2 );
51  return tmp2[0];
52  };
59  virtual bool derivate( const DoubleVector& inputs, const DoubleVector& outputs, DoubleVector& derivates ) const {
60  Q_UNUSED( inputs );
61  Q_UNUSED( outputs );
62  Q_UNUSED( derivates );
63  return false;
64  };
68  void setCluster( Cluster* cl ) {
69  if ( clusterv != NULL ) throw OutputFunctionSetClusterException();
70  clusterv = cl;
71  clusterSetted();
72  };
73 protected:
77  virtual void clusterSetted() { /* nothing to do */ };
79  Cluster* clusterv;
80 private:
82  DoubleVector tmp1;
84  DoubleVector tmp2;
85 };
86 
87 }
88 
89 #endif