linker.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 
20 #include "linker.h"
21 #include "neuralnet.h"
22 
23 namespace farsa {
24 
25 Linker::Linker( Cluster* from, Cluster* to, QString name )
26  : Updatable(name) {
27  this->fromc = from;
28  getFromVector = fromc->getDelegateFor( "outputs" );
29  fromVectorName = "outputs";
30  this->toc = to;
31  getToVector = toc->getDelegateFor( "inputs" );
32  toVectorName = "inputs";
33 }
34 
35 Linker::Linker( ConfigurationParameters& params, QString prefix )
36  : Updatable( params, prefix ) {
37  fromc = params.getObjectFromParameter<Cluster>( prefix + "from", true );
38  toc = params.getObjectFromParameter<Cluster>( prefix + "to", true );
39  if ( !fromc || !toc ) throw ClusterFromOrToMissing();
40  QString str = params.getValue( prefix + "fromVector" );
41  if ( str.isEmpty() ) {
42  getFromVector = fromc->getDelegateFor( "outputs" );
43  fromVectorName = "outputs";
44  } else {
45  getFromVector = fromc->getDelegateFor( str );
46  fromVectorName = str;
47  }
48  str = params.getValue( prefix + "toVector" );
49  if ( str.isEmpty() ) {
50  getToVector = toc->getDelegateFor( "inputs" );
51  toVectorName = "inputs";
52  } else {
53  getToVector = toc->getDelegateFor( str );
54  toVectorName = str;
55  }
56 }
57 
58 void Linker::save(ConfigurationParameters& params, QString prefix)
59 {
60  Updatable::save( params, prefix );
61  params.startObjectParameters(prefix, "Linker", this);
62  params.createParameter(prefix, "from", fromc );
63  if ( fromVectorName != "outputs" ) {
64  params.createParameter( prefix, "fromVector", fromVectorName );
65  }
66  params.createParameter(prefix, "to", toc );
67  if ( toVectorName != "inputs" ) {
68  params.createParameter( prefix, "toVector", toVectorName );
69  }
70 }
71 
72 void Linker::describe( QString type ) {
73  Updatable::describe( type );
74  Descriptor d = addTypeDescription( type, "The Linker connect two Cluster" );
75  d.describeObject( "from" ).type( "Cluster" ).props( IsMandatory ).help( "The Linker will get values from this Cluster" );
76  d.describeString( "fromVector" ).def( "outputs" ).help( "The vector on which the Linker will get values from" );
77  d.describeObject( "to" ).type( "Cluster" ).props( IsMandatory ).help( "The Linker will write values to this Cluster" );
78  d.describeString( "toVector" ).def( "inputs" ).help( "The vector on which the Linker will write values to" );
79 }
80 
81 }