public void LogisticCorrectRun() { Layer layer = new Layer( new WeightsMatrix( Matrix <double> .Build.DenseOfArray(new double[, ] { { 2, 3, 5 } }) ), new BiasesVector(1), NeuralFunction.__Logistic, NeuralFunction.__LogisticDerivative ); VectorBatch input = new VectorBatch( Matrix <double> .Build.DenseOfArray(new double[, ] { { 7, 11, 13 } }) ); VectorBatch outputcheck = new VectorBatch( Matrix <double> .Build.DenseOfArray(new double[, ] { { NeuralFunction.__Logistic(112) } }) ); VectorBatch result = layer.Run(input); Assert.AreEqual(outputcheck, result); }
public void CanBack2() { wc_2.Run(inputBatch_2); VectorBatch inputGradient = wc_2.BackPropagate(gradientBatch2); Assert.AreEqual(inputGradientCheck, inputGradient); }
public void CorrectRun() { Layer layer = new Layer( new WeightsMatrix( Matrix <double> .Build.DenseOfArray(new double[, ] { { 2, 3, 5 } }) ) ); VectorBatch input = new VectorBatch( Matrix <double> .Build.DenseOfArray(new double[, ] { { 7, 11, 13 } }) ); VectorBatch outputcheck = new VectorBatch( Matrix <double> .Build.DenseOfArray(new double[, ] { { 112 } }) ); VectorBatch result = layer.Run(input); Assert.AreEqual(outputcheck, result); }
public void LogisticInputGradient() { Layer layer = new Layer( new WeightsMatrix( Matrix <double> .Build.DenseOfArray(new double[, ] { { 1 } }) ), new BiasesVector(1), NeuralFunction.__Logistic, NeuralFunction.__LogisticDerivative ); DataVector zeroVector = new DataVector(1); VectorBatch result = layer.Run(zeroVector); DataVector oneVector = new DataVector( Vector <double> .Build.DenseOfArray(new double[] { 1 }) ); VectorBatch inputGradient = layer.BackPropagate(oneVector); DataVector inputGradientCheck = new DataVector( Vector <double> .Build.DenseOfArray( new double[] { NeuralFunction.__LogisticDerivative(0, NeuralFunction.__Logistic(0)) }) ); Assert.AreEqual(inputGradientCheck, inputGradient); }
public void CanRun1() { VectorBatch result = wc_1.Run(inputBatch_1); VectorBatch outcheck = inputBatch_1; Assert.AreEqual(outcheck, result); }
public void AsMatrix() { NetworkVector vector = new NetworkVector(new double[] { 1, 2, 3 }); VectorBatch batch = new VectorBatch(new List <NetworkVector> { vector, vector }); Matrix <double> result = batch.AsMatrix(); }
public void CanBack1() { wc_1b.Run(inputBatch_1); VectorBatch inputGradient = wc_1b.BackPropagate(gradientBatch1); VectorBatch inputGradientCheck = gradientBatch1; Assert.AreEqual(inputGradientCheck, inputGradient); }
public void CanRun2() { VectorBatch result = wc_2.Run(inputBatch_2); VectorBatch outcheck = new VectorBatch( Matrix <double> .Build.DenseOfArray(new double[, ] { { 25, 32 }, { 31, 41 } })); Assert.AreEqual(outcheck, result); }
public void CanRunBatch() { VectorBatch result = wc_2.Run(input_batch); for (int i = 0; i < input_batch.AsMatrix().RowCount; i++) { Assert.AreEqual( wc_2.Run(input_batch[i]), result[i] ); } }
public void Dimension() { Vector <double> vector1 = Vector <double> .Build.Dense(new double[] { 0, 1, 2, 3 }); Vector <double> vector2 = Vector <double> .Build.Dense(new double[] { 1, 2, 3, 4 }); List <NetworkVector> vectors = new List <NetworkVector> { new NetworkVector(vector1), new NetworkVector(vector2) }; VectorBatch batch = new VectorBatch(vectors); Assert.AreEqual(vectors[0].Dimension, batch.Dimension); }
public void CanRun() { Layer layer = new Layer( new WeightsMatrix( Matrix <double> .Build.DenseOfArray(new double[, ] { { 1 } }) ) ); DataVector zeroVector = new DataVector(1); VectorBatch result = layer.Run(zeroVector); Assert.AreEqual(zeroVector, result); }
public void CannotSubractMismatched() { try { VectorBatch vb1 = new VectorBatch(Matrix <double> .Build.DenseOfArray(new double[, ] { { 1, 2 }, { 2, 3 } })); VectorBatch vb2 = new VectorBatch(Matrix <double> .Build.DenseOfArray(new double[, ] { { 2, 3, 4 }, { 3, 4, 5 } })); VectorBatch vb3 = vb2.Subtract(vb1); Assert.Fail("Subtract failed to throw an ArgumentOutOfRangeException."); } catch (ArgumentOutOfRangeException) { } }
public void CanSubtract() { VectorBatch vb1 = new VectorBatch(Matrix <double> .Build.DenseOfArray(new double[, ] { { 1, 2, 3 }, { 2, 3, 4 } })); VectorBatch vb2 = new VectorBatch(Matrix <double> .Build.DenseOfArray(new double[, ] { { 2, 3, 4 }, { 3, 4, 5 } })); VectorBatch vb3 = vb2.Subtract(vb1); Assert.AreEqual(1, vb3[0, 0]); Assert.AreEqual(1, vb3[0, 1]); Assert.AreEqual(1, vb3[0, 2]); Assert.AreEqual(1, vb3[1, 0]); Assert.AreEqual(1, vb3[1, 1]); Assert.AreEqual(1, vb3[1, 2]); }
public void CanAdd() { VectorBatch vb1 = new VectorBatch(Matrix <double> .Build.DenseOfArray(new double[, ] { { 1, 2, 3 }, { 2, 3, 4 } })); VectorBatch vb2 = new VectorBatch(Matrix <double> .Build.DenseOfArray(new double[, ] { { 2, 3, 4 }, { 3, 4, 5 } })); VectorBatch vb3 = vb1.Add(vb2); Assert.AreEqual(3, vb3[0, 0]); Assert.AreEqual(5, vb3[0, 1]); Assert.AreEqual(7, vb3[0, 2]); Assert.AreEqual(5, vb3[1, 0]); Assert.AreEqual(7, vb3[1, 1]); Assert.AreEqual(9, vb3[1, 2]); }
public void RunAfterBackPropIsCorrect() { VectorBatch result; result = wc_2.Run(inputBatch_2); VectorBatch inputGradient = wc_2.BackPropagate(gradientBatch2); result = wc_2.Run(inputBatch_2); VectorBatch resultCheck = new VectorBatch( Matrix <double> .Build.DenseOfArray(new double[, ] { { -32, -61 }, { -50, -91 } }) ); Assert.AreEqual(resultCheck, result); }
public void CanMake() { try { VectorBatch vb1 = new VectorBatch(Matrix <double> .Build.Dense(1, 1)); VectorBatch vb2 = new VectorBatch( Matrix <double> .Build.DenseOfArray( new double[, ] { { 1, 2 }, { 2, 3 } } ) ); VectorBatch vb3 = new VectorBatch(vb1); } catch (Exception e) { Assert.Fail("VectorBatch constructor threw an exception: " + e.Message); } }
public void CanMake_IEnumerable() { Vector <double> vector1 = Vector <double> .Build.Dense(new double[] { 0, 1, 2, 3 }); Vector <double> vector2 = Vector <double> .Build.Dense(new double[] { 1, 2, 3, 4 }); List <NetworkVector> vectors = new List <NetworkVector> { new NetworkVector(vector1), new NetworkVector(vector2) }; try { VectorBatch batch = new VectorBatch(vectors); } catch (Exception e) { Assert.Fail("VectorBatch constructor threw an exception. Message: " + e.Message); } }
public void CanMake_Matrix() { Vector <double> vector1 = Vector <double> .Build.Dense(new double[] { 0, 1, 2, 3 }); Vector <double> vector2 = Vector <double> .Build.Dense(new double[] { 1, 2, 3, 4 }); Matrix <double> vectors = Matrix <double> .Build.DenseOfRowVectors( new List <Vector <double> > { vector1, vector2 }); try { VectorBatch batch = new VectorBatch(vectors); } catch (Exception e) { Assert.Fail("VectorBatch constructor threw an exception. Message: " + e.Message); } }
public void InputGradient() { Layer layer = new Layer( new WeightsMatrix( Matrix <double> .Build.DenseOfArray(new double[, ] { { 1 } }) ) ); DataVector zeroVector = new DataVector(1); VectorBatch result = layer.Run(zeroVector); DataVector oneVector = new DataVector( Vector <double> .Build.DenseOfArray(new double[] { 1 }) ); VectorBatch inputGradient = layer.BackPropagate(oneVector); DataVector inputGradientCheck = oneVector; Assert.AreEqual(inputGradientCheck, inputGradient); }
public void CanUpdateBatch() { AdaptationStrategy strategy = new GradientDescent(1.0, 1); VectorBatch result = wc_2.Run(input_batch); wc_2.BackPropagate(gradient_batch); VectorBatch inputGradient = wc_2.InputGradient(gradient_batch); wc_2.Update(strategy); NetworkVector biasesCheck = new NetworkVector(new double[] { 8, 7 }); WeightsMatrix weightsCheck = new WeightsMatrix(new double[, ] { { -4, -6, -8 }, { -6, -10, -14 } }); Assert.AreEqual(biasesCheck, wc_2.Biases); Assert.AreEqual(weightsCheck, wc_2.Weights); for (int i = 0; i < inputGradient.Count; i++) { Assert.AreEqual(inputgradient_check[i], inputGradient[i]); } }