/// <inheritdoc /> public virtual object DeepCopy() { Network copy = new Network(Name); copy.Architecture = (INetworkArchitecture)Architecture.DeepCopy(); if (_initialised) { copy.Initialise(_associatedHandler); for (int i = 0; i < _orderedLayerBuffers.Count; i++) { InternalLayerBuffer originalBuffer = _orderedLayerBuffers[i]; InternalLayerBuffer copyBuffer = copy._orderedLayerBuffers[i]; foreach (string parameterIdentifier in originalBuffer.Parameters.Keys.ToArray()) { object value = originalBuffer.Parameters[parameterIdentifier]; IDeepCopyable deepCopyableValue = value as IDeepCopyable; object copiedValue; // copy and copy efficiently by any means possible if (deepCopyableValue == null) { ICloneable cloneableValue = value as ICloneable; copiedValue = cloneableValue?.Clone() ?? value; } else { INDArray asNDArray = value as INDArray; if (asNDArray != null) { _associatedHandler.Fill(asNDArray, copyBuffer.Parameters.Get <INDArray>(parameterIdentifier)); copiedValue = copyBuffer.Parameters.Get <INDArray>(parameterIdentifier); } else { copiedValue = deepCopyableValue.DeepCopy(); } } copyBuffer.Parameters[parameterIdentifier] = copiedValue; } } } copy.UpdateRegistry(); return(copy); }