/// <summary> /// Adds a new connection. /// </summary> /// <param name="connection">The connection.</param> public void AddConnection(NeuronalNetworkConnection connection) { this.Connections.Add(connection); }
/// <inheritdoc cref="IArchiveSerialization"/> /// <summary> /// Serializes the archive. /// </summary> /// <param name="archive">The archive.</param> /// <seealso cref="IArchiveSerialization"/> public void Serialize(Archive archive) { if (archive.IsStoring()) { archive.Write(this.label); archive.Write(this.Neurons.Count); archive.Write(this.Weights.Count); foreach (var neuron in this.Neurons) { archive.Write(neuron.Label); archive.Write(neuron.Connections.Count); foreach (var cit in neuron.Connections) { archive.Write(cit.NeuronIndex); archive.Write(cit.WeightIndex); } } foreach (var wit in this.Weights) { archive.Write(wit.Label); archive.Write(wit.Value); } } else { // Read the label archive.Read(out string localLabel); this.label = localLabel; // Read numbers of neurons and weights archive.Read(out int numberOfNeurons); archive.Read(out int numberOfWeights); if (numberOfNeurons == 0) { return; } // Clear neuron list and weight list. this.Neurons.Clear(); this.Neurons = new NeuronalNetworkNeuronList(numberOfNeurons); this.Weights.Clear(); this.Weights = new NeuronalNetworkWeightList(numberOfWeights); int ii; int jj; for (ii = 0; ii < numberOfNeurons; ii++) { // Read the neuron's label archive.Read(out localLabel); // Read the neuron's connection number archive.Read(out int numberOfConnections); var neuron = new NeuronalNetworkNeuron(localLabel, numberOfConnections) { Label = localLabel }; this.Neurons.Add(neuron); for (jj = 0; jj < numberOfConnections; jj++) { var connection = new NeuronalNetworkConnection(); archive.Read(out uint neuronIndex); archive.Read(out uint weightIndex); connection.NeuronIndex = neuronIndex; connection.WeightIndex = weightIndex; neuron.AddConnection(connection); } } for (jj = 0; jj < numberOfWeights; jj++) { archive.Read(out localLabel); archive.Read(out double value); var weight = new NeuronalNetworkWeight(localLabel, value); this.Weights.Add(weight); } } }
/// <summary> /// Adds a new connection. /// </summary> /// <param name="neuronIndex">The neuron index.</param> /// <param name="weightIndex">The weight index.</param> public void AddConnection(uint neuronIndex, uint weightIndex) { var conn = new NeuronalNetworkConnection(neuronIndex, weightIndex); this.Connections.Add(conn); }