public void CanRunWithZeroInput() { Layer layer = Layer.CreateLinearLayer(new NeuralNet.WeightsMatrix(new double[, ] { { 1 } })); NetComponentChain layerlist = new NetComponentChain(layer); NeuralNet.NetworkVector vector = new NeuralNet.NetworkVector(new double[] { 0 }); NetworkVector result = layerlist.Run(vector); Assert.AreEqual(vector, result); }
public void CannotRunWithInputOfWrongSize() { Layer layer = Layer.CreateLinearLayer(new NeuralNet.WeightsMatrix(new double[, ] { { 1 } })); NetComponentChain layerlist = new NetComponentChain(layer); NeuralNet.NetworkVector input = new NeuralNet.NetworkVector(new double[] { 0, 0 }); try { layerlist.Run(input); Assert.Fail("Run should throw an ArgumentException for input of the wrong size, but did not."); } catch (ArgumentException) { } }
public void CanRunTwoLayersWithZeroInput() { Layer layer1 = new Layer(new NeuralNet.WeightsMatrix(new double[, ] { { 1, 1 }, { 1, 1 } })); Layer layer2 = Layer.CreateLinearLayer(new NeuralNet.WeightsMatrix(new double[, ] { { 1, 1 } })); NetComponentChain layerlist = new NetComponentChain(layer1); layerlist.AddFixed(layer2); NeuralNet.NetworkVector vector = new NeuralNet.NetworkVector(new double[] { 0, 0 }); NetworkVector result = layerlist.Run(vector); NeuralNet.NetworkVector outputCheck = new NeuralNet.NetworkVector(new double[] { 0 }); Assert.AreEqual(outputCheck, result); }
public void CanRunTwoLayerNetWithOneInput() { Layer inputlayer = new Layer(new NeuralNet.WeightsMatrix(new double[, ] { { 1, 1, 1 }, { 1, 1, 1 } })); Layer outputlayer = Layer.CreateLinearLayer(new NeuralNet.WeightsMatrix(new double[, ] { { 1, 1 } })); NetComponentChain network = new NetComponentChain(); network.AddFixed(inputlayer); network.AddTrainable(outputlayer); NeuralNet.NetworkVector inputvector = new NeuralNet.NetworkVector(new double[] { 1, 0, 0 }); NetworkVector result = network.Run(inputvector); NeuralNet.NetworkVector outputCheck = new NeuralNet.NetworkVector(new double[] { 2 }); Assert.AreEqual(outputCheck, result); }
public void CanBackPropagateTwoLayerNetGradient1() { Layer inputlayer = new Layer(new NeuralNet.WeightsMatrix(new double[, ] { { 1, 1, 1 }, { 1, 1, 1 } })); Layer outputlayer = Layer.CreateLinearLayer(new NeuralNet.WeightsMatrix(new double[, ] { { 1, 1 } })); NetComponentChain network = new NetComponentChain(); network.AddFixed(inputlayer); network.AddTrainable(outputlayer); NeuralNet.NetworkVector inputvector = new NeuralNet.NetworkVector(new double[] { 1, 0, 0 }); NeuralNet.NetworkVector outputgradient = new NeuralNet.NetworkVector(new double[] { 1 }); network.Run(inputvector); NeuralNet.NetworkVector inputGradientCheck = new NeuralNet.NetworkVector(new double[] { 2, 2, 2 }); Assert.AreEqual(inputGradientCheck, network.InputGradient(outputgradient)); }