Esempio n. 1
0
 //Methods
 /// <inheritdoc/>
 protected override void Check()
 {
     if (Regime != InputEncoder.InputSpikesCoding.Forbidden)
     {
         if (CoderCfgCollection.Count == 0)
         {
             throw new ArgumentException($"It must be specified at least one coder configuration.", "CoderCfgCollection");
         }
         foreach (RCNetBaseSettings coderCfg in CoderCfgCollection)
         {
             if (!A2SCoderFactory.CheckSettings(coderCfg))
             {
                 throw new ArgumentException($"Unknown coder configuration {coderCfg.GetType().Name}.", "CoderCfgCollection");
             }
         }
     }
     return;
 }
Esempio n. 2
0
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="elem">A xml element containing the configuration data.</param>
 public InputSpikesCoderSettings(XElement elem)
 {
     //Validation
     XElement settingsElem = Validate(elem, XsdTypeName);
     //Parsing
     //Regime
     Regime = (InputEncoder.InputSpikesCoding)Enum.Parse(typeof(InputEncoder.InputSpikesCoding), settingsElem.Attribute("regime").Value, true);
     //Coders configurations
     CoderCfgCollection = null;
     if (Regime != InputEncoder.InputSpikesCoding.Forbidden)
     {
         CoderCfgCollection = new List<RCNetBaseSettings>();
         foreach (XElement coderCfgElem in settingsElem.Elements())
         {
             if (A2SCoderFactory.CheckSettingsElemName(coderCfgElem))
             {
                 CoderCfgCollection.Add(A2SCoderFactory.LoadSettings(coderCfgElem));
             }
         }
     }
     Check();
     return;
 }
Esempio n. 3
0
        //Constructor
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="cfg">The configuration of the coder.</param>
        public InputSpikesCoder(InputSpikesCoderSettings cfg)
        {
            _encodingCfg           = (InputSpikesCoderSettings)cfg.DeepClone();
            _coderCollection       = new List <A2SCoderBase>(_encodingCfg.CoderCfgCollection.Count);
            _numOfComponents       = 0;
            LargestComponentLength = 0;
            foreach (RCNetBaseSettings coderCfg in _encodingCfg.CoderCfgCollection)
            {
                A2SCoderBase coder = A2SCoderFactory.Create(coderCfg);
                _coderCollection.Add(coder);
                _numOfComponents      += coder.NumOfComponents;
                LargestComponentLength = Math.Max(LargestComponentLength, coder.BaseCodeLength);
            }
            ComponentSpikesCollection = new byte[_numOfComponents][];
            switch (_encodingCfg.Regime)
            {
            case InputEncoder.InputSpikesCoding.Forbidden:
            {
                AllSpikesFlatCollection = new byte[0];
            }
            break;

            case InputEncoder.InputSpikesCoding.Horizontal:
            {
                int idx             = 0;
                int allSpikesLength = 0;
                foreach (A2SCoderBase coder in _coderCollection)
                {
                    for (int i = 0; i < coder.NumOfComponents; i++)
                    {
                        ComponentSpikesCollection[idx] = new byte[coder.BaseCodeLength];
                        ComponentSpikesCollection[idx].Populate((byte)0);
                        allSpikesLength += coder.BaseCodeLength;
                        ++idx;
                    }
                }
                AllSpikesFlatCollection = new byte[allSpikesLength];
                AllSpikesFlatCollection.Populate((byte)0);
            }
            break;

            case InputEncoder.InputSpikesCoding.Vertical:
            {
                int idx             = 0;
                int allSpikesLength = 0;
                foreach (A2SCoderBase coder in _coderCollection)
                {
                    for (int i = 0; i < coder.NumOfComponents; i++)
                    {
                        ComponentSpikesCollection[idx] = new byte[LargestComponentLength];
                        ComponentSpikesCollection[idx].Populate((byte)0);
                        allSpikesLength += coder.BaseCodeLength;
                        ++idx;
                    }
                }
                AllSpikesFlatCollection = new byte[allSpikesLength];
                AllSpikesFlatCollection.Populate((byte)0);
            }
            break;
            }

            return;
        }