gagents.h

来自「一个由Mike Gashler完成的机器学习方面的includes neural」· C头文件 代码 · 共 148 行

H
148
字号
/*	Copyright (C) 2006, Mike Gashler	This library is free software; you can redistribute it and/or	modify it under the terms of the GNU Lesser General Public	License as published by the Free Software Foundation; either	version 2.1 of the License, or (at your option) any later version.	see http://www.gnu.org/copyleft/lesser.html*/#ifndef __AGENTS_H__#define __AGENTS_H__class ConstructNode;class IncrementalModel;#define LOGSPEWclass GAgentWorldInterface{public:	GAgentWorldInterface() {}	virtual ~GAgentWorldInterface() {}	virtual void Iterate() = 0;	virtual int GetSenseCount() = 0;	virtual double GetSenseValue(int nIndex) = 0;	virtual int GetActionCount() = 0;	virtual void DoAction(int nIndex, int nParams, double* pParams) = 0;};class Agent{protected:	GAgentWorldInterface* m_pWorld;public:	Agent(GAgentWorldInterface* pWorld)	{		m_pWorld = pWorld;	}	virtual ~Agent()	{	}	virtual void Iterate() = 0;};class AgentAl : public Agent{protected:	ConstructNode** m_pConstructNodes;	int m_nSenseCount;	int m_nSenseConstructs;	int m_nActionCount;	int m_nShortTermMemoryCapacity;	double* m_pShortTermMemory;	int m_nShortTermMemoryPos;	int* m_pSenseConstructDependencyOrder;	bool m_bTrialIteration;	double m_dFocus;public:	// nShortTermMemoryCapacity is the number of iterations for which the agent stores historical sense vectors	// dFocus specifies how many iterations the agent stays on task before it re-evaluates its goal. (1=works on the	// 	same goal until it achieves it, nomatter what. 0.99=stays on the same task for an average of 100 iterations.	// 	0.9=stays on the same task for an average of 10 iterations. etc.)	AgentAl(GAgentWorldInterface* pWorldInterface, int nShortTermMemoryCapacity, double dFocus);	virtual ~AgentAl();	virtual void Iterate();protected:#ifdef LOGSPEW	void LogSpew_PrintObservations();	void LogSpew_PrintSenseConstructs();	void LogSpew_PrintSingleActionConstruct(int nSense, IncrementalModel* pModel, ConstructNode* pConstruct, double* pSenseVector);	void LogSpew_PrintActionConstructs();	void LogSpew_PrintConstructs();#endif // LOGSPEW	// pConstruct is the root of a construct tree for modelling this sense. This	// method takes ownership of pConstruct.	void AddSense(const char* szName, ConstructNode* pConstruct);	// ppModels should be an array of size "nSenses" (where "nSenses" is the number	// of senses). This method will take ownership of all the models (but not the	// array of pointers to them). You shouldn't add any actions until you are done	// adding senses.	void AddAction(const char* szName, IncrementalModel** ppModels);	// Returns a sense vector from short-term memory	// i = the time of the vector. 0=now, 1=just before now, 2=before that, etc.	double* GetMemoryVector(int i);	// Records the sense vector into short-term memory	void Observe();	// Learns from observations and decides what to do next	void Think();	// Performs the next action	void Act();	// Evaluate how well action consequences were predicted	void EvaluatePredictions();	// Determines an update order for the senses that is sensitive to dependencies	void RecomputeDependencyOrder();	// Learn how to model the world based on sense observations	void LearnToModelTheWorld();	// This is a helper method used by LearnToPredictHowActionsAffectTheWorld()	// nSense = the index of the sense	// pActionVector = the sense vector at the time the action was performed	// pCurrentVector = the sense vector at the time the consequences were observed	void TrainActionModel(int nSense, double* pActionVector, double* pCurrentVector);	// Learn to predict how actions will affect the world	void LearnToPredictHowActionsAffectTheWorld();	// Decide what to do next	void SelectNextAction();	// Simulate the specified action on the specified sense construct	void SimulateAction(int nAction, IncrementalModel* pModel, ConstructNode* pSenseConstruct);	// Predict how the world will change when the chosen action is performed	void PredictConsequences();	// Kill off the worst construct nodes and replace them with evolutions of the best	// construct nodes	void EvolveConstructs();};#endif // __AGENTS_H__

⌨️ 快捷键说明

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