/// <summary> /// Compare this neural network with another. /// To be equal it must have the same structure and matrix values. /// </summary> /// <param name="other">The other neural network.</param> /// <returns>True if the neural networks are equal.</returns> public bool Equals(FeedforwardNetwork other) { int i = 0; foreach (FeedforwardLayer layer in _layers) { FeedforwardLayer otherLayer = other.Layers[i++]; if (layer.NeuronCount != otherLayer.NeuronCount) { return(false); } if ((layer.LayerMatrix == null) && (otherLayer.LayerMatrix != null)) { return(false); } if ((layer.LayerMatrix != null) && (otherLayer.LayerMatrix == null)) { return(false); } if ((layer.LayerMatrix != null) && (otherLayer.LayerMatrix != null)) { if (!layer.LayerMatrix.Equals(otherLayer.LayerMatrix)) { return(false); } } } return(true); }
/// <summary> /// Returns a clone of this neural network. Including weight, threshold and structure. /// </summary> /// <returns>A cloned copy of this neural network.</returns> public object Clone() { FeedforwardNetwork result = CloneStructure(); double[] copy = MatrixCODEC.NetworkToArray(this); MatrixCODEC.ArrayToNetwork(copy, result); return(result); }
/// <summary> /// Clone the structure of this neural network. /// </summary> /// <returns>A cloned copy of the structure of the neural network.</returns> public FeedforwardNetwork CloneStructure() { FeedforwardNetwork result = new FeedforwardNetwork(); foreach (FeedforwardLayer layer in _layers) { FeedforwardLayer cloned = new FeedforwardLayer(layer.NeuronCount); result.AddLayer(cloned); } return(result); }