Пример #1
0
 public MLP(IActivation activationFunction, params int[] numNeuronInLayers)
 {
     if (numNeuronInLayers == null || numNeuronInLayers.Length < 2)
         throw new ArgumentException("At Least 2 Layers should have neuron count.");
     //input layer
     var il = new InputLayer(numNeuronInLayers[0]);
     //hidden layer with bias
     var layers = numNeuronInLayers.Skip(1).Take(numNeuronInLayers.Length - 2).
         Select(numNeuronInLayer => new PerceptronLayer(numNeuronInLayer, activationFunction)).
         Cast<INodeLayer>().ToList();
     //output layer without bias
     layers.Add(new PerceptronLayer(numNeuronInLayers.Last(), activationFunction, false));
     Create(il, layers.ToArray());
 }
Пример #2
0
 public MLP(int numberOfInputs, params Tuple<int, IActivation>[] neuronCountActivationFunctionPack)
 {
     if (neuronCountActivationFunctionPack == null || neuronCountActivationFunctionPack.Length < 1)
         throw new ArgumentException("At Least 1 output Layer should be specified.");
     //input layer
     var il = new InputLayer(numberOfInputs);
     //hidden layer with bias
     var layers = neuronCountActivationFunctionPack.Take(neuronCountActivationFunctionPack.Length - 1).
         Select(tuple => new PerceptronLayer(tuple.Item1, tuple.Item2)).
         Cast<INodeLayer>().ToList();
     //output layer without bias
     var lastLayerTuple = neuronCountActivationFunctionPack.Last();
     layers.Add(new PerceptronLayer(lastLayerTuple.Item1, lastLayerTuple.Item2, false));
     Create(il, layers.ToArray());
 }
Пример #3
0
 public MLP(InputLayer inputLayer, INodeLayer[] layers)
 {
     Create(inputLayer, layers);
 }
Пример #4
0
        private void Create(InputLayer inputLayer, INodeLayer[] layers)
        {
            NodeLayers = new INodeLayer[layers.Length + 1];
            ConnectionLayers = new List<IConnectionLayer>();
            var nodes = new List<List<INode>>();
            NumberOfInputs = inputLayer.Input.Length;
            NumberOfOutputs = layers.Last().Output.Length;
            NodeLayers[0] = inputLayer;
            nodes.Add(inputLayer.Nodes);

            for (int i = 0; i < layers.Length; i++)
            {
                var ih = layers[i];
                NodeLayers[i+1] = ih;
                nodes.Add(ih.Nodes);
            }

            for (var i = 0; i < NodeLayers.Length - 1; i++)
            {
                var cl = new LinearWeightLayer(NodeLayers[i], NodeLayers[i + 1]);
                ConnectionLayers.Add(cl);
            }

            StagedNodes = nodes.Select(n => n.ToArray()).ToArray();
            Nodes = nodes.SelectMany(s => s).ToList();
        }