public BackPropagationNetwork(int[] layerSizes, TransferFunction[] transferFunctions) { // Validate the input data if (transferFunctions.Length != layerSizes.Length || transferFunctions[0] != TransferFunction.None) { throw new ArgumentException("Cannot construct a network with these parameters."); } // Initialize network layers layerCount = layerSizes.Length - 1; inputSize = layerSizes[0]; layerSize = new int[layerCount]; for (int i = 0; i < layerCount; i++) { layerSize[i] = layerSizes[i + 1]; } transferFunction = new TransferFunction[layerCount]; for (int i = 0; i < layerCount; i++) { transferFunction[i] = transferFunctions[i + 1]; } // Start dimensioning arrays bias = new double[layerCount][]; previousBiasDelta = new double[layerCount][]; delta = new double[layerCount][]; layerOutput = new double[layerCount][]; layerInput = new double[layerCount][]; weight = new double[layerCount][][]; previousWeightDelta = new double[layerCount][][]; // Fill 2 dimensional arrays for (int l = 0; l < layerCount; l++) { bias[l] = new double[layerSize[l]]; previousBiasDelta[l] = new double[layerSize[l]]; delta[l] = new double[layerSize[l]]; layerOutput[l] = new double[layerSize[l]]; layerInput[l] = new double[layerSize[l]]; weight[l] = new double[l == 0 ? inputSize : layerSize[l - 1]][]; previousWeightDelta[l] = new double[l == 0 ? inputSize : layerSize[l - 1]][]; for (int i = 0; i < (l == 0 ? inputSize : layerSize[l - 1]); i++) { weight[l][i] = new double[layerSize[l]]; previousWeightDelta[l][i] = new double[layerSize[l]]; } } // Initialize the weights for (int l = 0; l < layerCount; l++) { for (int j = 0; j < layerSize[l]; j++) { bias[l][j] = Gaussian.GetRandomGaussian(); previousBiasDelta[l][j] = 0.0; layerOutput[l][j] = 0.0; layerInput[l][j] = 0.0; delta[l][j] = 0.0; } for (int i = 0; i < (l == 0 ? inputSize : layerSize[l - 1]); i++) { for (int j = 0; j < layerSize[l]; j++) { weight[l][i][j] = Gaussian.GetRandomGaussian(); previousWeightDelta[l][i][j] = 0.0; } } } }
public BoltzmanMachine(int[] layerSizes, TransferFunction[] TransferFunctions) { // Перевірка вхідних даних if (TransferFunctions.Length != layerSizes.Length || TransferFunctions[0] != TransferFunction.None) { throw new ArgumentException("The network cannot be created with these parameters"); } // Ініціалізація шарів мережі layerCount = layerSizes.Length - 1; inputSize = layerSizes[0]; layerSize = new int[layerCount]; transferFunction = new TransferFunction[layerCount]; for (int i = 0; i < layerCount; i++) { layerSize[i] = layerSizes[i + 1]; } for (int i = 0; i < layerCount; i++) { transferFunction[i] = TransferFunctions[i + 1]; } // Визначення вимірів масивів bias = new double[layerCount][]; previosBiasDelta = new double[layerCount][]; delta = new double[layerCount][]; layerOtput = new double[layerCount][]; layerInput = new double[layerCount][]; weight = new double[layerCount][][]; previousWeightDelta = new double[layerCount][][]; // Заповнення двовимірних масивів for (int l = 0; l < layerCount; l++) { bias[l] = new double[layerSize[l]]; previosBiasDelta[l] = new double[layerSize[l]]; delta[l] = new double[layerSize[l]]; layerOtput[l] = new double[layerSize[l]]; layerInput[l] = new double[layerSize[l]]; weight[l] = new double[l == 0 ? inputSize : layerSize[l - 1]][]; previousWeightDelta[l] = new double[l == 0 ? inputSize : layerSize[l - 1]][]; for (int i = 0; i < (l == 0 ? inputSize : layerSize[l - 1]); i++) { weight[l][i] = new double[layerSize[l]]; previousWeightDelta[l][i] = new double[layerSize[l]]; } } // Ініціалізація ваг for (int l = 0; l < layerCount; l++) { for (int i = 0; i < layerSize[l]; i++) { bias[l][i] = Gaussian.GetRandomGaussian(); previosBiasDelta[l][i] = 0.0; layerInput[l][i] = 0.0; layerOtput[l][i] = 0.0; delta[l][i] = 0.0; } for (int i = 0; i < (l == 0 ? inputSize : layerSize[l - 1]); i++) { for (int j = 0; j < layerSize[l]; j++) { weight[l][i][j] = Gaussian.GetRandomGaussian(); previousWeightDelta[l][i][j] = 0.0; } } } }