/// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public FeedForwardNetworkSettings(FeedForwardNetworkSettings source) { OutputActivationCfg = ActivationFactory.DeepCloneActivationSettings(source.OutputActivationCfg); OutputRange = source.OutputRange.DeepClone(); HiddenLayersCfg = (HiddenLayersSettings)source.HiddenLayersCfg.DeepClone(); TrainerCfg = source.TrainerCfg.DeepClone(); return; }
//Methods /// <summary> /// Checks consistency /// </summary> protected override void Check() { if (NumOfNeurons < 1) { throw new ArgumentException($"Invalid NumOfNeurons {NumOfNeurons.ToString(CultureInfo.InvariantCulture)}. NumOfNeurons must be GT 0.", "NumOfNeurons"); } if (!FeedForwardNetworkSettings.IsAllowedActivation(ActivationCfg, out _)) { throw new ArgumentException($"Specified ActivationCfg can't be used in the hidden layer of a FF network. Activation function has to be stateless and has to support derivative calculation.", "ActivationCfg"); } return; }
/// <summary> /// Creates an initialized instance. /// </summary> /// <param name="numOfInputValues">The number of the network's input values.</param> /// <param name="numOfOutputValues">The number of the network's output values.</param> /// <param name="cfg">The configuration of the network and associated trainer.</param> public FeedForwardNetwork(int numOfInputValues, int numOfOutputValues, FeedForwardNetworkSettings cfg) : this(numOfInputValues, numOfOutputValues) { Random rand = new Random(1); //Initialize FF network for (int i = 0; i < cfg.HiddenLayersCfg.HiddenLayerCfgCollection.Count; i++) { AddLayer(cfg.HiddenLayersCfg.HiddenLayerCfgCollection[i].NumOfNeurons, (AFAnalogBase)ActivationFactory.CreateAF(cfg.HiddenLayersCfg.HiddenLayerCfgCollection[i].ActivationCfg, rand) ); } FinalizeStructure((AFAnalogBase)ActivationFactory.CreateAF(cfg.OutputActivationCfg, rand)); return; }
/// <summary> /// The deep copy constructor. /// </summary> /// <param name="source">The source instance.</param> public FeedForwardNetworkSettings(FeedForwardNetworkSettings source) : this(source.OutputActivationCfg, source.HiddenLayersCfg, source.TrainerCfg) { return; }