public Neuron(int index, Layer initLayer, Neuron.ActivationType actType = ActivationType.SIGMOID, double bias = 0) { Index = index; Connections = new List <Connection>(); SelfLayer = initLayer; ActType = actType; Bias = bias; }
public Layer(int neuronCount, Neuron.ActivationType neuronType, LearningType learnMethod) { Neurons = new Neuron[neuronCount]; NeuronType = neuronType; LearningMethod = learnMethod; InitializeNeurons(); }
public NeuronLayer(int neuronCount, int inputs, Neuron.ActivationType activationType) { neurons = new Neuron[neuronCount]; for (int i = 0; i < neuronCount; i++) { neurons [i] = new Neuron(inputs, activationType); } output = new double[neuronCount]; }
public Layer(int index, int numNeurons, Neuron.ActivationType actTye = Neuron.ActivationType.SIGMOID, IEnumerable <double> initBias = null) { Index = index; NumNeurons = numNeurons; ActType = actTye; Neurons = new Neuron[NumNeurons]; if (initBias != null) { for (int i = 0; i < NumNeurons; i++) { Neurons[i] = new Neuron(i, this, ActType, initBias.ElementAt(i)); } } else { for (int i = 0; i < NumNeurons; i++) { Neurons[i] = new Neuron(i, this, ActType); } } }
private Neuron.ActivationType _activationType; // ActivationType public NeuralNetwork(Genome genome, Neuron.ActivationType activationType = Neuron.ActivationType.SIGMOID, bool bias = true, int timeOut = 1000) { _activationType = activationType; _bias = bias; _timeOut = timeOut; _inputIds = new List <int>(); _outputIds = new List <int>(); _neurons = new Dictionary <int, Neuron>(); _unprocessedNeurons = new List <Neuron>(); Genome = genome; Fitness = 0f; // Fill Neurons, Input & Outputs Ids w/ Nodes in Genome foreach (int nodeId in genome.Nodes.Keys) { NodeGene node = genome.Nodes[nodeId]; Neuron neuron = null; // Input & Output Node if (node.Type == NodeGene.TYPE.INPUT) { neuron = new Neuron(Neuron.NeuronType.INPUT, _activationType, false); // No bias on Input Node neuron.AddInputConnection(); _inputIds.Add(nodeId); } else if (node.Type == NodeGene.TYPE.OUTPUT) { neuron = new Neuron(Neuron.NeuronType.OUTPUT, _activationType, _bias); _outputIds.Add(nodeId); } else { neuron = new Neuron(Neuron.NeuronType.HIDDEN, _activationType, _bias); } // Add Neuron to the Network _neurons.Add(nodeId, neuron); } _inputIds.Sort(); _outputIds.Sort(); // Add Genome Connections to Neurons foreach (int connectionId in genome.Connections.Keys) { ConnectionGene connection = genome.Connections[connectionId]; // Ignore Disabled Nodes if (!connection.IsEnable) { continue; } // Add Output Connection to the Neuron of the emitting Node Neuron emittingNeuron = _neurons[connection.InNode]; emittingNeuron.AddOutputConnection(connection.OutNode, connection.Weight); // Add Input Connection to the Neuron of the receiving Node Neuron receivingNeuron = _neurons[connection.OutNode]; receivingNeuron.AddInputConnection(); } }
public ArtificialNeuralNetwork(int inputCount, int outputCount, int hiddenLayers, int neuronsPerLayer, double alpha, Neuron.ActivationType firstLayerActivation, Neuron.ActivationType hiddenLayerActivation, Neuron.ActivationType outputLayerActivation) { m_inputCount = inputCount; m_alpha = alpha; if (hiddenLayers < 0) { hiddenLayers = 0; } layers = new NeuronLayer[hiddenLayers + 1]; if (hiddenLayers > 0) { layers [0] = new NeuronLayer(neuronsPerLayer, inputCount, firstLayerActivation); for (int i = 1; i < hiddenLayers; i++) { layers [i] = new NeuronLayer(neuronsPerLayer, neuronsPerLayer, hiddenLayerActivation); } layers [hiddenLayers] = new NeuronLayer(outputCount, neuronsPerLayer, outputLayerActivation); } else { layers [0] = new NeuronLayer(outputCount, inputCount, outputLayerActivation); } }
/// <summary> /// Starts the neural network with full controls of its setup. /// </summary> /// <param name="inputAmmount">Input ammount.</param> /// <param name="outputAmmount">Output ammount.</param> /// <param name="hiddenLayers">Hidden layers.</param> /// <param name="neuronsPerLayer">Neurons per layer.</param> /// <param name="alpha">Alpha.</param> /// <param name="inputActivationMethod">Input activation method.</param> /// <param name="hiddenLayerActivationMethod">Hidden layer activation method.</param> /// <param name="outputActivationMethod">Output activation method.</param> public void StartNeuralNetwork(int inputAmmount, int outputAmmount, int hiddenLayerAmmount, int neuronsInHiddenLayer, double errorAlpha, Neuron.ActivationType inputActivationMethod, Neuron.ActivationType hiddenActivationMethod, Neuron.ActivationType outputActivationMethod) { if (neuralNetwork != null) { return; } neuralNetwork = new ArtificialNeuralNetwork(inputAmmount, outputAmmount, hiddenLayerAmmount, neuronsInHiddenLayer, errorAlpha, inputActivationMethod, hiddenActivationMethod, outputActivationMethod); }