AI-PSO

 view release on metacpan or  search on metacpan

examples/NeuralNet/NeuralNet.h  view on Meta::CPAN

                // add if statements for each new transfer function object
            }
        }
};



///
/// \class NeuralNet NeuralNet.h NeuralNet
/// \brief Simulates a NeuralNet made up of Neurons and Input Neurons
/// 
class NEURALNET_API NeuralNet 
{
    public:

        ///
        /// \fn NeuralNet(int numInputs, int numHidden)
        /// \brief constructor
        /// \param numInputs an int
        /// \param numHidden an int
        ///
        NeuralNet(int numInputs = 3, int numHidden = 2, const char *xferFunc = "Logistic") : m_numInputs(numInputs), m_numHidden(numHidden)
        {
            m_inputs = new Input[m_numInputs];
//            m_hidden = new Neuron[m_numHidden];
            m_hidden = new Hidden[m_numHidden];
            for(int i = 0; i < m_numHidden; i++)
                m_hidden[i].setTransferFunction(xferFunc);
            m_xferFunc = string(xferFunc);
            connectionize();
        }


        ///
        /// \fn ~NeuralNet()
        /// \brief destructor 
        ///
        ~NeuralNet()
        {
            delete [] m_inputs;
            delete [] m_hidden;
        }


        ///
        /// \fn void setInput(int index, double value)
        /// \brief sets the value of the Input Neuron given by index to value
        /// \param index an int
        /// \param value a double
        ///
        void setInput(int index, double value)
        {
            if(index >= 0 && index < m_numInputs)
                m_inputs[index].setValue(value);
        }


        ///
        /// \fn void setWeightsToOne()
        /// \brief sets all of the connections weights to unity
        /// \note this is really only used for testing/debugging purposes
        ///
        void setWeightsToOne()
        {
            for(int i = 0; i < m_numHidden; i++)
                for(int j = 0; j < m_hidden[i].numConnections(); j++)
                    m_hidden[i].setWeight(j, 1.0);
            for(int k = 0; k < m_output.numConnections(); k++)
                m_output.setWeight(k, 1.0);
        }


        ///
        /// \fn double value()
        /// \brief returns the final network value 
        /// \return double
        ///
        double value()
        {
            return m_output.value();
        }


        ///
        /// \fn void setHiddenWeight(int indexHidden, int indexInput, double weight)
        /// \brief sets the connection weight between a pair of input and hidden neurons
        /// \param indexHidden an int
        /// \param indexInput an int
        /// \param weight a double
        ///
        void setHiddenWeight(int indexHidden, int indexInput, double weight)
        {
            if(indexHidden >= 0 && indexHidden < m_numHidden)
                m_hidden[indexHidden].setWeight(indexInput, weight);
        }


        ///
        /// \fn void setOutputWeight(int index, double weight)
        /// \brief sets the connection weight between a pair of hidden and output neurons
        /// \param index an int
        /// \param weight a double
        ///
        void setOutputWeight(int index, double weight)
        {
            m_output.setWeight(index, weight);
        }

/*
        void read(istream & in)
        {
            in  >> m_numInputs
                >> m_numHidden;
            
            delete [] m_inputs;
            delete [] m_hidden;

            m_inputs = new Input[m_numInputs];
            m_hidden = new Neuron[m_numHidden];
            connectionize();



( run in 0.356 second using v1.01-cache-2.11-cpan-483215c6ad5 )