include/cluster.h

Go to the documentation of this file.
00001 /********************************************************************************
00002  *  Neural Network Framework.                                                   *
00003  *  Copyright (C) 2005-2008 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 #ifndef CLUSTER_H
00021 #define CLUSTER_H
00022 
00027 #include "types.h"
00028 #include "updatable.h"
00029 #include "outputfunction.h"
00030 
00031 namespace nnfw {
00032 
00084 class NNFW_API Cluster : public Updatable {
00085 public:
00089     Cluster( u_int numNeurons, const char* name = "unnamed" );
00091     Cluster( PropertySettings& prop );
00093     virtual ~Cluster();
00094 
00096 
00098 
00101     u_int numNeurons() const {
00102         return numneurons;
00103     };
00104 
00107     bool needReset() {
00108         return needRst;
00109     };
00110 
00115     void setAccumulate( bool mode ) {
00116         accOff = !mode;
00117     };
00118 
00121     bool isAccumulate() const {
00122         return !accOff;
00123     };
00124 
00128     virtual void randomize( Real min, Real max ) = 0;
00129 
00132     Variant numNeuronsP() {
00133         return Variant( numNeurons() );
00134     };
00135 
00138     Variant accumP() {
00139         return Variant( isAccumulate() );
00140     };
00141 
00144     bool setAccumP( const Variant& b ) {
00145         setAccumulate( b.getBool() );
00146         return true;
00147     };
00148 
00150 
00152 
00156     virtual void setInput( u_int neuron, Real value );
00157 
00160     virtual void setInputs( const RealVec& inputs );
00161 
00165     virtual void setAllInputs( Real value );
00166 
00170     virtual void resetInputs();
00171 
00174     virtual Real getInput( u_int neuron ) const;
00175 
00179     RealVec& inputs() {
00180         return inputdata;
00181     };
00182 
00184     const RealVec& inputs() const {
00185         return inputdata;
00186     };
00187 
00189     Variant inputsP() {
00190         return Variant( &inputdata );
00191     };
00192 
00194     bool setInputsP( const Variant& v ) {
00195         inputdata.assign( *(v.getRealVec()) );
00196         return true;
00197     };
00198 
00200 
00202 
00205     virtual void setOutput( u_int neuron, Real value );
00206 
00209     virtual void setOutputs( const RealVec& outputs );
00210 
00213     virtual Real getOutput( u_int neuron ) const;
00214 
00218     RealVec& outputs() {
00219         return outputdata;
00220     };
00221 
00223     const RealVec& outputs() const {
00224         return outputdata;
00225     };
00226 
00228     Variant outputsP() {
00229         return Variant( &outputdata );
00230     };
00231 
00233     bool setOutputsP( const Variant& v ) {
00234         outputdata.assign( *(v.getRealVec()) );
00235         return true;
00236     };
00237 
00239 
00241 
00246     void setFunction( const OutputFunction& up );
00247 
00250     OutputFunction* const getFunction() const {
00251         return updater;
00252     };
00253 
00255     Variant getFunctionP() {
00256         return Variant( updater );
00257     };
00258 
00260     bool setFunction( const Variant& outf ) {
00261         setFunction( *(outf.getOutputFunction()) );
00262         return true;
00263     };
00264 
00266     virtual Cluster* clone() const;
00267 
00269 
00270 protected:
00274     void setNeedReset( bool b ) {
00275         needRst = accOff && b;
00276     };
00277 
00278 private:
00280     u_int numneurons;
00282     RealVec inputdata;
00284     RealVec outputdata;
00286     OutputFunction* updater;
00287 
00289     bool needRst;
00293     bool accOff;
00294 
00296     void propdefs();
00297 };
00298 
00299 }
00300 
00301 #endif
00302 
BerliOS Developer Logo Valid XHTML 1.0 Transitional Valid CSS!