/// <summary> /// Initializes a new instance of the <see cref="NnLayer"/> class with the specified parameters. /// </summary> /// <param name="numberOfInputs">The number of inputs.</param> /// <param name="numberOfOutputs">The number of outputs.</param> /// <param name="activationFunction">The activation function.</param> public NnLayer(int numberOfInputs, int numberOfOutputs, IActivationFunction activationFunction) { Contracts.ValueGreaterThanZero(numberOfInputs, nameof(numberOfInputs)); Contracts.ValueGreaterThanZero(numberOfOutputs, nameof(numberOfOutputs)); Contracts.ValueNotNull(activationFunction, nameof(activationFunction)); _numberOfInputs = numberOfInputs; _numberOfOutputs = numberOfOutputs; _activationFunction = activationFunction; _weightMatrix = new WeightMatrix(_numberOfInputs, _numberOfOutputs); _biasVector = new BiasVector(_numberOfOutputs); }
/// <summary> /// Initializes a new instance of the <see cref="NnLayer"/> class with the specified parameters. /// </summary> /// <param name="weightsRowCount">The number of row in the weight matrix.</param> /// <param name="weightsColCount">The number of columns in the weight matrix.</param> /// <param name="biasLength">The bias length.</param> /// <param name="data">The values of the weights and biases.</param> /// <param name="activationFunction">The activation function.</param> public NnLayer(int weightsRowCount, int weightsColCount, int biasLength, double[] data, IActivationFunction activationFunction) { Contracts.ValueGreaterThanZero(weightsRowCount, nameof(weightsRowCount)); Contracts.ValueGreaterThanZero(weightsColCount, nameof(weightsColCount)); Contracts.ValueGreaterThanZero(biasLength, nameof(biasLength)); Contracts.ValueNotNull(activationFunction, nameof(activationFunction)); _numberOfInputs = weightsRowCount; _numberOfOutputs = weightsColCount; _weightMatrix = new WeightMatrix(VectorUtilities.CreateMatrix(weightsRowCount, weightsColCount, data)); var biasData = new double[biasLength]; Buffer.BlockCopy(data, weightsRowCount * weightsColCount * sizeof(double), biasData, 0, biasLength * sizeof(double)); _biasVector = new BiasVector(biasData); _activationFunction = activationFunction; }