/// <summary> /// Returns the decorated (activation) neuron. /// </summary> /// <param name="parentLayer">The parent layer.</param> /// <returns> /// The decorated (activation) neuron. /// </returns> public virtual IActivationNeuron GetDecoratedActivationNeuron(IActivationLayer parentLayer) { // Reintegrate. ParentLayer = parentLayer; return(decoratedActivationNeuron); }
/// <summary> /// Creates a new hidden neuron. /// </summary> /// <param name="parentLayer">The parnet layer.</param> public ActivationNeuron(IActivationLayer parentLayer) { sourceSynapses = new List <ISynapse>(); targetSynapses = new List <ISynapse>(); // Validate the parent layer. Utilities.ObjectNotNull(parentLayer, "parentLayer"); this.parentLayer = parentLayer; }
/// <summary> /// /// </summary> /// <param name="connector">The connector to be disconnected.</param> public void Disconnect(IConnector connector) { // 1. Make the connector's source layer not aware of it ... sourceLayer.TargetConnectors.Remove(connector); // ... and vice versa. sourceLayer = null; // 2. Make the connector's target layer not aware of it ... targetLayer.SourceConnectors.Remove(connector); // ... and vice versa. targetLayer = null; // 3. Disconnect the synapses. foreach (ISynapse synapse in synapses) { synapse.Disconnect(); } }
/// <summary> /// /// </summary> /// <param name="connector">The connector being connected.</param> public void Connect(IConnector connector) { // 1. Make the connector aware of its source layer ... sourceLayer = parentNetwork.GetLayerByIndex(blueprint.SourceLayerIndex); // ... and vice versa. sourceLayer.TargetConnectors.Add(connector); // 2. Make the connector aware of its target layer ... targetLayer = (IActivationLayer)parentNetwork.GetLayerByIndex(blueprint.TargetLayerIndex); // ... and vice versa. targetLayer.SourceConnectors.Add(connector); // 3. Connect the synapses. foreach (ISynapse synapse in synapses) { synapse.Connect(); } }
/// <summary> /// /// </summary> /// <param name="layer">The (activation) layer to be decorated as backpropagation (activation) layer.</param> /// <param name="parnetNetwork">The parnet network.</param> public BackpropagationLayer(IActivationLayer activationLayer, INetwork parnetNetwork) : base(activationLayer,parnetNetwork) { // Ensure the activation function of the neuron is derivable. if (!(ActivationFunction is IDerivableActivationFunction)) { // TODO: Throw an exception informing the client that in order for the neuron to undergo training // using the error backpropagation algorithm, its activation function has to be derivable // (i.e. it has to implement the IDerivableActivationFunction interface) throw new Exception(); } // Decorate the neurons. for (int i = 0; i < NeuronCount; i++) { Neurons[ i ] = new BackpropagationNeuron(Neurons[i],this); } }
/// <summary> /// Creates a new (artificial neural) network (from its blueprint). /// </summary> /// /// <param name="blueprint">The blueprint of the network.</param> public Network(NetworkBlueprint blueprint) { // 0. Validate the blueprint. Utilities.ObjectNotNull(blueprint, "blueprint"); this.blueprint = blueprint; // 1. Create the network components. // 1.1. Create the layers. // 1.1.1. Create the bias layer. biasLayer = new InputLayer(this.blueprint.BiasLayerBlueprint, this); biasLayer.SetInputVector(new double[] { 1.0 }); // 1.1.2. Create the input layer. inputLayer = new InputLayer(this.blueprint.InputLayerBlueprint, this); // 1.1.3. Create the hidden layers. hiddenLayers = new List <IActivationLayer>(this.blueprint.HiddenLayerCount); foreach (ActivationLayerBlueprint hiddenLayerBlueprint in this.blueprint.HiddenLayerBlueprints) { IActivationLayer hiddenLayer = new ActivationLayer(hiddenLayerBlueprint, this); hiddenLayers.Add(hiddenLayer); } // 1.1.4. Create the output layer. outputLayer = new ActivationLayer(this.blueprint.OutputLayerBlueprint, this); // 1.2 Create the connectors. connectors = new List <IConnector>(this.blueprint.ConnectorCount); foreach (ConnectorBlueprint connectorBlueprint in this.blueprint.ConnectorBlueprints) { IConnector connector = new Connector(connectorBlueprint, this); connectors.Add(connector); } // 2. Connect the network. Connect(); }
/// <summary> /// /// </summary> /// <param name="decoratedActivationNeuron">The (activation) layer to be decorated.</param> /// <param name="parentLayer">The parent layer.</param> public ActivationNeuronDecorator(IActivationNeuron decoratedActivationNeuron, IActivationLayer parentLayer) { this.decoratedActivationNeuron = decoratedActivationNeuron; ParentLayer = parentLayer; }
/// <summary> /// /// </summary> /// <param name="decoratedActivationLayer">The (activation) layer to be decorated.</param> /// <param name="parentNetwork">The parent network.</param> public ActivationLayerDecorator(IActivationLayer activationLayer, INetwork parentNetwork) { this.decoratedActivationLayer = activationLayer; ParentNetwork = parentNetwork; }
/// <summary> /// /// </summary> /// <param name="neuron">The (activation) neuron to be decorated as backpropagation (activation) neuron.</param> /// <param name="parentLayer">The parent layer.</param> public BackpropagationNeuron(IActivationNeuron activationNeuron, IActivationLayer parentLayer) : base(activationNeuron, parentLayer) { }