Esempio n. 1
0
 /// <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);
     }
     ReadoutNeuronsDensity = source.ReadoutNeuronsDensity;
     NeuronGroups          = new List <NeuronGroupSettings>(source.NeuronGroups.Count);
     foreach (NeuronGroupSettings item in source.NeuronGroups)
     {
         NeuronGroups.Add(item.DeepClone());
     }
     InterconnectionCfg       = source.InterconnectionCfg.DeepClone();
     RetainmentNeuronsFeature = source.RetainmentNeuronsFeature;
     RetainmentNeuronsDensity = source.RetainmentNeuronsDensity;
     if (RetainmentNeuronsFeature)
     {
         RetainmentRate = source.RetainmentRate.DeepClone();
     }
     else
     {
         RetainmentRate = null;
     }
     return;
 }
Esempio n. 2
0
        //Static methods
        //Methods
        /// <summary>
        /// See the base.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            PoolDimensions cmpSettings = obj as PoolDimensions;

            if (!Coordinates.ContainsEqualValues(cmpSettings.Coordinates) ||
                !Dimensions.ContainsEqualValues(cmpSettings.Dimensions)
                )
            {
                return(false);
            }
            return(true);
        }
Esempio n. 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;
 }
Esempio n. 4
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;
        }