libcompetitivefunctions.cpp
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 
21 #include <cmath>
22 
23 namespace farsa {
24 
26  : OutputFunction() {
27  valuev = value;
28 }
29 
31  valuev = v;
32  return true;
33 }
34 
36  return valuev;
37 }
38 
39 void WinnerTakeAllFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) {
40  outputs.setZero();
41  int index = 0;
42  inputs.maxCoeff(&index);
43  outputs[ index ] = valuev;
44 }
45 
47 {
48  valuev = 1.0;
49  QString str = params.getValue(prefix + "value");
50  if (!str.isEmpty()) {
51  bool ok;
52  valuev = str.toDouble(&ok);
53  if (!ok) {
54  valuev = 1.0;
55  }
56  }
57 }
58 
60 {
61  params.startObjectParameters(prefix, "WinnerTakeAllFunction", this);
62  params.createParameter(prefix, "value", QString::number(valuev));
63 }
64 
65 void WinnerTakeAllFunction::describe( QString type ) {
66  Descriptor d = addTypeDescription( type, "Winner Take All Output function" );
67  d.describeReal( "value" ).def(1.0).limits(1, +Infinity).help("The output value assumed by the winner (the most activated neuron); all other neurons will have 0.0 as output value");
68 }
69 
70 }
71 
double value()
Return the value.
OutputFunction Class.
bool setValue(double v)
Set the value.
static const double Infinity
WinnerTakeAllFunction(double value=1.0)
Construct.
virtual void save(ConfigurationParameters &params, QString prefix)
Save the actual status of parameters into the ConfigurationParameters object passed.
virtual void configure(ConfigurationParameters &params, QString prefix)
Configures the object using a ConfigurationParameters object.
bool startObjectParameters(QString groupPath, QString typeName, ParameterSettable *object)
static Descriptor addTypeDescription(QString type, QString shortHelp, QString longHelp=QString(""))
QString getValue(QString path, bool alsoMatchParents=false) const
Library of Competitive OutputFunction.
void createParameter(QString groupPath, QString parameter)
virtual void apply(DoubleVector &inputs, DoubleVector &outputs)
Implement the WinnerTakeAllFunction function.
static void describe(QString)
describe the parameters and subgroups for configure it