神经网络中的分段错误

发布于 2024-11-04 07:26:20 字数 885 浏览 1 评论 0原文

我一直在使用反向传播算法为神经网络编写代码,并且为了传播输入,我编写了以下代码,但仅对于两个输入,它显示分段错误。代码是否有任何错误。我无法弄清楚出去....

void propagateInput(int cur,int next)
{
    cout<<"propagating input"<<cur<<"  "<<next<<endl;   
    cout<<"Number of nerons : "<<neuronsInLayer[cur]<<"  "<<neuronsInLayer[next]<<endl;
    for(int i = 0;i < neuronsInLayer[next];i++)
    {
        neuron[next][i].output = 0;
        for(int j = 0;j < neuronsInLayer[cur];j++)
        {
            cout<<neuron[cur][j].output<<" ";
            cout<<neuron[next][i].weight[j]<<"\n";
            neuron[next][i].output += neuron[next][i].weight[j] * neuron[cur][j].output;
        }
        cout<<"out["<<i<<"] = "<<neuron[next][i].output<<endl;
    }
    cout<<"completed propagating input.\n";
}

I have been writing a code for a neural network using back propagation algorithm and for propagating inputs I have written the following code,but just for two inputs,its displaying segmentation fault.Is there any wrong withe code.I wan not able to figure it out....

void propagateInput(int cur,int next)
{
    cout<<"propagating input"<<cur<<"  "<<next<<endl;   
    cout<<"Number of nerons : "<<neuronsInLayer[cur]<<"  "<<neuronsInLayer[next]<<endl;
    for(int i = 0;i < neuronsInLayer[next];i++)
    {
        neuron[next][i].output = 0;
        for(int j = 0;j < neuronsInLayer[cur];j++)
        {
            cout<<neuron[cur][j].output<<" ";
            cout<<neuron[next][i].weight[j]<<"\n";
            neuron[next][i].output += neuron[next][i].weight[j] * neuron[cur][j].output;
        }
        cout<<"out["<<i<<"] = "<<neuron[next][i].output<<endl;
    }
    cout<<"completed propagating input.\n";
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风吹短裙飘 2024-11-11 07:26:21
for(int i = 0;i < neuronsInLayer[next];i++)...

NeurosInLayer[next] 是一个指针。也许如果我知道层中神经元的类型,我可以为您提供更多帮助。

for(int i = 0;i < neuronsInLayer[next];i++)...

neuronsInLayer[next] is a pointer. perhaps if i knew the type of neuronsInLayer i could assist you more.

一身骄傲 2024-11-11 07:26:21

这些信息远远不足以调试您的代码。没有有关行号或结构在内存中如何布局或哪些结构有效等的信息。

所以让我告诉您如何自己找到它。如果您使用的是 Unix/Mac,则在可执行文件上使用 GDB 调试器,a.out:

$ gdb a.out
> run
*segfault*
> where

Visual Studio 也有一个很棒的调试器,只需在调试模式下运行它,它会告诉您段错误在哪里,并让您检查内存。

That is not anywhere near enough information to debug your code. No info about line numbers or how the structures are laid out in memory or which ones are valid, etc.

So let me tell you how you can find this yourself. If you're using a Unix/Mac then use the GDB debugger on your executable, a.out:

$ gdb a.out
> run
*segfault*
> where

Visual Studio has a great debugger as well, just run it in Debug mode and it'll tell you where the segfault is and let you inspect memory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文