ggreedysearch.h
来自「一个由Mike Gashler完成的机器学习方面的includes neural」· C头文件 代码 · 共 130 行
H
130 行
/* 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 __GGREEDYSEARCH_H__#define __GGREEDYSEARCH_H__#include "GSearch.h"class GAVLTree;// At each iteration this algorithm moves in only one// dimension. If the situation doesn't improve it tries// the opposite direction. If both directions are worse,// it decreases the step size for that dimension, otherwise// it increases the step size for that dimension.class GMomentumGreedySearch : public GRealVectorSearch{protected: int m_nDimensions; int m_nCurrentDim; double* m_pStepSizes; double* m_pVector; double m_dError; double m_dChangeFactor;public: GMomentumGreedySearch(GRealVectorCritic* pCritic); virtual ~GMomentumGreedySearch(); // Set the current vector void SetState(double* pVector); // Set all the current step sizes to this value void SetAllStepSizes(double dStepSize); virtual void Iterate(); // d should be a value between 0 and 1 void SetChangeFactor(double d) { m_dChangeFactor = d; }};// At each iteration this algorithm moves in a random direction// from the best point ever found. The size of the step is a// random number raised to a constant power (called the// conservativeness).class GStochasticGreedySearch : public GRealVectorSearch{protected: double m_dRange; double m_dConservativeness; int m_nDimensions; double* m_pVector; double* m_pTest; double m_dError;public: GStochasticGreedySearch(GRealVectorCritic* pCritic, double dMin, double dRange); virtual ~GStochasticGreedySearch(); virtual void Iterate(); // d should be greater than 1. A bigger value will cause it to usually // take small steps and only rarely take big steps. A smaller value // will cause it to take big steps more frequently. void SetConservativeness(double d) { m_dConservativeness = d; }};class GActionGreedySearch : public GActionPathSearch{protected: double m_dPrevError; GActionPath* m_pPath;public: // Takes ownership of pStartState GActionGreedySearch(GActionPathState* pStartState, int nActionCount); virtual ~GActionGreedySearch(); virtual bool Iterate(); virtual GActionPath* GetBestPath(); virtual double GetBestPathError();#ifndef NO_TEST_CODE static void Test();#endif // !NO_TEST_CODE};class GAStarSearch : public GActionPathSearch{protected: GAVLTree* m_pPriorityQueue; int m_nMaxPaths; double m_dBestError; GActionPath* m_pBestPath;public: // Takes ownership of pStartState // nMaxPaths is the max number of unique paths to hold in the priority queue. When // this number is exceeded, it throws out the worst paths. if nMaxPaths is small, // the search resembles bar-search, except with a best-first ordering. GAStarSearch(GActionPathState* pStartState, int nActionCount, int nMaxPaths); virtual ~GAStarSearch(); virtual bool Iterate(); virtual GActionPath* GetBestPath(); virtual double GetBestPathError();#ifndef NO_TEST_CODE static void Test();#endif // !NO_TEST_CODE};#endif // __GGREEDYSEARCH_H__
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?