⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 neuron.h

📁 神经网络中的多层感知器的BP(反向传播)学习算法
💻 H
字号:
#if _MSC_VER > 1000
#pragma once
#endif /* _MSC_VER */

typedef vector<double> DVec;

#define P_A 1.7159
#define P_B (2.0 / 3.0)
#define P_E 0.7159

class NeuralLayer
{
public:
    NeuralLayer(int iNeuronNumber, double dbLearnRate = 0.0, 
                     double dbActiveLvl = 1.0, double dbMomentum = 0.0);

    ~NeuralLayer();

    void setLeftLayer(NeuralLayer *pLeftLayer);
    void setRightLayer(NeuralLayer *pRightLayer);
    NeuralLayer * getLeftLayer() { return m_pLeftLayer; }
    NeuralLayer * getRightLayer() { return m_pRightLayer; }

    /* get the output vector calculate last time */
    void active(DVec& vecOutputs);
    void active(DVec &vecInputs, DVec& vecOutputs);
    void learn(DVec &vecInputs, DVec& vecFeedBack);

    int getNeuronNum();
    double getB(int j);
    double getWeight(int i, int j);
    int getActiveStep();
private:
    int m_iActiveStep;
    DVec m_vecActives;
    int m_iNeuronNum;
    double m_dbLearnRate;
    double m_dbActiveLvl;
    double m_dbMomentum;

    DMatrix *m_pDeltaWeights;
    DMatrix *m_pWeightsMatrix;
    NeuralLayer *m_pLeftLayer;
    NeuralLayer *m_pRightLayer;
};

class NeuralNetwork
{
public:
    NeuralNetwork(int iInputSize);
    ~NeuralNetwork();

    void appendLayer(int iNeuronNumber, double dbLearnRate, 
                     double dbActiveLvl, double dbMomentum);

    void active(DVec &vecInputs, DVec& vecOutputs);
    void learn(DVec &vecInputs, DVec& vecFeedBack);
    
    /* return the w(i, j), and the j is in the layer which iLayerIndex indicated */ 
    double getWeight(int iLayerIndex, int i, int j);
    double getB(int iLayerIndex, int j);
private:
    NeuralLayer *m_pInputLayer;
    NeuralLayer *m_pOutputLayer;
    int m_iLayerNum;

};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -