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

📄 bp.h

📁 一个简单灵活的数据挖掘实验平台
💻 H
字号:
#ifndef _BP_H_
#define _BP_H_

#include "..\\Core\\Data.h"
#include <vector>
struct BP_PARAM
{
	int input;            //: input layer node count
	int hidden;           //: hidden layer node count
	int output;           //: output layer node count
	int max_epoch;        //: maximum epoch
	double learning_rate; //: learning rate
	double random_range;  //: weights initial range
	BP_PARAM()
	{
		input         = 0;
		hidden        = 0;
		output        = 0;
		max_epoch     = 2000; //: default maximum epoch 2000
		learning_rate = 0.5;  //: default learning rate 0.5
		random_range  = 0.05; //: default random range 0.05
	}
};
//: NOTE: 
class BP
{

public:
	//: constructs BP algorithm with specified training data set and parameters
	BP(vector<Data>* train_set,BP_PARAM params);
	~BP();
	//: trains the initialized network
	void train();
	//: works with the data on the trained network
	void work(Data& data);
	//: loads BP network from a specified file
	static BP* load(string file);
	//: saves BP network on a specified file
	void save(string file);

private:
	//: forward calculates the output of hidden and output layers
	void forward(Data data);
	//: backward calculates the delta weights
	void backward(Data data);
	//: update the weights,reset the delta weights
	void update_weights();
	//: active function for hidden layer
	static inline double squash(double net); 
	static inline double dx_squash(double o);
	static inline double linear(double net);
	static inline double dx_linear(double o);
private:
	//: checks algorithm parameters
	void check();  
	//: initializes the algorithm internal parameters
	void initialize();
	//: randomizes the initial weights by specified random range
	inline double random();
private:
	vector<Data>* _train_set; //: training set
	int _ni;                 //: input layer neuron node count
	int _nh;                 //: hidden layer neuron node count
	int _no;				 //: output layer neuron node count
	double _range;           //: initialized random range
	double _enta;            //: learning rate               
	int _max_epoch;          //: maximum epoch count

	double* _wih;   //: weights between input and hidden layer
	double* _who;   //: weights between hidden and output layer
	double* _dwho;  //: delta weights between hidden and output layer
	double* _dwih;  //: delta weights between input and hidden layer

	double* _bh;    //: bias of hidden layer
	double* _bo;    //: bias of output layer
	double* _dbh;   //: delta bias of hidden layer
	double* _dbo;   //: delta bias of output layer

	double* _oh;    //: output of hidden layer
	double* _oo;    //: output of output layer

	double* _so;    //: error backward of output layer
	double* _sh;    //: error backward of hidden layer
};
#endif

⌨️ 快捷键说明

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