nnfw/src/linker.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 "linker.h"
00021 #include "neuralnet.h"
00022 
00023 namespace farsa {
00024 
00025 Linker::Linker( Cluster* from, Cluster* to, QString name )
00026     : Updatable(name) {
00027     this->fromc = from;
00028     getFromVector = fromc->getDelegateFor( "outputs" );
00029     fromVectorName = "outputs";
00030     this->toc = to;
00031     getToVector = toc->getDelegateFor( "inputs" );
00032     toVectorName = "inputs";
00033 }
00034 
00035 Linker::Linker( ConfigurationParameters& params, QString prefix )
00036     : Updatable( params, prefix ) {
00037     fromc = params.getObjectFromParameter<Cluster>( prefix + "from", true );
00038     toc = params.getObjectFromParameter<Cluster>( prefix + "to", true );
00039     if ( !fromc || !toc ) throw ClusterFromOrToMissing();
00040     QString str = params.getValue( prefix + "fromVector" );
00041     if ( str.isEmpty() ) {
00042         getFromVector = fromc->getDelegateFor( "outputs" );
00043         fromVectorName = "outputs";
00044     } else {
00045         getFromVector = fromc->getDelegateFor( str );
00046         fromVectorName = str;
00047     }
00048     str = params.getValue( prefix + "toVector" );
00049     if ( str.isEmpty() ) {
00050         getToVector = toc->getDelegateFor( "inputs" );
00051         toVectorName = "inputs";
00052     } else {
00053         getToVector = toc->getDelegateFor( str );
00054         toVectorName = str;
00055     }
00056 }
00057 
00058 void Linker::save(ConfigurationParameters& params, QString prefix)
00059 {
00060     Updatable::save( params, prefix );
00061     params.startObjectParameters(prefix, "Linker", this);
00062     params.createParameter(prefix, "from", fromc );
00063     if ( fromVectorName != "outputs" ) {
00064         params.createParameter( prefix, "fromVector", fromVectorName );
00065     }
00066     params.createParameter(prefix, "to", toc );
00067     if ( toVectorName != "inputs" ) {
00068         params.createParameter( prefix, "toVector", toVectorName );
00069     }
00070 }
00071 
00072 void Linker::describe( QString type ) {
00073     Updatable::describe( type );
00074     Descriptor d = addTypeDescription( type, "The Linker connect two Cluster" );
00075     d.describeObject( "from" ).type( "Cluster" ).props( IsMandatory ).help( "The Linker will get values from this Cluster" );
00076     d.describeString( "fromVector" ).def( "outputs" ).help( "The vector on which the Linker will get values from" );
00077     d.describeObject( "to" ).type( "Cluster" ).props( IsMandatory ).help( "The Linker will write values to this Cluster" );
00078     d.describeString( "toVector" ).def( "inputs" ).help( "The vector on which the Linker will write values to" );
00079 }
00080 
00081 }