Define the common interface among Clusters. More...

Inheritance diagram for Cluster:

Public Types

typedef DoubleVector &(* getStateVectorFuncPtr )(Cluster *)
 Delegate type for retrieving a vector by name (pointer to function) It works in this way:
 

Public Member Functions

 Cluster (unsigned int numNeurons, QString name="unnamed")
 Construct a Cluster.
 
 Cluster (ConfigurationParameters &params, QString prefix)
 Constructor.
 
virtual ~Cluster ()
 Destructor.
 
getStateVectorFuncPtr getDelegateFor (QString stateVector)
 Return the pointer to function for retrieving the DoubleVector representing the state requested.
 
double getInput (unsigned int neuron) const
 Get the input of neuron.
 
double getOutput (unsigned int neuron) const
 Get the output of neuron.
 
DoubleVectorinputs ()
 Get the array of inputs.
 
DoubleVector inputs () const
 Get the array of inputs.
 
bool isAccumulate () const
 return true if the Cluster will accumulates inputs
 
bool needReset ()
 Return true if inputs needs a reset.
 
unsigned int numNeurons () const
 Return the number of neurons (the length of input and output arrays)
 
OutputFunctionoutFunction () const
 Get the Output function.
 
DoubleVectoroutputs ()
 Get the array of outputs.
 
DoubleVector outputs () const
 Get the array of outputs.
 
virtual void randomize (double min, double max)=0
 Randomize the parameters of the Cluster
The parameters randomized by this method will be specified by sub-classes.
 
void resetInputs ()
 Reset the inputs of this cluster; the inputs will be set to zero.
 
virtual void save (ConfigurationParameters &params, QString prefix)
 Save the actual status of parameters into the ConfigurationParameters object passed.
 
void setAccumulate (bool mode)
 Enable/Disable accumulation mode
If accumulation is enabled (true) then linkers attached to this Cluster will never resetInput and accumulates data, otherwise the inputs will be resetted at each step of neural network.
 
void setAllInputs (double value)
 Set all the inputs with the same value Details...
 
void setInput (unsigned int neuron, double value)
 Set the input of neuron Details...
 
void setInputs (const DoubleVector &inputs)
 Set the inputs from the vector given.
 
void setOutFunction (OutputFunction *up)
 Set the output function for all neurons contained
This method create an internal copy of the OutputFunction passed

 
void setOutput (unsigned int neuron, double value)
 Force the output of the neuron at value specified.
 
void setOutputs (const DoubleVector &outputs)
 Set the outputs from the vector given.
 
- Public Member Functions inherited from Updatable
 Updatable (QString name="unnamed")
 Constructor.
 
 Updatable (ConfigurationParameters &params, QString prefix)
 Constructor.
 
virtual ~Updatable ()
 Destructor.
 
QString name () const
 Return its name.
 
void setName (QString newname)
 Set the name of Updatable.
 
virtual void update ()=0
 Update the object.
 
- Public Member Functions inherited from ParameterSettableInConstructor
 ParameterSettableInConstructor (ConfigurationParameters &, QString)
 
void addObserver (RuntimeParameterObserver *obs)
 
getRuntimeParameter (QString paramName)
 
virtual ParameterSettableUIgetUIManager ()
 
 ParameterSettable ()
 
virtual void postConfigureInitialization ()
 
void removeObserver (RuntimeParameterObserver *obs)
 
void setRuntimeParameter (QString paramName, T newvalue)
 
QString typeName () const
 
- Public Member Functions inherited from ParameterSettable
void addObserver (RuntimeParameterObserver *obs)
 
getRuntimeParameter (QString paramName)
 
void removeObserver (RuntimeParameterObserver *obs)
 
void setRuntimeParameter (QString paramName, T newvalue)
 
QString typeName () const
 

Static Public Member Functions

static void describe (QString type)
 Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups.
 
- Static Public Member Functions inherited from Updatable
static void describe (QString type)
 Add to Factory::typeDescriptions() the descriptions of all parameters and subgroups.
 
- Static Public Member Functions inherited from ParameterSettableInConstructor
static void describe (QString type)
 
static QString fullParameterDescriptionPath (QString type, QString param)
 
static QString fullSubgroupDescriptionPath (QString type, QString sub)
 
- Static Public Member Functions inherited from ParameterSettable
static void describe (QString type)
 
static QString fullParameterDescriptionPath (QString type, QString param)
 
static QString fullSubgroupDescriptionPath (QString type, QString sub)
 

Protected Member Functions

