我正在尝试使用 visual studio 2013 在 c++ 中构建一个多层感知器网络。首先,我为第一层的中子创建了一个结构,但是当我运行它时,出现了堆栈溢出错误。这是我的代码:
#include "stdafx.h"
#include <iostream>
#include <math.h>
#include <fstream>
#include <vector>
// Number of Neurons
#define INPUTS 784
#define INPNEUR 784
#define HIDNEUR 500
#define OUTNEUR 10
struct inpneuron {
int number;
double weights[INPUTS];
double bias;
double inputs[INPUTS];
double output;
double delta;
};
typedef struct inpneuron InpNeuron;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int i, j, x[INPUTS];
InpNeuron InputLayer[INPNEUR];
system("PAUSE");
return 0;
}
它给出的异常是:多层感知器 MNIST.exe 中 0x00302CB7 处未处理的异常:0xC00000FD:堆栈溢出(参数:0x00000000、0x00522000)。
我在编程方面经验很少,但我认为这是一个内存问题,因为当我减少神经元或输入的数量时,它会起作用。有什么方法可以让它与这么多的神经元和输入一起工作吗?
最佳答案
这一行
InpNeuron InputLayer[INPNEUR];
在堆栈上分配大量内存,超过默认可用的内存。您应该改用 std::vector
:
std::vector<InpNeuron> InputLayer(INPNEUR);
从堆中安全地分配必要的内存。
关于c++ - 堆栈溢出多层感知器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29194318/