📄 neuralnode.cpp
字号:
// NeuronNode.cpp: implementation of the NeuronNode class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "NeuralNetwork.h"
#include "NeuralNode.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(NeuralNode, CObject, 1)
NeuralNode::NeuralNode()
{
for(int i=0;i<EDGENUM;i++)
{
edgeType[i]=0;
}
//======初始化偏置值========
bias=0.0;
//======初始化传输函数======
activeFunction=gaussian;
}
NeuralNode::~NeuralNode()
{
}
NeuralNode::NeuralNode(CPoint pos,int index)
{
//======初始化传输函数======
activeFunction=gaussian;
//======初始化偏置值========
bias=0.0;
//======初始化节点坐标======
nodePos=pos;
//======初始化节点索引======
totalIndex=index;
//=====初始化边缘节点类型======
for(int i=0;i<EDGENUM;i++)
{
edgeType[i]=0;
}
//======初始化中心点矩形区域======
centerPos=CRect(pos.x+3*LINESIZE,pos.y+3*LINESIZE,pos.x+6*LINESIZE,pos.y+6*LINESIZE);
//======初始化边缘节点矩形区域=======
edgeNodePos[0]=CRect(pos.x+3*LINESIZE,pos.y,pos.x+4*LINESIZE,pos.y+LINESIZE);
edgeNodePos[1]=CRect(pos.x+5*LINESIZE,pos.y,pos.x+6*LINESIZE,pos.y+LINESIZE);
edgeNodePos[2]=CRect(pos.x+LINESIZE,pos.y+LINESIZE,pos.x+2*LINESIZE,pos.y+2*LINESIZE);
edgeNodePos[3]=CRect(pos.x+7*LINESIZE,pos.y+LINESIZE,pos.x+8*LINESIZE,pos.y+2*LINESIZE);
edgeNodePos[4]=CRect(pos.x,pos.y+3*LINESIZE,pos.x+LINESIZE,pos.y+4*LINESIZE);
edgeNodePos[5]=CRect(pos.x+8*LINESIZE,pos.y+3*LINESIZE,pos.x+9*LINESIZE,pos.y+4*LINESIZE);
edgeNodePos[6]=CRect(pos.x,pos.y+5*LINESIZE,pos.x+LINESIZE,pos.y+6*LINESIZE);
edgeNodePos[7]=CRect(pos.x+8*LINESIZE,pos.y+5*LINESIZE,pos.x+9*LINESIZE,pos.y+6*LINESIZE);
edgeNodePos[8]=CRect(pos.x+LINESIZE,pos.y+7*LINESIZE,pos.x+2*LINESIZE,pos.y+8*LINESIZE);
edgeNodePos[9]=CRect(pos.x+7*LINESIZE,pos.y+7*LINESIZE,pos.x+8*LINESIZE,pos.y+8*LINESIZE);
edgeNodePos[10]=CRect(pos.x+3*LINESIZE,pos.y+8*LINESIZE,pos.x+4*LINESIZE,pos.y+9*LINESIZE);
edgeNodePos[11]=CRect(pos.x+5*LINESIZE,pos.y+8*LINESIZE,pos.x+6*LINESIZE,pos.y+9*LINESIZE);
}
void NeuralNode::setBias(real newBias)
{
bias=newBias;
}
void NeuralNode::setActivationFunction(ActivationFunction newFunction)
{
activeFunction=newFunction;
}
void NeuralNode::setWeight(real newWeight, int btnPosType)
{
outputLine[btnPosType].setWeight(newWeight);
}
ActivationFunction NeuralNode::getActivationFunction()
{
return activeFunction;
}
void NeuralNode::Serialize(CArchive &ar)
{
if(ar.IsStoring())
{
ar<<bias<<centerPos<<layerIndex<<neuronIndex<<nodePos<<totalIndex;//===<<activeFunction
for(int i=0;i<EDGENUM;i++)
{
ar<<edgeNodePos[i]<<edgeType[i]<<inputNeuronIndex[i];
}
}
else
{
ar>>bias>>centerPos>>layerIndex>>neuronIndex>>nodePos>>totalIndex;//=====>>activeFunction
for(int i=0;i<EDGENUM;i++)
{
ar>>edgeNodePos[i]>>edgeType[i]>>inputNeuronIndex[i];
}
}
for(int i=0;i<EDGENUM;i++)
{
outputLine[i].Serialize(ar);
}
}
NeuralNode& NeuralNode::operator =(const NeuralNode &s)
{
activeFunction=s.activeFunction;
bias=s.bias;
centerPos=s.centerPos;
for(int i=0;i<EDGENUM;i++)
{
edgeNodePos[i]=s.edgeNodePos[i];
inputNeuronIndex[i]=s.inputNeuronIndex[i];
outputLine[i]=s.outputLine[i];
edgeType[i]=s.edgeType[i];
}
layerIndex=s.layerIndex;
neuronIndex=s.neuronIndex;
nodePos=s.nodePos;
totalIndex=s.totalIndex;
return *this;
}
NeuralNode::NeuralNode( const NeuralNode &s )
{
activeFunction=s.activeFunction;
bias=s.bias;
centerPos=s.centerPos;
for(int i=0;i<EDGENUM;i++)
{
edgeNodePos[i]=s.edgeNodePos[i];
inputNeuronIndex[i]=s.inputNeuronIndex[i];
outputLine[i]=s.outputLine[i];
edgeType[i]=s.edgeType[i];
}
layerIndex=s.layerIndex;
neuronIndex=s.neuronIndex;
nodePos=s.nodePos;
totalIndex=s.totalIndex;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -