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

📄 cneuralnet.h

📁 游戏开发人工智能技术-AI.Techniques.for.Game.Programming
💻 H
字号:
#ifndef CNEURALNET_H
#define CNEURALNET_H
//------------------------------------------------------------------------
//
//	Name: CNeuralNet.h
//
//  Author: Mat Buckland 2002
//
//  Desc: Class for creating a feedforward neural net.From the book Game AI 
//  Programming with Neural Nets and Genetic Algorithms.
//-------------------------------------------------------------------------
#include <vector>
#include <math.h>

#include "utils.h"
#include "CParams.h"

using namespace std;



//-------------------------------------------------------------------
//	define neuron struct
//-------------------------------------------------------------------
struct SNeuron
{
	//the number of inputs into the neuron
	int				      m_NumInputs;

	//the weights for each input
	vector<double>	m_vecWeight;


	//ctor
	SNeuron(int NumInputs);
};


//---------------------------------------------------------------------
//	struct to hold a layer of neurons.
//---------------------------------------------------------------------

struct SNeuronLayer
{
	//the number of neurons in this layer
	int					      m_NumNeurons;

	//the layer of neurons
	vector<SNeuron>		m_vecNeurons;

	SNeuronLayer(int NumNeurons, 
				       int NumInputsPerNeuron);
};


//----------------------------------------------------------------------
//	neural net class
//----------------------------------------------------------------------

class CNeuralNet
{
	
private:
	
	int					m_NumInputs;

	int					m_NumOutputs;

	int					m_NumHiddenLayers;

	int					m_NeuronsPerHiddenLyr;

	//storage for each layer of neurons including the output layer
	vector<SNeuronLayer>	m_vecLayers;

public:

	CNeuralNet();

	void			      CreateNet();

	//gets the weights from the NN
	vector<double>	GetWeights()const;

	//returns total number of weights in net
	int				      GetNumberOfWeights()const;

	//replaces the weights with new ones
	void			      PutWeights(vector<double> &weights);

	//calculates the outputs from a set of inputs
	vector<double>	Update(vector<double> &inputs);

	//sigmoid response curve
	inline double	  Sigmoid(double activation, double response);

  //calculate the points which define the individual neurons
  vector<int>     CalculateSplitPoints() const;

};
				



#endif

⌨️ 快捷键说明

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