Marsyas  0.5.0-beta1
/Users/jleben/code/marsyas/src/marsyas/marsystems/ANN_node.cpp
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2010 George Tzanetakis <gtzan@cs.princeton.edu>
00003 **
00004 ** This program is free software; you can redistribute it and/or modify
00005 ** it under the terms of the GNU General Public License as published by
00006 ** the Free Software Foundation; either version 2 of the License, or
00007 ** (at your option) any later version.
00008 **
00009 ** This program is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 ** GNU General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU General Public License
00015 ** along with this program; if not, write to the Free Software
00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 */
00018 
00019 #include "ANN_node.h"
00020 #include "../common_source.h"
00021 
00022 
00023 using std::ostringstream;
00024 
00025 using namespace Marsyas;
00026 
00027 ANN_node::ANN_node(mrs_string name):MarSystem("ANN_node", name)
00028 {
00029   //type_ = "ANN_node";
00030   //name_ = name;
00031 
00032   addControls();
00033 }
00034 
00035 
00036 ANN_node::~ANN_node()
00037 {
00038 }
00039 
00040 
00041 MarSystem*
00042 ANN_node::clone() const
00043 {
00044   return new ANN_node(*this);
00045 }
00046 
00047 void
00048 ANN_node::addControls()
00049 {
00050   addctrl("mrs_realvec/weights", weights_);
00051   setctrlState("mrs_realvec/weights", true);
00052   addctrl("mrs_real/bias", bias_);
00053   setctrlState("mrs_real/bias", true);
00054 }
00055 
00056 void
00057 ANN_node::myUpdate(MarControlPtr sender)
00058 {
00059   (void) sender;  //suppress warning of unused parameter(s)
00060   MRSDIAG("ANN_node.cpp - ANN_node:myUpdate");
00061 
00062   setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples"));
00063   setctrl("mrs_natural/onObservations", (mrs_natural)1);
00064   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00065 
00066   //weights_.create(getctrl("mrs_realvec/weights")->to<mrs_realvec>().getSize());
00067   weights_ = getctrl("mrs_realvec/weights")->to<mrs_realvec>();
00068   bias_ = getctrl("mrs_real/bias")->to<mrs_real>();
00069 }
00070 
00071 void
00072 ANN_node::myProcess(realvec& in, realvec& out)
00073 {
00074   mrs_natural o,t;
00075   //checkFlow(in,out);
00076 
00077   for (t = 0; t < inSamples_; t++)
00078   {
00079     out(0,t) = bias_; // initialize output to bias
00080 
00081     for (o=0; o < inObservations_; o++)
00082     {
00083       out(0,t) += weights_(o) * in(o,t); // calculate weighted sum
00084     }
00085 
00086   }
00087 }
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00095 
00096 
00097 
00098 
00099