コード例 #1
0
        private void TestA2SCoder()
        {
            double[]     orderedAnalogValues    = { -1, -0.9, -0.8, -0.7, -0.6, -0.5, -0.4, -0.3, -0.2, -0.1, -0.05, -0.025, -0.0125, 0, 0.0125, 0.025, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1 };
            double[]     disorderedAnalogValues = { -1, 1, -0.8, -0.7, 0.8, 0.8, -0.4, 0.3, 0.2, 1, 0, 0.1, 0.2, 0.3, -0.5, 0.6, 0.9 };
            A2SCoderBase coder = null;

            //Gaussian
            coder = new A2SCoderGaussianReceptors(new A2SCoderGaussianReceptorsSettings(8, 10));
            Console.WriteLine($"{coder.GetType().Name}");
            foreach (double value in orderedAnalogValues)
            {
                Console.WriteLine($"    {value.ToString(CultureInfo.InvariantCulture),-10} {ByteArraysToString(coder.GetCode(value))}");
            }
            Console.ReadLine();

            //Signal strength
            coder = new A2SCoderSignalStrength(new A2SCoderSignalStrengthSettings(8));
            Console.WriteLine($"{coder.GetType().Name}");
            foreach (double value in orderedAnalogValues)
            {
                Console.WriteLine($"    {value.ToString(CultureInfo.InvariantCulture),-10} {ByteArraysToString(coder.GetCode(value))}");
            }
            Console.ReadLine();

            //UpDirArrows
            coder = new A2SCoderUpDirArrows(new A2SCoderUpDirArrowsSettings(16, 8));
            Console.WriteLine($"{coder.GetType().Name}");
            foreach (double value in disorderedAnalogValues)
            {
                Console.WriteLine($"    {value.ToString(CultureInfo.InvariantCulture),-10} {ByteArraysToString(coder.GetCode(value))}");
            }
            Console.ReadLine();

            //DownDirArrows
            coder = new A2SCoderDownDirArrows(new A2SCoderDownDirArrowsSettings(16, 8));
            Console.WriteLine($"{coder.GetType().Name}");
            foreach (double value in disorderedAnalogValues)
            {
                Console.WriteLine($"    {value.ToString(CultureInfo.InvariantCulture),-10} {ByteArraysToString(coder.GetCode(value))}");
            }
            Console.ReadLine();

            return;
        }
コード例 #2
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;
        }