public void CanMakeAndReadZeroNetworkVector() { NetworkVector vector = new NetworkVector(2); Assert.AreEqual(0.0, vector.ToArray()[0]); Assert.AreEqual(0.0, vector.ToArray()[1]); }
public void CanZeroNetworkVector() { NetworkVector vector = new NetworkVector(new double[] { 1, 2 }); vector.Zero(); Assert.AreEqual(0.0, vector.ToArray()[0]); Assert.AreEqual(0.0, vector.ToArray()[1]); }
public void CanMakeAndRead_1_2_NetworkVector() { NetworkVector vector = new NetworkVector(new double[] { 1, 2 }); double[] vectorValues = vector.ToArray(); Assert.AreEqual(1.0, vectorValues[0]); Assert.AreEqual(2.0, vectorValues[1]); }
public void CanApplyFunctionComponentwise() { NetworkVector.SingleVariableFunction f = x => x - 1; NetworkVector vector = new NetworkVector(new double[] { 1, 2 }); NetworkVector newvector = NetworkVector.ApplyFunctionComponentWise(vector, f); double[] vectorValues = newvector.ToArray(); Assert.AreEqual(0.0, vectorValues[0]); Assert.AreEqual(1.0, vectorValues[1]); }
public void CanCopy() { NetworkVector vector1 = new NetworkVector(new double[] { 1, 0 }); NetworkVector vector2 = vector1.Copy(); double[] vector1Values = vector1.ToArray(); double[] vector2Values = vector2.ToArray(); Assert.AreEqual(vector1Values[0], vector2Values[0]); Assert.AreEqual(vector1Values[1], vector2Values[1]); }
public void CanSubtract() { NetworkVector vector = new NetworkVector(new double[] { 1, 2, 3, 4, 5 }); vector.Subtract(vector); double[] vectorValues = vector.ToArray(); for (int i = 0; i < vectorValues.Length; i++) { Assert.AreEqual(0.0, vectorValues[i]); } }
public void CanBackSigmoid() { NetworkVector result = nf_sigmoid.Run(vector_2); double[] outarray = result.ToArray(); double[] inarray = vector_2.ToArray(); NetworkVector gradientCheck = new NetworkVector( new double[] { sigmoidDerivative(inarray[0], outarray[0]), sigmoidDerivative(inarray[1], outarray[1]) }); Assert.AreEqual(gradientCheck, nf_sigmoid.InputGradient(vector_2, vector_2, result)); }
public void CanLeftMultiply() { WeightsMatrix matrix = new WeightsMatrix(new double[, ] { { 0, 1 }, { 1, 0 } }); NetworkVector vector = new NetworkVector(new double[] { 1, 1 }); NetworkVector result = matrix.LeftMultiply(vector); double[] resultValues = result.ToArray(); Assert.AreEqual(1, resultValues[0]); Assert.AreEqual(1, resultValues[1]); }
public void CanMakeAndReadBigNetworkVector() { int size = 10000; double[] array = new double[size]; for (int i = 0; i < size; i++) { array[i] = i; } NetworkVector vector = new NetworkVector(array); double[] vectorValues = vector.ToArray(); for (int i = 0; i < size; i++) { Assert.AreEqual(array[i], vectorValues[i]); } }
public void CanSum() { int listSize = 100; NetworkVector vector = new NetworkVector(new double[] { 0, 1, 2, 3, 4, 5 }); List <NetworkVector> list = new List <NetworkVector>(); for (int i = 0; i < listSize; i++) { list.Add(vector); } vector = NetworkVector.Sum(list); double[] result = vector.ToArray(); for (int i = 0; i < vector.Dimension; i++) { Assert.AreEqual(i * listSize, result[i]); } }
public void RunProducesCorrectOutput() { SoftMaxUnit smu = new SoftMaxUnit(7); NetworkVector input = new NetworkVector(new double[] { 1, 0, 0, 0, 0, 0, 1 }); NetworkVector output = smu.Run(input); double sum = 5 + (2 * Math.E); double one_value = Math.E / sum; double zero_value = 1 / sum; double delta = 0.000000001; double[] outputvalues = output.ToArray(); double outputvaluessum = output.SumValues(); Assert.AreEqual(1.0, outputvaluessum, delta); Assert.AreEqual(one_value, outputvalues[0], delta); Assert.AreEqual(one_value, outputvalues[6], delta); for (int i = 1; i < smu.NumberOfOutputs - 1; i++) { Assert.AreEqual(zero_value, outputvalues[i], delta); } }