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

📄 bpn.h

📁 2002年
💻 H
字号:
#ifndef _BPN
#define _BPN

#include<vector>

enum FuncType{purelin,logsig,tansig};
enum TrainType{adapt, batch};
typedef double REAL;
typedef std::vector<REAL> RA;

#ifndef NULL
#define NULL 0
#endif

class BPN;
class LAYER{
private:
	int				units;	
	int				p_units;	//units of next layer
    std::vector<REAL>	Output;
    std::vector<REAL>   Error;
    std::vector<RA>        Weight;
	FuncType      functype;
	std::vector<RA>        dWeight; /*weight deltas */
	std::vector<RA>        last_dWeight; /* last weight deltas for momentum     */
	REAL          Eta;
	REAL          Alpha;

public:
	LAYER(int num_units=0, int num_punits=0);
	~LAYER();

	bool Resize(int num_units, int num_punits);
	void SetFuncType(FuncType functype);

	friend class BPN;
};

class BPN{
private:
	LAYER*        InputLayer;
	LAYER*        OutputLayer;
	int           NUM_LAYERS;
	int           INPUT_SIZE;
	int           OUTPUT_SIZE;
	REAL          BIAS;
	REAL          Gain;          /* - gain of sigmoid function            */    
	REAL          Error;         /* - total net error                     */

	REAL sigmoid(REAL Input);
	REAL dsigmoid(REAL Out);
	REAL purelinear(REAL Input);
	REAL dpurelinear(REAL Out);
	REAL tanh(REAL Input);
	REAL dtanh(REAL Out);

	REAL Input_HI, Input_LO;
	REAL Input_MAX, Input_MIN;
	REAL Target_HI, Target_LO;
	REAL Target_MAX, Target_MIN;
	int epoch;
	int batch_period;
	TrainType traintype;

public:
	std::vector<LAYER> Layers;

	void RandomWeights(REAL Low = -0.5,REAL High = 0.5);
	int RandomInt(int Low, int High);
	int RandomInt(int High);
	BPN(int NUM_LAYERS = 0, int* LAYER_SIZE = NULL, FuncType* functype = NULL, bool BIASED = true);
	void Resize(int NUM_LAYERS, int* Units);
	~BPN();

	void SetInput(REAL* Input);
	void GetOutput(REAL* Output);
	void PropagateLayer(int Lower,int Upper);
	void PropagateNet();
	void ComputeOutputError(REAL* Desire);
	void SetOutputError(REAL* Error);
	void GetInputError(REAL* Error);
	void BackpropagateLayer(int Lower,int Upper);
	void BackpropagateNet();
	void AdjustWeights();
	void SimulateNet(REAL* Input, REAL* Output);
	void SimulateNet(int num_samples, REAL* Input, REAL* Output);
	void ForwardBack(REAL* Input, REAL* Desire);
	void GeneratedWeights();
	void Adapt(int num_samples, REAL* Input, REAL* Desire);
	void BatchTrain(int num_samples, REAL* Input, REAL* Desire);
	void TestNet(REAL* Input, REAL* Desire);
	REAL TestNet(int num_samples, REAL* Input, REAL* Desire);
	void TrainNet(int num_samples, REAL* Input, REAL* Desire);

	bool SetFunctype(FuncType functype, int layer);
	void SetTraintype(TrainType traintype);
	void SetEpoch(int epoch);
	void SetBatchPeriod(int period);
	void SetBIAS(REAL BIAS);
	void SetGain(REAL gain);
	void SetLearningRate(REAL lr);
	void SetMomentum(REAL mc);
	bool SetInputRange(REAL min, REAL max);
	bool SetTargetRange(REAL min, REAL max);
	bool SetInsideRange(REAL input_min, REAL input_max, REAL target_min, REAL target_max);
	void Normalize(int num_samples, REAL* Input, REAL* Desire);
	void DeNormalize(int num_samples, REAL* Output);
	void ResetdWeights();

	bool SaveNet(char* filename);
	bool RestoreNet(char* filename, int mode = 0);
	bool RestoreNetFromString(char*string);

	REAL GetError();

	REAL Normalize_Input(REAL y);
	REAL DeNormalize_Input(REAL y);
	REAL Normalize_Target(REAL y);
	REAL DeNormalize_Target(REAL y);
};
#endif























































































⌨️ 快捷键说明

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