神经网络-更新网络
Neural Networks- Updating the Network
我正在用Java构建我的第一个神经网络,并遵循这个C++示例在线
vector<double> CNeuralNet::Update(vector<double> &inputs)
{
//stores the resultant outputs from each layer
vector<double> outputs;
int cWeight = 0;
//first check that we have the correct amount of inputs
if (inputs.size() != m_NumInputs)
{
//just return an empty vector if incorrect.
return outputs;
}
//For each layer....
for (int i=0; i<m_NumHiddenLayers + 1; ++i)
{
if ( i > 0 )
{
inputs = outputs;
}
outputs.clear();
cWeight = 0;
//for each neuron sum the (inputs * corresponding weights).Throw
//the total at our sigmoid function to get the output.
for (int j=0; j<m_vecLayers[i].m_NumNeurons; ++j)
{
double netinput = 0;
int NumInputs = m_vecLayers[i].m_vecNeurons[j].m_NumInputs;
//for each weight
for (int k=0; k<NumInputs - 1; ++k)
{
//sum the weights x inputs
netinput += m_vecLayers[i].m_vecNeurons[j].m_vecWeight[k] *
inputs[cWeight++];
}
//add in the bias
netinput += m_vecLayers[i].m_vecNeurons[j].m_vecWeight[NumInputs-1] *
CParams::dBias;
//we can store the outputs from each layer as we generate them.
//The combined activation is first filtered through the sigmoid
//function
outputs.push_back(Sigmoid(netinput, CParams::dActivationResponse));
cWeight = 0;
}
}
return outputs;
}
关于这个代码,我有两个问题。首先,看似。。。输入到输出的奇怪分配
//For each layer....
for (int i=0; i<m_NumHiddenLayers + 1; ++i)
{
if ( i > 0 )
{
inputs = outputs;
}
outputs.clear();
这部分真的让我很困惑。他只是创建了输出。。。他为什么要把输出分配给输入?还有,为什么是++i?据我所知,在此之前的代码中,他仍然使用index[0],这就是我正在做的。为什么会突然改变?有理由离开最后一个吗?我知道,如果没有其他代码示例,这可能是一个很难理解的问题。。。
我的第二个问题是
//add in the bias
netinput += m_vecLayers[i].m_vecNeurons[j].m_vecWeight[NumInputs-1] *
CParams::dBias;
//we can store the outputs from each layer as we generate them.
//The combined activation is first filtered through the sigmoid
//function
outputs.push_back(Sigmoid(netinput, CParams::dActivationResponse));
CParams:dBias和CParams:dActivationResponse在此之前不会出现。我现在创建了两个静态的最终全局变量。我走对了吗?
如有任何帮助,我们将不胜感激。这是一个个人项目,自从两周前我第一次了解这个话题以来,我一直在思考这个话题。
我同意@kohakun的观点,我想把我的答案和他的答案相加。在我看来,输出被分配给输入,以计算下一层神经网络的输出。有时,在我工作的网络中,我们可以有多个层,在我的项目中,我有多个隐藏层,看看你的代码,这里可能有类似的安排。因此,我认为您可以将我们的答案与您的代码联系起来,这可能会在一定程度上解决您的疑问。
在for语句中,在循环再次开始之前,第三部分将不会执行,这意味着for(int i=0;i<10;++i)将与for(int i=0;i&llt;10;i++)完全相同。仅当i>0'输入=输出时;',这不是正确的行为吗?CParams应该是一个类或命名空间名称,它必须存在于整个项目中的某个位置。如果它是一个类名,我认为使用全局静态是可以的。
对于您的第一个问题:您将刚刚生成的输出分配给输入,以通过反向归纳来完善您的神经网络,这样它就可以学习了。
对于第二个问题:我认为你走在了正确的轨道上,因为偏差不会随着每次迭代而改变
- 从C++本机插件更新Vector3数组
- 我的神经网络不起作用 [XOR 问题]
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- 通过网络、跨平台传递std::变体是否安全
- cmake更新缓存的变量
- 如何在MNIST上提高网络运行的准确性
- 更新到莫哈韦后出现cmath错误
- Active Directory:从网络服务帐户下运行的Windows服务调用ADsOpenObject时失败
- OpenMP:并行更新数组总是需要减少数组吗
- 为什么我的变量没有更新,我的 LED 没有亮起?
- 指针没有更新它在void函数内部指向的值
- 如何在c++中获取要更新的值
- 已修改的LinkedList未在文本文件本身中更新
- Qt:当QListView获得新条目时,如何更新QStringList
- 更新的矢量元素不打印
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- 网络回复后Qt更新
- 我如何更新这个神经网络来使用图像像素数据
- 神经网络-更新网络