/// <summary> /// Create a new neural network /// with "inputs" inputs and size of "layers" /// layers of neurones. /// The layer i is made with layers_desc[i] neurones. /// The activation function of each neuron is set to n_act. /// The lerning algorithm is set to learn. /// </summary> /// <param name="inputs">Number of inputs of the network</param> /// <param name="layers_desc">Number of neurons for each layer of the network</param> /// <param name="activationFunc">Activation function for each neuron in the network</param> /// <param name="learnAlg">Learning algorithm to be used by the neural network</param> public Network(int inputs, int[] layers_desc, IActivationFunction activationFunc, LearningAlgorithm learnAlg) { if (layers_desc.Length < 1) { throw new Exception("PERCEPTRON : cannot build perceptron, it must have at least 1 layer of neurons"); } if (inputs < 1) { throw new Exception("PERCEPTRON : cannot build perceptron, it must have at least 1 input"); } learningAlg = learnAlg; numInputs = inputs; layers = new Layer[layers_desc.Length]; layers[0] = new Layer(layers_desc[0], numInputs); for (int i = 1; i < layers_desc.Length; i++) { layers[i] = new Layer(layers_desc[i], layers_desc[i - 1], activationFunc); } }
/// <summary> /// Create a new neural network /// with "inputs" inputs and size of "layers" /// layers of neurones. /// The layer i is made with layers_desc[i] neurones. /// The activation function of each neuron is set to default (Sigmoid with beta = 1). /// The lerning algorithm is set to default (Back Propagation). /// </summary> /// <param name="inputs">Number of inputs of the network</param> /// <param name="layers_desc">Number of neurons for each layer of the network</param> public Network(int inputs, int[] layers_desc) { if (layers_desc.Length < 1) { throw new Exception("PERCEPTRON : cannot build perceptron, it must have at least 1 layer of neurone"); } if (inputs < 1) { throw new Exception("PERCEPTRON : cannot build perceptron, it must have at least 1 input"); } learningAlg = new BackPropagationLearningAlgorithm(this); numInputs = inputs; IActivationFunction n_act = new SigmoidActivation(); layers = new Layer[layers_desc.Length]; layers[0] = new Layer(layers_desc[0], numInputs); for (int i = 1; i < layers_desc.Length; i++) { layers[i] = new Layer(layers_desc[i], layers_desc[i - 1], n_act); } }