/// <summary> /// Create a network activation scheme from the scheme setting in the provided config XML. /// </summary> /// <returns></returns> public static NetworkActivationScheme CreateActivationScheme(XmlElement xmlConfig, string activationElemName) { // Get root activation element. XmlNodeList nodeList = xmlConfig.GetElementsByTagName(activationElemName, ""); if (nodeList.Count != 1) { throw new ArgumentException("Missing or invalid activation XML config setting."); } XmlElement xmlActivation = nodeList[0] as XmlElement; string schemeStr = XmlUtils.TryGetValueAsString(xmlActivation, "Scheme"); switch (schemeStr) { case "Acyclic": return(NetworkActivationScheme.CreateAcyclicScheme()); case "CyclicFixedIters": int iters = XmlUtils.GetValueAsInt(xmlActivation, "Iters"); return(NetworkActivationScheme.CreateCyclicFixedTimestepsScheme(iters)); case "CyclicRelax": double deltaThreshold = XmlUtils.GetValueAsInt(xmlActivation, "Threshold"); int maxIters = XmlUtils.GetValueAsInt(xmlActivation, "MaxIters"); return(NetworkActivationScheme.CreateCyclicRelaxingActivationScheme(deltaThreshold, maxIters)); } throw new ArgumentException(string.Format("Invalid or missing ActivationScheme XML config setting [{0}]", schemeStr)); }
/// <summary> /// This is inspired by ExperimentUtils.CreateActivationScheme, but can't be put there, because NeatConfigInfo_Activation isn't /// defined that low /// </summary> private static NetworkActivationScheme GetActivationScheme(ExperimentInitArgs_Activation scheme) { if (scheme == null) { throw new ArgumentNullException("scheme"); } else if (scheme is ExperimentInitArgs_Activation_Acyclic) { return(NetworkActivationScheme.CreateAcyclicScheme()); } else if (scheme is ExperimentInitArgs_Activation_CyclicFixedTimesteps) { ExperimentInitArgs_Activation_CyclicFixedTimesteps cast = (ExperimentInitArgs_Activation_CyclicFixedTimesteps)scheme; return(NetworkActivationScheme.CreateCyclicFixedTimestepsScheme(cast.TimestepsPerActivation, cast.FastFlag)); } else if (scheme is ExperimentInitArgs_Activation_CyclicRelaxing) { ExperimentInitArgs_Activation_CyclicRelaxing cast = (ExperimentInitArgs_Activation_CyclicRelaxing)scheme; return(NetworkActivationScheme.CreateCyclicRelaxingActivationScheme(cast.SignalDeltaThreshold, cast.MaxTimesteps, cast.FastFlag)); } else { throw new ArgumentException("Unknown scheme type: " + scheme.GetType().ToString()); } }
/// <summary> /// Creates a cyclic or acyclic activation scheme for the network. /// </summary> private NetworkActivationScheme CreateActivationScheme(string activationScheme, int?activationIters, double?activationDeltaThreshold) { switch (activationScheme) { case "Acyclic": return(NetworkActivationScheme.CreateAcyclicScheme()); case "CyclicFixedIters": if (activationIters == null) { throw new ArgumentException( "Maximum iterations must be specified for cyclic activation scheme"); } var iters = activationIters.Value; return(NetworkActivationScheme.CreateCyclicFixedTimestepsScheme(iters)); case "CyclicRelax": if (activationIters == null) { throw new ArgumentException( "Maximum iterations must be specified for cyclic relaxation scheme"); } if (activationDeltaThreshold == null) { throw new ArgumentException("Delta threshold must be specified for cyclic relaxation scheme"); } var deltaThreshold = activationDeltaThreshold.Value; var maxIters = activationIters.Value; return(NetworkActivationScheme.CreateCyclicRelaxingActivationScheme(deltaThreshold, maxIters)); } throw new ArgumentException($"Invalid ActivationScheme setting [{activationScheme}]"); }