KeyValuePair <double, double[, , ]> SetBackwardErrors(double[,,] input, double[,,] t) { double[,,] output = GetOutput(input); //Console.WriteLine("{0} {1}", (float)output[0, 0, 0], (float)output[0, 0, 1]); int depth2 = output.GetLength(0); int height2 = output.GetLength(1); int width2 = output.GetLength(2); double val = 0; double temp = 0; double[,,] out_err = errors.Last(); double[,,] diff = layers.Last().GetCachedDiff(); for (int z2 = 0; z2 < depth2; z2++) { for (int y2 = 0; y2 < height2; y2++) { for (int x2 = 0; x2 < width2; x2++) { temp = t[z2, y2, x2] - output[z2, y2, x2]; out_err[z2, y2, x2] = -temp * diff[z2, y2, x2]; val += temp * temp; } } } errors[errors.Count - 1] = out_err; for (int i = layers.Count - 1; i >= 0; i--) { Layer prev = null; if (i != 0) { prev = layers[i - 1]; if (prev != null) { errors[i - 1] = layers[i].GetError(errors[i], prev.GetCachedDiff(), prev.GetCachedOutpur()); } else { double[,,] diff2 = (double[, , ])input.Clone(); diff2.ForEach(x => 1); errors[i - 1] = layers[i].GetError(errors[i], diff2, input); } } } return(new KeyValuePair <double, double[, , ]>(val, output)); }