/// <summary> /// Creates the instance and initialize it from given xml element. /// </summary> /// <param name="elem"> /// Xml data containing settings. /// Content of xml element is always validated against the xml schema. /// </param> public InterconnectionSettings(XElement elem) { //Validation ElemValidator validator = new ElemValidator(); Assembly assemblyRCNet = Assembly.GetExecutingAssembly(); validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.Preprocessing.PoolInterconnectionSettings.xsd"); validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd"); XElement settingsElem = validator.Validate(elem, "rootElem"); //Parsing //Density Density = double.Parse(settingsElem.Attribute("density").Value, CultureInfo.InvariantCulture); //Ratios double relShareEE = double.Parse(settingsElem.Attribute("relShareEE").Value, CultureInfo.InvariantCulture); double relShareEI = double.Parse(settingsElem.Attribute("relShareEI").Value, CultureInfo.InvariantCulture); double relShareIE = double.Parse(settingsElem.Attribute("relShareIE").Value, CultureInfo.InvariantCulture); double relShareII = double.Parse(settingsElem.Attribute("relShareII").Value, CultureInfo.InvariantCulture); double sum = relShareEE + relShareEI + relShareIE + relShareII; RatioEE = relShareEE / sum; RatioEI = relShareEI / sum; RatioIE = relShareIE / sum; RatioII = relShareII / sum; //Average distance AvgDistance = settingsElem.Attribute("avgDistance").Value == "NA" ? 0d : double.Parse(settingsElem.Attribute("avgDistance").Value, CultureInfo.InvariantCulture); //Allow self connections? AllowSelfConnection = bool.Parse(settingsElem.Attribute("allowSelfConnection").Value); //Will have each neuron the same number of connections? ConstantNumOfConnections = bool.Parse(settingsElem.Attribute("constantNumOfConnections").Value); //Synapse SynapseCfg = new InternalSynapseSettings(settingsElem.Descendants("synapse").First()); return; }
/// <summary> /// Creates the instance and initialize it from given xml element. /// </summary> /// <param name="elem">Xml data containing settings.</param> /// <param name="poolSettingsCollection">Collection of pool settings.</param> public PoolsInterconnection(XElement elem, List <PoolSettings> poolSettingsCollection) { TargetPoolName = elem.Attribute("targetPool").Value; TargetPoolID = -1; //Find target pool ID (index) for (int idx = 0; idx < poolSettingsCollection.Count; idx++) { if (poolSettingsCollection[idx].Name == TargetPoolName) { TargetPoolID = idx; break; } } if (TargetPoolID == -1) { throw new Exception($"Pool {TargetPoolName} was not found."); } TargetConnectionDensity = double.Parse(elem.Attribute("targetConnDensity").Value, CultureInfo.InvariantCulture); SourcePoolName = elem.Attribute("srcPool").Value; SourcePoolID = -1; //Find source pool ID (index) for (int idx = 0; idx < poolSettingsCollection.Count; idx++) { if (poolSettingsCollection[idx].Name == SourcePoolName) { SourcePoolID = idx; break; } } if (SourcePoolID == -1) { throw new Exception($"Pool {SourcePoolName} was not found."); } SourceConnectionDensity = double.Parse(elem.Attribute("srcConnDensity").Value, CultureInfo.InvariantCulture); if (SourcePoolID == TargetPoolID) { throw new Exception($"Two different pools have to be specified for interpool connection."); } //Ratios double relShareEE = double.Parse(elem.Attribute("relShareEE").Value, CultureInfo.InvariantCulture); double relShareEI = double.Parse(elem.Attribute("relShareEI").Value, CultureInfo.InvariantCulture); double relShareIE = double.Parse(elem.Attribute("relShareIE").Value, CultureInfo.InvariantCulture); double relShareII = double.Parse(elem.Attribute("relShareII").Value, CultureInfo.InvariantCulture); double sum = relShareEE + relShareEI + relShareIE + relShareII; RatioEE = relShareEE / sum; RatioEI = relShareEI / sum; RatioIE = relShareIE / sum; RatioII = relShareII / sum; //Constant number of neuron's connections ConstantNumOfConnections = bool.Parse(elem.Attribute("constantNumOfConnections").Value); //Synapse SynapseCfg = new InternalSynapseSettings(elem.Descendants("synapse").First()); return; }
/// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public InterconnectionSettings(InterconnectionSettings source) { Density = source.Density; RatioEE = source.RatioEE; RatioEI = source.RatioEI; RatioIE = source.RatioIE; RatioII = source.RatioII; AvgDistance = source.AvgDistance; AllowSelfConnection = source.AllowSelfConnection; ConstantNumOfConnections = source.ConstantNumOfConnections; SynapseCfg = source.SynapseCfg.DeepClone(); return; }
//Constructors /// <summary> /// Creates an uninitialized instance /// </summary> public InterconnectionSettings() { Density = 0; RatioEE = 0.3; RatioEI = 0.2; RatioIE = 0.4; RatioII = 0.1; AvgDistance = 0; AllowSelfConnection = true; ConstantNumOfConnections = false; SynapseCfg = null; return; }
//Constructors /// <summary> /// Copy constructor /// </summary> /// <param name="source">Source instance</param> public PoolsInterconnection(PoolsInterconnection source) { SourcePoolName = source.SourcePoolName; SourcePoolID = source.SourcePoolID; SourceConnectionDensity = source.SourceConnectionDensity; TargetPoolName = source.TargetPoolName; TargetPoolID = source.TargetPoolID; TargetConnectionDensity = source.TargetConnectionDensity; RatioEE = source.RatioEE; RatioEI = source.RatioEI; RatioIE = source.RatioIE; RatioII = source.RatioII; ConstantNumOfConnections = source.ConstantNumOfConnections; SynapseCfg = source.SynapseCfg.DeepClone(); return; }