nnfw/src/libcompetitivefunctions.cpp
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 #include "libcompetitivefunctions.h" 00021 #include <cmath> 00022 00023 namespace farsa { 00024 00025 WinnerTakeAllFunction::WinnerTakeAllFunction( double value ) 00026 : OutputFunction() { 00027 valuev = value; 00028 } 00029 00030 bool WinnerTakeAllFunction::setValue( double v ) { 00031 valuev = v; 00032 return true; 00033 } 00034 00035 double WinnerTakeAllFunction::value() { 00036 return valuev; 00037 } 00038 00039 void WinnerTakeAllFunction::apply( DoubleVector& inputs, DoubleVector& outputs ) { 00040 outputs.zeroing(); 00041 outputs[ maxIndex( inputs ) ] = valuev; 00042 } 00043 00044 void WinnerTakeAllFunction::configure(ConfigurationParameters& params, QString prefix) 00045 { 00046 valuev = 1.0; 00047 QString str = params.getValue(prefix + "value"); 00048 if (!str.isEmpty()) { 00049 bool ok; 00050 valuev = str.toDouble(&ok); 00051 if (!ok) { 00052 valuev = 1.0; 00053 } 00054 } 00055 } 00056 00057 void WinnerTakeAllFunction::save(ConfigurationParameters& params, QString prefix) 00058 { 00059 params.startObjectParameters(prefix, "WinnerTakeAllFunction", this); 00060 params.createParameter(prefix, "value", QString::number(valuev)); 00061 } 00062 00063 void WinnerTakeAllFunction::describe( QString type ) { 00064 Descriptor d = addTypeDescription( type, "Winner Take All Output function" ); 00065 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"); 00066 } 00067 00068 } 00069