internal static void ConvolutionalLayer2D(Index2 currentInput, ArrayView3D <float> weights, ArrayView2D <float> error, ArrayView2D <float> activatedPreviousLayer, ArrayView2D <float> bias, ArrayView <float> variables) { int radius = (int)variables[new Index1(2)]; int diameter = radius * 2 + 1; var fac = error[currentInput] * variables[new Index1(0)]; float xBounds = error.Extent.X; float yBounds = error.Extent.Y; bias[currentInput] -= fac; var baseIndex = new Index2(currentInput.X - radius, currentInput.Y - radius); for (int i = 0; i < diameter; i++) { for (int j = 0; j < diameter; j++) { var asosInput = baseIndex.Add(new Index2(i, j)); if (asosInput.X < xBounds & asosInput.X >= 0 & asosInput.Y >= 0 & asosInput.Y < yBounds) { var adjustment = fac * activatedPreviousLayer[asosInput]; var d = activatedPreviousLayer[asosInput]; if (float.IsNaN(adjustment) | float.IsInfinity(adjustment)) { ; } weights[new Index3(currentInput, i * diameter + j)] -= adjustment; } } } }
internal static void ConvolutionalLayer2D(Index2 currentInput, ArrayView3D <float> weight, ArrayView2D <float> outputPreviousLayerActivated, ArrayView2D <float> sumInput, ArrayView2D <float> bias, ArrayView <float> variables) { int radius = (int)variables[new Index1(1)]; int diameter = radius * 2 + 1; var baseIndex = new Index2(currentInput.X - radius, currentInput.Y - radius); var xBounds = outputPreviousLayerActivated.Extent.X; var yBounds = outputPreviousLayerActivated.Extent.Y; float sum = bias[currentInput]; for (int i = 0; i < diameter; i++) { for (int j = 0; j < diameter; j++) { var asosInput = baseIndex.Add(new Index2(i, j)); if (asosInput.X < xBounds & asosInput.X >= 0 & asosInput.Y >= 0 & asosInput.Y < yBounds) { sum += weight[new Index3(currentInput, i * diameter + j)] * outputPreviousLayerActivated[asosInput]; var w = weight[new Index3(currentInput, i * diameter + j)]; var oA = outputPreviousLayerActivated[asosInput]; if (float.IsNaN(w * oA) | float.IsInfinity(w * oA)) { ; } } } } sumInput[currentInput] = sum; if (float.IsNaN(sum) | float.IsInfinity(sum)) { ; } }
private static void UpdateBKernel(Index2 index, ArrayView2D <float> candidates, ArrayView2D <float> psf2, ArrayView <Pixel> pixel) { var indexCandidate = index.Add(new Index2(pixel[0].X, pixel[0].Y)).Subtract(psf2.Extent / 2); if (index.InBounds(psf2.Extent) & indexCandidate.InBounds(candidates.Extent) & pixel[0].AbsDiff > 0) { candidates[indexCandidate] -= (psf2[index] * pixel[0].Sign * pixel[0].AbsDiff); } }
internal static void ConvolutionalLayer2D(Index2 currentInput, ArrayView2D <float> error, ArrayView2D <float> errorNextLayer, ArrayView3D <float> weightNextLayer, ArrayView2D <float> derived, ArrayView2D <float> should, ArrayView <float> variable) { int radius = (int)variable[new Index1(2)]; int diameter = radius * 2 + 1; int xBounds = (int)errorNextLayer.Extent.X; int yBounds = (int)errorNextLayer.Extent.Y; var baseIndex = new Index2(currentInput.X - radius, currentInput.Y - radius); float sum = 0.0f; for (int i = 0; i < diameter; i++) { for (int j = 0; j < diameter; j++) { var asosInput = baseIndex.Add(new Index2(i, j)); if (asosInput.X < xBounds & asosInput.X >= 0 & asosInput.Y >= 0 & asosInput.Y < yBounds) { sum += errorNextLayer[asosInput] * weightNextLayer[new Index3(currentInput, i * diameter + j)]; } } } error[currentInput] = sum * derived[currentInput]; var d = derived[currentInput]; var e = error[currentInput]; int c = 0; while (error[currentInput] > 1 | error[currentInput] < -1) { error[currentInput] /= 10; c++; if (c > 20) { ; } } if (float.IsNaN(error[currentInput]) | float.IsInfinity(e) | sum > 1000 | sum < -1000) { ; } }