bpnet.h
来自「演示在角色扮演游戏中如何利用人工神经网络进行智能分类的训练」· C头文件 代码 · 共 88 行
H
88 行
// BPNet.h: interface for the BPNet class.
//
// Copyright Gideon Pertzov, 2003
//
// This software is provided "as is" without express or implied
// warranties. You may freely copy and compile this source into
// applications you distribute provided that credit is given to
// the original author.
//
//////////////////////////////////////////////////////////////////////
#ifndef _BPNET_H
#define _BPNET_H
#include <cmath>
#include <vector>
#include "Pattern.h"
using namespace std;
class BPLink;
class BPNode;
class BPNet
{
// Methods
public:
virtual ~BPNet(); // destructor
BPNet(); // default c-tor
BPNet( double lr, double mt, int layers, ... ); // c-tor with network parameters
// create network structure
void createNetwork( double lr, double mt, const vector<int>& nodeCnt);
// forward-pass
void run();
// backward-pass
void learn();
// get number of layers
int getNumLayers() { return _nodeCount.size(); }
// get numer of nodes in a specific layer
int getNumNodes(int layerIndex);
// set values of input nodes
void setInput(double value, int inputNodeIndex);
void setInput( const Pattern* pattern );
// set desired output for error computation
void setError(double value, int outputNodeIndex);
void setError( const Pattern* pattern);
// get values/errors of output nodes
double getOutput(int outputNodeIndex) const;
double getError(int outputNodeIndex) const;
// set training parameters
void setLearningRate(double lr);
void setMomentum(double mt);
// get training parameters
double getLearningRate();
double getMomentum();
// save/load network
bool save( ofstream &ost ) const;
bool load( ifstream &ist );
protected:
// cleanup
void destroyNetwork();
// Members
protected:
int _firstMiddleNode; // index of first node in middle layer
int _firstOutputNode; // index of first node in output layer
vector<int> _nodeCount; // stores number of nodes in each layer
vector<BPNode*> _nodes; // vector of network nodes
vector<BPLink*> _links; // vector of links between nodes
};
#endif // _BPNET_H
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?