コード例 #1
0
 /// <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               = null;
     if (source.SynapseCfg != null)
     {
         if (source.SynapseCfg.GetType() == typeof(StaticSynapseSettings))
         {
             //Static synapse settings
             SynapseCfg = ((StaticSynapseSettings)source.SynapseCfg).DeepClone();
         }
         else
         {
             //Dynamic synapse settings
             SynapseCfg = ((DynamicSynapseSettings)source.SynapseCfg).DeepClone();
         }
     }
     return;
 }
コード例 #2
0
 /// <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;
 }
コード例 #3
0
 //Constructors
 /// <summary>
 /// The deep copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public PoolSettings(PoolSettings source)
 {
     Name = source.Name;
     Dim  = null;
     if (source.Dim != null)
     {
         Dim = new PoolDimensions(source.Dim.X, source.Dim.Y, source.Dim.Z, source.Dim.DimX, source.Dim.DimY, source.Dim.DimZ);
     }
     NeuronGroups = new List <NeuronGroupSettings>(source.NeuronGroups.Count);
     foreach (NeuronGroupSettings item in source.NeuronGroups)
     {
         NeuronGroups.Add(item.DeepClone());
     }
     PredictorsCfg      = source.PredictorsCfg?.DeepClone();
     InterconnectionCfg = source.InterconnectionCfg.DeepClone();
     return;
 }
コード例 #4
0
            //Methods
            /// <summary>
            /// See the base.
            /// </summary>
            public override bool Equals(object obj)
            {
                if (obj == null)
                {
                    return(false);
                }
                InterconnectionSettings cmpSettings = obj as InterconnectionSettings;

                if (Density != cmpSettings.Density ||
                    RatioEE != cmpSettings.RatioEE ||
                    RatioEI != cmpSettings.RatioEI ||
                    RatioIE != cmpSettings.RatioIE ||
                    RatioII != cmpSettings.RatioII ||
                    AvgDistance != cmpSettings.AvgDistance ||
                    AllowSelfConnection != cmpSettings.AllowSelfConnection ||
                    ConstantNumOfConnections != cmpSettings.ConstantNumOfConnections ||
                    !Equals(SynapseCfg, cmpSettings.SynapseCfg)
                    )
                {
                    return(false);
                }
                return(true);
            }
コード例 #5
0
        /// <summary>
        /// Creates the instance and initialize it from given xml element.
        /// </summary>
        /// <param name="elem">
        /// Xml data containing pool settings.
        /// Content of xml element is always validated against the xml schema.
        /// </param>
        public PoolSettings(XElement elem)
        {
            //Validation
            ElemValidator validator     = new ElemValidator();
            Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

            validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.Preprocessing.PoolSettings.xsd");
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
            XElement poolSettingsElem = validator.Validate(elem, "rootElem");

            //Parsing
            //Name
            Name = poolSettingsElem.Attribute("name").Value;
            //Dimensions
            Dim = new PoolDimensions(int.Parse(poolSettingsElem.Attribute("x").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("y").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("z").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("dimX").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("dimY").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("dimZ").Value, CultureInfo.InvariantCulture)
                                     );
            //NeuronGroups
            XElement neuronGroupsElem = poolSettingsElem.Descendants("neuronGroups").First();
            double   totalRelShare    = 0;

            NeuronGroups = new List <NeuronGroupSettings>();
            //Analog neuron groups
            foreach (XElement neuronGroupElem in neuronGroupsElem.Descendants("analogGroup"))
            {
                NeuronGroupSettings ngs = new NeuronGroupSettings(neuronGroupElem, ActivationType.Analog);
                if (ngs.RelativeShare > 0)
                {
                    NeuronGroups.Add(ngs);
                    totalRelShare += ngs.RelativeShare;
                }
            }
            //Spiking neuron groups
            foreach (XElement neuronGroupElem in neuronGroupsElem.Descendants("spikingGroup"))
            {
                NeuronGroupSettings ngs = new NeuronGroupSettings(neuronGroupElem, ActivationType.Spiking);
                if (ngs.RelativeShare > 0)
                {
                    NeuronGroups.Add(ngs);
                    totalRelShare += ngs.RelativeShare;
                }
            }
            //Neuron groups counts
            int totalCount = 0;

            foreach (NeuronGroupSettings ngs in NeuronGroups)
            {
                double ratio = ngs.RelativeShare / totalRelShare;
                ngs.Count   = (int)Math.Round(((double)Dim.Size) * ratio, 0);
                totalCount += ngs.Count;
            }
            while (totalCount != Dim.Size)
            {
                //Correction of neuron counts
                int sign = Math.Sign(Dim.Size - totalCount);
                if (sign < 0)
                {
                    NeuronGroups.Sort(NeuronGroupSettings.Comparer_desc);
                }
                else
                {
                    NeuronGroups.Sort(NeuronGroupSettings.Comparer_asc);
                }
                NeuronGroups[0].Count += sign;
                totalCount            += sign;
                if (NeuronGroups[0].Count < 0)
                {
                    throw new Exception("Can't set proper neuron counts for the neuron groups.");
                }
            }

            //Predictors
            XElement predictorsElem = poolSettingsElem.Descendants("predictors").FirstOrDefault();

            if (predictorsElem != null)
            {
                PredictorsCfg = new HiddenNeuronPredictorsSettings(predictorsElem);
            }

            //Interconnection
            XElement interconnectionElem = poolSettingsElem.Descendants("interconnection").First();

            InterconnectionCfg = new InterconnectionSettings(interconnectionElem);
            return;
        }
