コード例 #1
0
ファイル: InputField.cs プロジェクト: okozelsk/NET
        //Constructor
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="name">The name of the input field.</param>
        /// <param name="idx">The zero-based index of the input field among other input fields.</param>
        /// <param name="coordinates">The coordinates of input neurons in 3D space.</param>
        /// <param name="dataWorkingRange">The output range of the input data.</param>
        /// <param name="featureFilterCfg">The configuration of the feature filter.</param>
        /// <param name="spikesEncodingCfg">The configuration of the spikes coder.</param>
        /// <param name="routeToReadout">Specifies whether to route the input field values to readout layer.</param>
        /// <param name="inputNeuronsStartIdx">The zero-based index of the first input neuron of this field among all other input neurons.</param>
        public InputField(string name,
                          int idx,
                          int[] coordinates,
                          Interval dataWorkingRange,
                          IFeatureFilterSettings featureFilterCfg,
                          InputSpikesCoderSettings spikesEncodingCfg,
                          bool routeToReadout,
                          int inputNeuronsStartIdx
                          )
        {
            Name            = name;
            Idx             = idx;
            RouteToReadout  = routeToReadout;
            _featureFilter  = FeatureFilterFactory.Create(dataWorkingRange, featureFilterCfg);
            _iAnalogStimuli = 0;
            _currentDataIdx = 0;
            //Spikes encoder
            _spikesEncoder = new InputSpikesCoder(spikesEncodingCfg);
            //Analog neuron
            int verticalCycles = _spikesEncoder.Regime == InputEncoder.InputSpikesCoding.Vertical ? _spikesEncoder.LargestComponentLength : 1;

            AnalogNeuron = new AnalogInputNeuron(new NeuronLocation(InputEncoder.ReservoirID, inputNeuronsStartIdx, InputEncoder.PoolID, inputNeuronsStartIdx, idx, coordinates[0], coordinates[1], coordinates[2]), verticalCycles);
            ++inputNeuronsStartIdx;
            //Spiking neurons
            int spikingPopulationSize;

            if (_spikesEncoder.Regime == InputEncoder.InputSpikesCoding.Horizontal)
            {
                //Population encoding
                spikingPopulationSize = _spikesEncoder.AllSpikesFlatCollection.Length;
            }
            else if (_spikesEncoder.Regime == InputEncoder.InputSpikesCoding.Vertical)
            {
                //Spike-train encoding
                spikingPopulationSize = _spikesEncoder.ComponentSpikesCollection.Length;
            }
            else
            {
                //Forbidden encoding
                spikingPopulationSize = 0;
            }
            SpikingNeuronCollection = new SpikingInputNeuron[spikingPopulationSize];
            for (int i = 0; i < SpikingNeuronCollection.Length; i++)
            {
                SpikingNeuronCollection[i] = new SpikingInputNeuron(new NeuronLocation(InputEncoder.ReservoirID, inputNeuronsStartIdx, InputEncoder.PoolID, inputNeuronsStartIdx, idx, coordinates[0], coordinates[1], coordinates[2]));
                ++inputNeuronsStartIdx;
            }
            return;
        }
コード例 #2
0
        //Constructor
        /// <summary>
        /// Creates an initialized instance
        /// </summary>
        /// <param name="name">Name of the input field</param>
        /// <param name="idx">Index of the input field</param>
        /// <param name="coordinates">Input coordinates (entry point)</param>
        /// <param name="dataWorkingRange">Input data range</param>
        /// <param name="featureFilterCfg">Feature filter configuration</param>
        /// <param name="spikeCodeCfg">Configuration of the input spike code</param>
        /// <param name="routeToReadout">Specifies whether to route values as the additional predictors to readout</param>
        /// <param name="inputNeuronsStartIdx">Index of the first input neuron of this unit among all input neurons</param>
        public InputField(string name,
                          int idx,
                          int[] coordinates,
                          Interval dataWorkingRange,
                          IFeatureFilterSettings featureFilterCfg,
                          SpikeCodeSettings spikeCodeCfg,
                          bool routeToReadout,
                          int inputNeuronsStartIdx
                          )
        {
            Name           = name;
            Idx            = idx;
            RouteToReadout = routeToReadout;
            _featureFilter = FeatureFilterFactory.Create(dataWorkingRange, featureFilterCfg);
            //Analog neuron
            AnalogNeuron = new AnalogInputNeuron(new NeuronLocation(InputEncoder.ReservoirID, inputNeuronsStartIdx, InputEncoder.PoolID, inputNeuronsStartIdx, idx, coordinates[0], coordinates[1], coordinates[2]));
            ++inputNeuronsStartIdx;
            //Spiking neurons
            _realSpikeCode = null;
            int populationSize = -1;

            switch (_featureFilter.Type)
            {
            case FeatureFilterBase.FeatureType.Real:
                _realSpikeCode = new SpikeCode(spikeCodeCfg);
                populationSize = _realSpikeCode.Code.Length;
                break;

            case FeatureFilterBase.FeatureType.Binary:
                populationSize = 1;
                break;

            case FeatureFilterBase.FeatureType.Enum:
                populationSize = ((EnumFeatureFilterSettings)featureFilterCfg).NumOfElements;
                break;
            }
            SpikingNeuronCollection = new SpikingInputNeuron[populationSize];
            for (int i = 0; i < SpikingNeuronCollection.Length; i++)
            {
                SpikingNeuronCollection[i] = new SpikingInputNeuron(new NeuronLocation(InputEncoder.ReservoirID, inputNeuronsStartIdx, InputEncoder.PoolID, inputNeuronsStartIdx, idx, coordinates[0], coordinates[1], coordinates[2]));
                ++inputNeuronsStartIdx;
            }
            return;
        }