/// <summary> /// Construct a neural network from a <see cref="NetworkDescription"/> /// </summary> public NeuralNetwork(NetworkDescription description) { //Ensure we can construct a nerual network from this description ValidateLayers(description); ConstructLayers(description); }
private void ConstructLayers(NetworkDescription description) { _layers = new NetworkLayer[description.Layers.Count]; for (int i = 0; i < description.Layers.Count; i++) { if (i == 0) { _layers[i] = NetworkLayer.ConstructLayer(description.Layers[i]); } else { _layers[i] = NetworkLayer.ConstructLayer(description.Layers[i], description.Layers[i - 1]); } } }
private void ValidateLayers(NetworkDescription description) { if (description.Layers == null || description.Layers.Count < 2) { throw new ArgumentException("A neural network must have at least 2 layers (one input and one output)"); } if (description.Layers[0].LayerType != ELayerType.Input) { throw new ArgumentException("The first layer of a neural network must be a input layer", nameof(description)); } if (description.Layers[description.Layers.Count - 1].LayerType != ELayerType.Output) { throw new ArgumentException("The last layer of a neural network must be a output layer", nameof(description)); } }