//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; }
/// <summary> /// Builds the inner cluster chain. /// </summary> /// <param name="dataBundle">The data to be used for training.</param> /// <param name="filter">The feature filter to be used to denormalize output.</param> /// <param name="rand">The random object to be used (optional).</param> /// <param name="controller">The build process controller (optional).</param> public void Build(VectorBundle dataBundle, FeatureFilterBase filter, Random rand = null, TNRNetBuilder.BuildControllerDelegate controller = null ) { rand = rand ?? new Random(0); TNRNetClusterChainBuilder builder = new TNRNetClusterChainBuilder(Name, _clusterChainCfg, rand, controller ); builder.ChainBuildProgressChanged += OnChainBuildProgressChanged; _clusterChain = builder.Build(dataBundle, new FeatureFilterBase[] { filter }); return; }
//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; }
//Methods /// <summary> /// Prepares a set of filters for the input data standardization. /// </summary> /// <param name="bundle">A bundle of the input and output data vectors.</param> protected FeatureFilterBase[] PrepareInputFeatureFilters(VectorBundle bundle) { //Allocation of the feature filters FeatureFilterBase[] inputFeatureFilters = new FeatureFilterBase[bundle.InputVectorCollection[0].Length]; for (int i = 0; i < inputFeatureFilters.Length; i++) { //Input data is always considered as the real numbers. inputFeatureFilters[i] = new RealFeatureFilter(Interval.IntN1P1, //Data to be standardized between -1 and 1 new RealFeatureFilterSettings(true, //We want to standardize data true //We want to keep a range reserve for unseen data ) ); } //Update feature filters foreach (double[] vector in bundle.InputVectorCollection) { for (int i = 0; i < vector.Length; i++) { //Update filter by the next known data value. inputFeatureFilters[i].Update(vector[i]); } } return(inputFeatureFilters); }