Professional Documents
Culture Documents
神经网络
神经网络
神经网络
2
Abstract........................................................................................................................................................... 2
1 ............................................................................................................................................................ 3
1.1 ............................................................................................................................ 3
1.2 ............................................................................................................................ 3
1.3 ............................................................................................................................ 4
1.4 ........................................................................................................................ 4
2 ................................................................................................................... 6
2.1 .................................................................................................................... 6
2.2 ................................................................................................................................ 6
2.3 ................................................................................................................ 7
2.4 ...............................................................................................................11
2.5 .......................................................................................................................... 12
3 ..................................................................................................... 13
3.1 .............................................................................................................................. 13
3.2 ...................................................................................................................... 13
3.3 .............................................................................................................................. 14
3.4 .............................................................................................................................. 15
3.4.1 ................................................................................................................... 15
3.4.2 ............................................................................................... 15
3.4.3 ........................................................................................................................... 17
3.4.4 ....................................................................................................................... 23
.............................................................................................................................................................. 24
...................................................................................................................................................... 25
AIAI
AI
AIAI
AI
; ;
1
1.1
[1]
AI
1.2
NO
YES
1.1
1.1
1.3
1.2 [2]
1.2
[3]
1.4
1.3
0
6*10
1
0 60
10
0
1.3
(01)0
[4]
10 50%1
0 [1]
1.4
NO
YES
1.4
2.1
1.
2.
3.
4.
5. 234
2.2
2.1
Bob Bob
2 2.1
2.1
00
01
10
11
Bob
18 36 36 18
2 2
2 10 20 20 6.6
10
00
Bob
2.3
1.
2.
3.
CBobsMap
CBobsMap
static const int
map[MAP_HEIGHT][MAP_WIDTH];//
m_iMapWidth;
//
m_iMapHeight;
//
m_iStartX;
// X
7
m_iStartY;
// Y
m_iEndX;
// X
m_iEndY;
// Y
int memory[MAP_HEIGHT][MAP_WIDTH]; //
0bob
1bob
bob Pxy Eendxendy
Fitness =
x endx + y endy + 1
//
posY -= 1;
}
break;
8
case 1://
.break;
case 2://
.break;
case 3: //
.break;
}
Bobs.memory[posY][posX] = 1;
//
if(posY==m_iEndY && posX==m_iEndX)
return 1;
}
//
// X Y
Int
int
//
return 1/(double)(DiffX+DiffY+1);
}
0 10
10
2.2
2.2
SGenome& CgaBob::RouletteWheelSelection()
{//
double fSlice
= RandFloat() * m_dTotalFitnessScore;
double cfTotal
= 0.0;
9
int SelectedGenome = 0;
//
for (int i=0; i<m_iPopSize; ++i)
{
cfTotal += m_vecGenomes[i].dFitness;
if (cfTotal > fSlice)
{//
SelectedGenome = i;
break;
}
}
return m_vecGenomes[SelectedGenome];
}
0100110100000110
1101100101101101
8
1
11011001 00000110
01001101 01101101
Crossover..
void CgaBob::Crossover( const vector<int> &mum,
const vector<int> &dad,
vector<int>
&baby1,
vector<int>
&baby2)
//
if ( (RandFloat() > m_dCrossoverRate) || (mum == dad))
{//
baby1 = mum;
baby2 = dad;
return;
}
//
int cp = RandInt(0, m_iChromoLength - 1);
//
10
2.4
Bob
2
pop_sizechromo_length P C
C t*P*C
10 n*C*P
m*C*P x*P y*C*P z*C*P
n*C*P+m*C*P+x*P+y*C*P+z*C*P=(n+m+y+z)*C*P+x*P
Gt*P*C+((n+m+y+z)*C*P+x*P)*G
OP*C*G
36
36
Bob
11
P*C*G
2.5
12
3.1
3.2
ANN
ANN
ANN
3.1
W
W
Output
Nucleus
W
3.1
output
a=w 1 x 1 +w 2 x 2 +w 3 x 3 +..+w n x n
i=n
wx
i=0
activation
0 1
13
1 0 3.2
-2
-1
3.2
1 1 1 0
3.3
3.3
3.3
14
3.4
3.4
3.4.1
3.4
3 .4.2
4 x1y1
x2y2
xy 6
y1-x1,y2-x2 3.5
15
3.5
CPU
3.6
//
//
0 1
0 1 4
3.6
0 1 0 1
0 1
3.7
output
1
1 + e a / p
e e 2.7183p
16
0.5
0
3.7
3.4.3
struct SNeuron
{
//
int
m_NumInputs;
//
vector<double>
m_vecWeight;
SNeuron(int NumInputs);
};
struct SNeuronLayer
{
//
int
m_NumNeurons;
//
vector<SNeuron>
m_vecNeurons;
int
m_NumInputs;
//
int
m_NumOutputs;
//
int
m_NumHiddenLayers;
//
int
m_NeuronsPerHiddenLyr;
//
vector<SNeuronLayer>
m_vecLayers;//
CNeuralNet();
//
void
CreateNet();
//
vector<double>
GetWeights()const;
//
int
GetNumberOfWeights()const;
//
void
PutWeights(vector<double> &weights);
//S
inline double
//
vector<double>
Update(vector<double> &inputs);
};
0 1
2000 2000 1
2000 m
2000
Fitness =
m
i =1
struct SGenome
{
vector <double>
double
vecWeights;
dFitness;
SGenome():dFitness(0){}
18
class CMinesweeper
{
private:
//
CNeuralNet
m_ItsBrain;
//
m_vPosition;[4]
SVector2D
//
SVector2D
m_vLookAt;
//
double
m_dRotation;
double
m_dSpeed;
//
double
m_lTrack,
m_rTrack;
//
19
double
m_dFitness;
//
double
m_dScale;
//
int
m_iClosestMine;
CMinesweeper();
// 2000
bool
Update(vector<SVector2D> &mines);
//
void
WorldTransform(vector<SPoint> &sweeper);
//
SVector2D
GetClosestMine(vector<SVector2D> &objects);
//
int
void
Reset();
SVector2D
Position()const{return m_vPosition;}
void
double
Fitness()const{return m_dFitness;}
void
PutWeights(vector<double> &w){m_ItsBrain.PutWeights(w);}
int
GetNumberOfWeights()const{return m_ItsBrain.GetNumberOfWeights();}
};
class CGenAlg
{
private:
//
vector <SGenome>
m_vecPop;
//
int m_iPopSize;
//
int m_iChromoLength;
//
double m_dTotalFitness;
//
double m_dBestFitness;
//
20
double m_dAverageFitness;
//
double m_dWorstFitness;
//
int
m_iFittestGenome;
//
double m_dMutationRate;
//
double m_dCrossoverRate;
//
int
void
m_cGeneration;
Crossover(const vector<double> &mum,
const vector<double> &dad,
void
&baby1,
vector<double>
&baby2);
Mutate(vector<double> &chromo);
SGenome
void
vector<double>
GetChromoRoulette();
GrabNBest(int
NBest,
const int
NumCopies,
vector<SGenome> &vecPop);
void
FitnessScaleRank();
void
CalculateBestWorstAvTot();
void
Reset();
public:
CGenAlg(int
popsize,
double
MutRat,
double CrossRat,
int
numweights);
//
vector<SGenome>
Epoch(vector<SGenome> &old_pop);
vector<SGenome>
GetChromos()const{return m_vecPop;}
double
double
BestFitness()const{return m_dBestFitness;}
};
21
class CController
{
private:
//
vector<SGenome>
m_vecThePopulation;
//
vector<CMinesweeper> m_vecSweepers;
//
vector<SVector2D>
m_vecMines;
//
CGenAlg*
m_pGA;
int
m_NumSweepers;
int
m_NumMines;
int
m_NumWeightsInNN;
//
vector<SPoint>
m_SweeperVB;
vector<SPoint>
m_MineVB;
//
vector<double>
m_vecAvFitness;
//
vector<double>
m_vecBestFitness;
//
HPEN
m_RedPen;
HPEN
m_BluePen;
HPEN
m_GreenPen;
HPEN
m_OldPen;
//
HWND
m_hwndMain;
//
bool
m_bFastRender;
//
int
m_iTicks;
//
int
m_iGenerations;
//
22
int
void
cxClient, cyClient;
PlotStats(HDC surface);
public:
CController(HWND hwndMain);
~CController();
void
Render(HDC surface);
void
WorldTransform(vector<SPoint> &VBuffer,
SVector2D
bool
Update();
bool
FastRender()const
void
void
FastRenderToggle()
vPos);
{return m_bFastRender;}
{m_bFastRender = !m_bFastRender;}
};
3.4.4
CPU
23
24
. [M] . .
.[M]..2002.05
[8] . [M]..2008.02
[9] . [M]..2004.10
[10] .[M]..2006.06
[11] .[J]..2007. (05)
[12] .[J]..2002.(02)
[13]
. [M]..1997.(05)
. [D], 2002
[20]
. [D], 2001
25