コード例 #6
0
            /// <summary>
            /// Creates the deep copy instance of this instance
            /// </summary>
            public InterconnectionSettings DeepClone()
            {
                InterconnectionSettings clone = new InterconnectionSettings(this);

                return(clone);
            }
コード例 #7
0
        /// <summary>
        /// Creates the instance and initialize it from given xml element.
        /// This is the preferred way to instantiate pool settings.
        /// </summary>
        /// <param name="elem">
        /// Xml data containing pool settings.
        /// Content of xml element is always validated against the xml schema.
        /// </param>
        public PoolSettings(XElement elem)
        {
            //Validation
            ElemValidator validator     = new ElemValidator();
            Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

            validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.ReservoirStructure.PoolSettings.xsd");
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
            XElement poolSettingsElem = validator.Validate(elem, "rootElem");

            //Parsing
            //Name
            Name = poolSettingsElem.Attribute("name").Value;
            //Dimensions
            Dim = new PoolDimensions(int.Parse(poolSettingsElem.Attribute("x").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("y").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("z").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("dimX").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("dimY").Value, CultureInfo.InvariantCulture),
                                     int.Parse(poolSettingsElem.Attribute("dimZ").Value, CultureInfo.InvariantCulture)
                                     );
            //Readout neurons density
            ReadoutNeuronsDensity = double.Parse(poolSettingsElem.Attribute("readoutNeuronsDensity").Value, CultureInfo.InvariantCulture);
            //NeuronGroups
            XElement neuronGroupsElem = poolSettingsElem.Descendants("neuronGroups").First();
            double   totalRelShare    = 0;

            NeuronGroups = new List <NeuronGroupSettings>();
            foreach (XElement neuronGroupElem in neuronGroupsElem.Descendants("neuronGroup"))
            {
                NeuronGroupSettings ngs = new NeuronGroupSettings(neuronGroupElem);
                if (ngs.RelativeShare > 0)
                {
                    NeuronGroups.Add(ngs);
                    totalRelShare += ngs.RelativeShare;
                }
            }
            //Neuron groups counts
            int totalCount = 0;

            foreach (NeuronGroupSettings ngs in NeuronGroups)
            {
                double ratio = ngs.RelativeShare / totalRelShare;
                ngs.Count   = (int)Math.Round(((double)Dim.Size) * ratio, 0);
                totalCount += ngs.Count;
            }
            while (totalCount != Dim.Size)
            {
                //Correction of neuron counts
                int sign = Math.Sign(Dim.Size - totalCount);
                if (sign < 0)
                {
                    NeuronGroups.Sort(NeuronGroupSettings.Comparer_desc);
                }
                else
                {
                    NeuronGroups.Sort(NeuronGroupSettings.Comparer_asc);
                }
                NeuronGroups[0].Count += sign;
                totalCount            += sign;
                if (NeuronGroups[0].Count < 0)
                {
                    throw new Exception("Can't set proper neuron absolute counts for the neuron groups.");
                }
            }

            //Interconnection
            XElement interconnectionElem = poolSettingsElem.Descendants("interconnection").First();

            InterconnectionCfg = new InterconnectionSettings(interconnectionElem);
            //Retainment neurons
            XElement retainmentElem = poolSettingsElem.Descendants("retainmentNeurons").FirstOrDefault();

            RetainmentNeuronsFeature = (retainmentElem != null);
            if (RetainmentNeuronsFeature)
            {
                RetainmentNeuronsDensity = double.Parse(retainmentElem.Attribute("density").Value, CultureInfo.InvariantCulture);
                RetainmentRate           = new RandomValueSettings(retainmentElem.Descendants("rate").First());
                RetainmentNeuronsFeature = (RetainmentNeuronsDensity > 0 &&
                                            RetainmentRate.Max > 0
                                            );
            }
            else
            {
                RetainmentNeuronsDensity = 0;
            }
            return;
        }