我的代码中有一个for循环,它给整个循环本身一个错误,说它是"无法访问的代码"。我完全不确定这个循环导致了什么:
To enable debugging of unmanaged code
它在
之后声称整个for循环public ArrayList<Double> Update(ArrayList<Double> addInputs)
{
// stores the resultant outputs from each layer
ArrayList<Double> outputs = null;
int cWeight = 0;
// first check that we have the correct amount of inputs
if (addInputs.size() != numInputs);
{
// just return an empty vector if incorrect
return outputs;
}
// For each layer....
for (int i = 0; i < numHiddenLayers + 1; ++i)
{
if (i > 0)
{
addInputs = 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 < neuronLayers.get(i).numNeurons; ++j)
{
double netinput = 0;
int numberInputs = neuronLayers.get(i).listNeurons.get(j).numInputs;
// for each weight
for (int k = 0; k < numberInputs - 1; ++k)
{
// sum the weights x inputs
netinput += neuronLayers.get(i).listNeurons.get(j).weights.get(k) *
addInputs.get(cWeight++);
}
// add in the bias
netinput += neuronLayers.get(i).listNeurons.get(j).weights.get(numberInputs - 1)
* dBias;
// we can store the outputs from each layer as we generate them.
// the combined activation is first filtered through the sigmoid
//function
outputs.add(sigmoid(netinput,dActivationResponse));
}
}
是无法访问的代码。任何帮助将不胜感激。
答案 0 :(得分:3)
此处有分号,因此该方法始终返回outputs
。只需删除它
if (addInputs.size() != numInputs); // <---- this one
{
// just return an empty vector if incorrect
return outputs;
}
答案 1 :(得分:1)
if:
结尾处有一个分号... != numInputs);
意味着它下面的返回将始终发生,使其下的代码无法访问。
删除分号。
答案 2 :(得分:0)
这是因为if condition
因分号而终止
所以return
将始终执行哪个传输控制到调用函数跳过你的其余代码