AI-PSO
view release on metacpan or search on metacpan
examples/NeuralNet/NeuralNet.h view on Meta::CPAN
protected:
///
/// \fn void checkSize()
/// \brief checks the size of the connection array for this Neuron.
/// if a connection needs to be added past the capacity, then
/// new connection array space is allocated.
///
void checkSize()
{
if( m_numConnections >= m_capacity )
{
m_capacity *= 2;
Neuron **newNeuronArr = new Neuron*[m_capacity];
double *newWeightArr = new double[m_capacity];
for(int i = 0; i < m_numConnections; i++)
{
newNeuronArr[i] = m_neurons[i];
newWeightArr[i] = m_weights[i];
}
delete [] m_neurons;
delete [] m_weights;
m_neurons = newNeuronArr;
m_weights = newWeightArr;
}
}
///
/// \fn double transferFunction(double val)
/// \brief applies a transfer function to val and returns the result
/// \param val a double
/// \return double
///
double transferFunc(double val)
{
return val;
}
int m_numConnections; /// number of connections to other Neurons
int m_capacity; /// capacity of connection array
Neuron **m_neurons; /// connection array of pointers to other Neurons
double *m_weights; /// weight array of connections
double m_value; /// value of this Neuron
TransferFunction *xfer;
};
///
/// \class Input NeuralNet.h NeuralNet
/// \brief Simulates an input neuron in a Neural net. This class extends Neuron
/// but allows for its value to be set directly and it also overrides
/// the virtual value function so that it returns its value directly
/// rather than passing though a transfer function.
///
class NEURALNET_API Input : public Neuron
{
public:
///
/// \fn Input(double value)
/// \brief constructor
///
Input(double value = 0) : Neuron()
{
m_value = value;
}
///
/// \fn ~Input()
/// \brief destructor
///
virtual ~Input()
{
}
///
/// \fn void setValue(double value)
/// \brief sets the value of this input Neuron to value
/// \param value a double
///
void setValue(double value)
{
m_value = value;
}
///
/// \fn double value()
/// \brief override of virtual function.
/// \return double
///
// double value()
// {
// return m_value;
// }
protected:
};
///
/// \class Hidden NeuralNet.h NeuralNet
/// \brief simulates a hidden Neuron
///
class NEURALNET_API Hidden : public Neuron
{
public:
///
/// \fn Hidden()
/// \brief constructor which sets transfer function
///
Hidden() : Neuron()
{
// delete xfer;
// xfer = new Logistic();
}
///
/// \fn ~Hidden()
/// \brief destructor
///
virtual ~Hidden()
{
}
///
/// \fn void setTransferFunction(char *xferFunc)
/// \brief sets the transfer function for this Neuron
///
void setTransferFunction(const char *xferFunc)
{
string xferName = string(xferFunc);
if(xferName != "UnityGain")
{
if(xferName == "Logistic")
{
delete xfer;
xfer = new Logistic();
}
// add if statements for each new transfer function object
}
}
};
( run in 1.892 second using v1.01-cache-2.11-cpan-39bf76dae61 )