template<class T , DoubleVector &(T::*)() TMethod>
void setDelegateFor (QString vectorName)
 Configure a delegate for a specifing state vector; who implements subclasses of Cluster has to specify a name and the method used to retrieve any state vector that needs to be public (i.e.
 
void setNeedReset (bool b)
 Set the state of 'needReset'
Used by subclasses into update implementation.
 

Protected Attributes

DoubleVectorinputdataptr
 Pointer to data Input.
 
DoubleVectoroutputdataptr
 Pointer to data Output.
 

Additional Inherited Members

- Public Attributes inherited from ParameterSettableInConstructor
 AllowMultiple
 
 Default
 
 IsList
 
 IsMandatory
 
- Static Public Attributes inherited from ParameterSettableInConstructor
static const double Infinity
 
static const int MaxInteger
 
static const int MinInteger
 
- Static Protected Member Functions inherited from ParameterSettableInConstructor
static Descriptor addTypeDescription (QString type, QString shortHelp, QString longHelp=QString(""))
 
static void setGraphicalEditor (QString type)
 

Detailed Description

Define the common interface among Clusters.

Motivation
The Cluster class define the common interface amog Cluster. The subclasses may extends this interface for specific purpose (ex. SimpleCluster), but the BaseNeuralNet, the Linker and other classes depends only by this class. This abstraction allow to isolate the specific implementation of various classes
Description
The Cluster class represent an abstract group of neurons. There isn't a neuron class. The Cluster class represent a group of neurons as two arrays: inputs and outputs. The inputs array represent the inputs of the neurons 'contained' in the cluster, and the outputs of this neurons are calculated by appling the function provided by OutputFunction.
The number of neuron returned by size() method is also the dimension of inputs and outputs arrays
You can sets one subclasses of OutputFunction by setUpdater methods. If you don't specify an index when set a OutputFunction then this OutputFunction will be used to update the output of all neurons. Otherwise, you can specifiy different OutputFunction for different neuron.
// create a SimpleCluster, a specialized subclass of Cluster
SimpleCluster* simple = new SimpleCluster( 10 ); // this cluster contains 10 neurons
// set the SigmoidUpdater for all neurons
simple->setUpdater( new SigmoidUpdater( 1.0 ) );
Warnings
For whose want to implement a subclass of Cluster: This class allocate the memory for inputs, outputs and updaters array. So, a subclass have to implements only the update method. The getInputs and getOutputs returns a valid array of internal data, and not simply a copy of the internal data. Look at the following code:
RealVec& in = cluster->inputs();
in[2] = 3.0; // This statement will be changes the inputs of third neuron.
// the above statement is equivalent with the following
cluster->setInput( 2, 3.0 );
The reasons behind this kind of behaviour its the efficiency!! When another class must do heavy calculation on all inputs of a Cluster (as MatrixLinker do), then its more efficient that it takes the array returned by inputs (or outputs) and works over them.

Definition at line 73 of file cluster.h.

Member Typedef Documentation

typedef DoubleVector&(* getStateVectorFuncPtr)(Cluster *)

Delegate type for retrieving a vector by name (pointer to function) It works in this way:

getStateVectorFuncPtr delegate = aCluster->getDelegateFor( "biases" );
DoubleVector& biasesVector = (*delegate)( aCluster );

In the first row, getDelegateFor return a pointer to the function for retrieving the vector of biases. At the second row the delegate is used.

Look at the code of Linker and DotLinker for a full example on how to use it.

Definition at line 175 of file cluster.h.

Constructor & Destructor Documentation

Cluster ( unsigned int  numNeurons,
QString  name = "unnamed" 
)
~Cluster ( )
virtual

Destructor.

Definition at line 89 of file cluster.cpp.

Member Function Documentation

getStateVectorFuncPtr getDelegateFor ( QString  stateVector)
inline

Return the pointer to function for retrieving the DoubleVector representing the state requested.

Parameters
stateVectoris the name of the DoubleVector requested (i.e. "biases" in the case of the biases of a BiasedCluster)
Note
the class Cluster defines "inputs" and "outputs" that correspond to method inputs() and outputs()
Warning
It will raise an exception if the state requested does not exists

Definition at line 182 of file cluster.h.

Referenced by Linker::Linker().

double getInput ( unsigned int  neuron) const

Get the input of neuron.

Definition at line 116 of file cluster.cpp.

References Cluster::inputdataptr.

double getOutput ( unsigned int  neuron) const

Get the output of neuron.

Definition at line 128 of file cluster.cpp.

References Cluster::outputdataptr.

DoubleVector& inputs ( )
inline

Get the array of inputs.

Definition at line 122 of file cluster.h.

Referenced by SimpleCluster::update(), BiasedCluster::update(), and DDECluster::update().

DoubleVector inputs ( ) const
inline

Get the array of inputs.

Definition at line 126 of file cluster.h.

bool isAccumulate ( ) const
inline

return true if the Cluster will accumulates inputs

Definition at line 97 of file cluster.h.

Referenced by Cluster::save().

bool needReset ( )
inline

Return true if inputs needs a reset.

Definition at line 86 of file cluster.h.

OutputFunction* outFunction ( ) const
inline

Get the Output function.

Definition at line 149 of file cluster.h.

Referenced by SimpleCluster::update(), BiasedCluster::update(), and DDECluster::update().

DoubleVector& outputs ( )
inline

Get the array of outputs.

Definition at line 136 of file cluster.h.

Referenced by BackPropagationAlgo::setTeachingInput(), SimpleCluster::update(), BiasedCluster::update(), and DDECluster::update().

DoubleVector outputs ( ) const
inline

Get the array of outputs.

Definition at line 140 of file cluster.h.

virtual void randomize ( double  min,
double  max 
)
pure virtual

Randomize the parameters of the Cluster
The parameters randomized by this method will be specified by sub-classes.

Implemented in BiasedCluster, DDECluster, FakeCluster, and SimpleCluster.

void resetInputs ( )

Reset the inputs of this cluster; the inputs will be set to zero.

Details...

Definition at line 111 of file cluster.cpp.

References Cluster::inputdataptr, Cluster::setNeedReset(), and DoubleVector::zeroing().

Referenced by DotLinker::update(), NormLinker::update(), and CopyLinker::update().

void save ( ConfigurationParameters params,
QString  prefix 
)
virtual

Save the actual status of parameters into the ConfigurationParameters object passed.

This saves the name property, remember to call this in child classes

Parameters
paramsthe configuration parameters object on which save actual parameters
prefixthe prefix to use to access the object configuration parameters.

Reimplemented from Updatable.

Reimplemented in BiasedCluster, DDECluster, FakeCluster, and SimpleCluster.

Definition at line 132 of file cluster.cpp.

References ConfigurationParameters::createParameter(), ConfigurationParameters::createSubGroup(), Cluster::inputdataptr, Cluster::isAccumulate(), Cluster::outputdataptr, Updatable::save(), DoubleVector::size(), and ConfigurationParameters::startObjectParameters().

Referenced by SimpleCluster::save(), FakeCluster::save(), DDECluster::save(), BiasedCluster::save(), and NeuralNet::save().

void setAccumulate ( bool  mode)
inline

Enable/Disable accumulation mode
If accumulation is enabled (true) then linkers attached to this Cluster will never resetInput and accumulates data, otherwise the inputs will be resetted at each step of neural network.

Definition at line 93 of file cluster.h.

void setAllInputs ( double  value)

Set all the inputs with the same value Details...

Definition at line 106 of file cluster.cpp.

References Cluster::inputdataptr, DoubleVector::setAll(), and Cluster::setNeedReset().

void setDelegateFor ( QString  vectorName)
inlineprotected

Configure a delegate for a specifing state vector; who implements subclasses of Cluster has to specify a name and the method used to retrieve any state vector that needs to be public (i.e.

used by Linkers for accessing and modifing it.

  The usage is the following: suppose the case of BiasedCluster that has the biases vector and
  the metod biases() that returns the reference to the DoubleVector containing the biases.
  In this case, in the constructor there is the following statement:
  @code 
    setDelegateFor<BiasedCluster, &BiasedCluster::biases>( "biases" )
  \endcode
  where the first parameter of the template if the class with the new state vector, the second
  parameter is the method for getting the vector specified with the pointer-to-member syntax, and
  the name of the state vector (used for referencing it by name)

Definition at line 204 of file cluster.h.

void setInput ( unsigned int  neuron,
double  value 
)

Set the input of neuron Details...

Definition at line 98 of file cluster.cpp.

void setInputs ( const DoubleVector inputs)

Set the inputs from the vector given.

Definition at line 102 of file cluster.cpp.

References DoubleVector::copyValues(), and Cluster::inputdataptr.

void setNeedReset ( bool  b)
inlineprotected

Set the state of 'needReset'
Used by subclasses into update implementation.

Definition at line 210 of file cluster.h.

Referenced by Cluster::Cluster(), Cluster::resetInputs(), Cluster::setAllInputs(), SimpleCluster::update(), BiasedCluster::update(), FakeCluster::update(), and DDECluster::update().

void setOutFunction ( OutputFunction up)

Set the output function for all neurons contained
This method create an internal copy of the OutputFunction passed

Warning
This function delete the previous updater class registered !!!

Definition at line 93 of file cluster.cpp.

Referenced by Cluster::Cluster().

void setOutput ( unsigned int  neuron,
double  value 
)

Force the output of the neuron at value specified.

Definition at line 120 of file cluster.cpp.

void setOutputs ( const DoubleVector outputs)

Set the outputs from the vector given.

Definition at line 124 of file cluster.cpp.

References DoubleVector::copyValues(), and Cluster::outputdataptr.

Member Data Documentation

DoubleVector* outputdataptr
protected

Pointer to data Output.

Definition at line 216 of file cluster.h.

Referenced by Cluster::Cluster(), FakeCluster::FakeCluster(), Cluster::getOutput(), Cluster::save(), and Cluster::setOutputs().


The documentation for this class was generated from the following files: