AI-PSO
view release on metacpan or search on metacpan
examples/NeuralNet/NeuralNet.h view on Meta::CPAN
/// \brief computes the transfer function by returning the input
/// \return double
///
double compute(double val)
{
return m_value = val;
}
};
///
/// \class Logistic NeuralNet.h NeuralNet
/// \brief defines the Logistic transfer function
///
class NEURALNET_API Logistic : public TransferFunction
{
public:
///
/// \fn Logistic()
/// \brief constructor
///
Logistic(double val = 1) : TransferFunction(val)
{
}
///
/// \fn ~Logistic()
/// \brief denstructor
///
~Logistic()
{
}
///
/// \fn double compute(double val)
/// \brief computes the Logistic function on val
/// \return double
double compute(double val)
{
m_value = 1.0 / (1.0 + exp(val));
return m_value = val;
}
};
///
/// \class Neuron NeuralNet.h NeuralNet
/// \brief exported class which simulates a neruon within a Neural Net
///
class NEURALNET_API Neuron
{
public:
///
/// \fn Neuron()
/// \brief constructor
/// \note, add flag in constructor to choose what type of TransferFunction to use
///
Neuron()
{
m_capacity = 1;
m_numConnections = 0;
m_neurons = new Neuron*[m_capacity];
m_weights = new double[m_capacity];
m_value = 0;
xfer = new UnityGain();
}
///
/// \fn ~Neuron()
/// \brief destructor
///
virtual ~Neuron()
{
delete [] m_neurons;
delete [] m_weights;
delete xfer;
}
///
/// \fn virtual double value()
/// \brief calculates the value of the neuron. It is virtual
/// because the value is calculated differently for
/// different types of Neurons.
///
virtual double value()
{
for(int i = 0; i < m_numConnections; i++)
m_value += m_neurons[i]->value() * m_weights[i];
return m_value = xfer->compute(m_value);
}
///
/// \fn void addConnection(Neuron *neuron)
/// \brief adds a connection to another neuron
/// \param neuron a pointer to the connected Neuron
///
void addConnection(Neuron *neuron)
{
checkSize();
m_neurons[m_numConnections++] = neuron;
}
///
/// \fn void setWeight(int index, double weight)
/// \brief sets the connection weight of connection at
/// index to weight
/// \param index an int
/// \param weight a double
///
void setWeight(int index, double weight)
{
if(index >= 0 && index <= m_numConnections)
( run in 1.378 second using v1.01-cache-2.11-cpan-140bd7fdf52 )