public static TryGetValueAsDouble ( |
||
xmlParent | ||
elemName | string | |
return | double? |
/// <summary> /// Read Radial Basis Function settings from config XML. /// </summary> public static void ReadRbfAuxArgMutationConfig(XmlElement xmlConfig, out double mutationSigmaCenter, out double mutationSigmaRadius) { // Get root activation element. XmlNodeList nodeList = xmlConfig.GetElementsByTagName( "RbfAuxArgMutationConfig", ""); if (nodeList.Count != 1) { throw new ArgumentException("Missing or invalid RbfAuxArgMutationConfig" + "XML config settings."); } XmlElement xmlRbfConfig = nodeList[0] as XmlElement; double? center = XmlUtils.TryGetValueAsDouble(xmlRbfConfig, "MutationSigmaCenter"); double?radius = XmlUtils.TryGetValueAsDouble(xmlRbfConfig, "MutationSigmaRadius"); if (null == center || null == radius) { throw new ArgumentException("Missing or invalid RbfAuxArgMutationConfig" + "XML config settings."); } mutationSigmaCenter = center.Value; mutationSigmaRadius = radius.Value; }
/// <summary> /// /// </summary> /// <param name="substrateXml"></param> /// <param name="substrateSettingsXml"></param> /// <param name="multispatial"></param> /// <returns></returns> public static ISubstrate ReadSubstrateFromXml(XmlElement substrateXml, XmlElement substrateSettingsXml) { var activationFunction = CreateActivationFunctionFromString(XmlUtils.GetValueAsString(substrateSettingsXml, "Function")); var weightThreshold = XmlUtils.TryGetValueAsDouble(substrateSettingsXml, "WeightThreshold") ?? 0.2; var maxWeight = XmlUtils.TryGetValueAsDouble(substrateSettingsXml, "MaxWeight") ?? 5.0; bool multispatial = XmlUtils.TryGetValueAsBool(substrateSettingsXml, "Multispatial") ?? false; bool leo = XmlUtils.TryGetValueAsBool(substrateSettingsXml, "Leo") ?? false; var layerlist = new List <SubstrateNodeSet>(); var nodes = new Dictionary <uint, SubstrateNode>(); uint nodeid = 1; foreach (XmlElement layer in substrateXml.GetElementsByTagName("Layer")) { SubstrateNodeSet.LayerType type; if (!Enum.TryParse(layer.GetAttribute("type"), out type)) { throw new Exception("Layer type must be defined as Input/Output/Hidden"); } var tmp = new SubstrateNodeSet(layer.ChildNodes.Count, type); foreach (XmlNode n in layer.ChildNodes) { if (n is XmlComment) { continue; } var node = (XmlElement)n; var tmpNode = new SubstrateNode(nodeid, Array.ConvertAll(node.InnerText.Split(','), double.Parse)); tmp.NodeList.Add(tmpNode); nodes.Add(nodeid, tmpNode); nodeid++; } layerlist.Add(tmp); } XmlNodeList mappings = substrateXml.GetElementsByTagName("Mapping"); XmlNodeList connections = substrateXml.GetElementsByTagName("Connection"); ISubstrate retval; if (connections.Count > 0) { var connectionList = new List <SubstrateConnection>(); foreach (XmlElement connection in connections) { var ids = Array.ConvertAll(connection.InnerText.Split(','), uint.Parse); connectionList.Add(new SubstrateConnection(nodes[ids[0]], nodes[ids[1]])); } retval = multispatial ? (ISubstrate) new MultiSpatialSubstrate(layerlist, activationFunction, 0, weightThreshold, maxWeight, connectionList) : new Substrate(layerlist, activationFunction, 0, weightThreshold, maxWeight, connectionList); } else if (mappings.Count > 0) { var mappingList = new List <NodeSetMapping>(); foreach (XmlElement mapping in mappings) { var ids = Array.ConvertAll(mapping.InnerText.Split(','), int.Parse); double maxDist; double?maxDistN = null; if (double.TryParse(mapping.GetAttribute("maxDist"), out maxDist)) { maxDistN = maxDist; } mappingList.Add(NodeSetMapping.Create(ids[0], ids[1], maxDistN)); } retval = multispatial ? (ISubstrate) new MultiSpatialSubstrate(layerlist, activationFunction, 0, weightThreshold, maxWeight, mappingList) : new Substrate(layerlist, activationFunction, 0, weightThreshold, maxWeight, mappingList); } else { throw new XmlException("Faulty substrate definition, at least one Mapping or Connection element must be defined."); } retval.Leo = leo; return(retval); }