/// <summary> /// 前向传播,计算卷积结果 /// </summary> public double[,] CalculatedConvolutionResult(List <double[, ]> value) { InputValue = value; double[,] result = new double[ConvolutionKernelWidth, ConvolutionKernelHeight]; for (int i = 0; i < ConvolutionKernelWidth; i++) { for (int j = 0; j < ConvolutionKernelHeight; j++) { for (int k = 0; k < value.Count; k++) { result[i, j] += CalculatedConvolutionPointResult(value[k], i, j, k);//卷积 } } } if (Standardization) { mean = CnnHelper.GetMean(result); variance = CnnHelper.GetVariance(result, mean); } //归一化每个结果 for (int i = 0; i < ConvolutionKernelWidth; i++) { for (int j = 0; j < ConvolutionKernelHeight; j++) { if (Standardization) { //调用激活函数计算结果 double z = (result[i, j] - mean) / Math.Sqrt(variance); //if (double.IsNaN(z)) // z = result[i, j] > 0 ? 1 : -1; result[i, j] = ActivationFunction(z + OutputOffset); } else { result[i, j] = ActivationFunction(result[i, j] + OutputOffset); } } } //正则化 if (CnnHelper.RandomObj.NextDouble() < dropoutChance) { for (int i = 0; i < ConvolutionKernelWidth; i++) { for (int j = 0; j < ConvolutionKernelHeight; j++) { result[i, j] = 0; } } dropoutState = true; } OutputValue = result; return(result); }
/// <summary> /// 前向传播,计算结果 /// </summary> public double[] CalculatedResult(double[] inputValue) { InputValue = inputValue; double[] result = new double[OutputCount]; for (int i = 0; i < OutputCount; i++) { result[i] = CalculatedPointResult(inputValue, i); //result[i] = CalculatedPointResult(value, i) + OutputOffset[i]; //调用激活函数计算结果 if (!Standardization) { result[i] = ActivationFunction(result[i] + OutputOffset[i]); } } if (Standardization) { mean = CnnHelper.GetMean(result); variance = CnnHelper.GetVariance(result, mean); //归一化每个结果 for (int i = 0; i < OutputCount; i++) { //调用激活函数计算结果 double z = (result[i] - mean) / Math.Sqrt(variance); result[i] = ActivationFunction(z + OutputOffset[i]); } } //正则化 if (CnnHelper.RandomObj.NextDouble() < dropoutChance) { for (int i = 0; i < OutputCount; i++) { result[i] = 0; } dropoutState = true; } OutputValue = result; return(result); }