/// <summary> /// Adds two matrices together /// </summary> /// <param name="inputs1">Matrix 1</param> /// <param name="inputs2">Matrix 2</param> public void Calculate(List <double[]> inputs1, List <double[]> inputs2) { ZVals = new List <double[]>(); if (inputs1.Count != inputs2.Count) { throw new Exception("List sizes do not match"); } for (int b = 0; b < NN.BatchSize; b++) { if (inputs1[b].Length != inputs2[b].Length) { throw new Exception("Array sizes do not match"); } double[] output = new double[inputs1[b].Length]; for (int i = 0; i < inputs1[b].Length; i++) { output[i] = inputs1[b][i] + inputs2[b][i]; } ZVals.Add(output); } //If normalizing, do so, but only if it won't return an all-zero matrix if (NN.NormOutputs && ZVals[0].Length > 1) { ZVals = Maths.Normalize(ZVals); } //Use the specified type of activation function if (ActivationFunction == 0) { Values = Maths.Tanh(ZVals); return; } if (ActivationFunction == 1) { Values = Maths.ReLu(ZVals); return; } else { Values = ZVals; } }
public override void Calculate(List <double[]> inputs, bool output) { ZVals = new List <double[]>(); for (int i = 0; i < NN.BatchSize; i++) { ZVals.Add(Maths.Convert(Pool(Maths.Convert(inputs[i]), output))); } //If normalizing, do so, but only if it won't return an all-zero matrix if (NN.NormOutputs && ZVals[0].Length > 1) { ZVals = Maths.Normalize(ZVals); } //Use the specified type of activation function if (ActivationFunction == 0) { Values = Maths.Tanh(ZVals); return; } if (ActivationFunction == 1) { Values = Maths.ReLu(ZVals); return; } Values = ZVals; }
/// <summary> /// Calculates the dot product of the kernel and input matrix. /// Matrices should be size [x, y] and [y], respectively, where x is the output size and y is the latent space's size /// </summary> /// <param name="inputs">The input matrix</param> /// <param name="isoutput">Whether to use hyperbolic tangent on the output</param> /// <returns></returns> public override void Calculate(List <double[]> inputs, bool isoutput) { ZVals = new List <double[]>(); for (int b = 0; b < NN.BatchSize; b++) { ZVals.Add(Maths.Convert(DownOrUp ? Convolve(Weights, Pad(Maths.Convert(inputs[b]))) : FullConvolve(Weights, Pad(Maths.Convert(inputs[b]))))); } //If normalizing, do so, but only if it won't return an all-zero matrix if (NN.NormOutputs && ZVals[0].Length > 1) { ZVals = Maths.Normalize(ZVals); } //Use the specified type of activation function if (ActivationFunction == 0) { Values = Maths.Tanh(ZVals); return; } if (ActivationFunction == 1) { Values = Maths.ReLu(ZVals); return; } Values = ZVals; }
public override void Calculate(List <double[]> inputs, bool output) { ZVals = new List <double[]>(); for (int b = 0; b < NN.BatchSize; b++) { var vals = new double[Length]; for (int k = 0; k < Length; k++) { //Values = (weights * inputs) + biases for (int j = 0; j < InputLength; j++) { vals[k] += Weights[k, j] * inputs[b][j]; } //Output layers don't use biases if (!output) { vals[k] += Biases[k]; } } ZVals.Add(vals); } //If normalizing, do so, but only if it won't return an all-zero matrix if (NN.NormOutputs && ZVals[0].Length > 1) { ZVals = Maths.Normalize(ZVals); } //Use the specified type of activation function if (ActivationFunction == 0) { Values = Maths.Tanh(ZVals); return; } if (ActivationFunction == 1) { Values = Maths.ReLu(ZVals); return; } Values = ZVals; }