Ejemplo n.º 1
0
        /// <summary>
        /// Creates the simplified configuration of the state machine following the pure LSM design.
        /// </summary>
        /// <param name="totalSize">The total number of hidden neurons.</param>
        /// <param name="spikingActivationCfg">The configuration of the spiking activation function.</param>
        /// <param name="excitabilityCfg">The homogenous excitability configuration.</param>
        /// <param name="inputConnectionDensity">The density of the input field connections to hidden neurons.</param>
        /// <param name="maxInputDelay">The maximum delay of an input synapse.</param>
        /// <param name="interconnectionDensity">The density of the hidden neurons recurrent interconnection.</param>
        /// <param name="maxInternalDelay">The maximum delay of an internal synapse.</param>
        /// <param name="steadyBias">The constant bias (0 means no bias).</param>
        /// <param name="predictorsProviderCfg">The configuration of the predictors provider.</param>
        public StateMachineSettings CreatePureLSMCfg(int totalSize,
                                                     IActivationSettings spikingActivationCfg,
                                                     HomogenousExcitabilitySettings excitabilityCfg,
                                                     double inputConnectionDensity,
                                                     int maxInputDelay,
                                                     double interconnectionDensity,
                                                     int maxInternalDelay,
                                                     double steadyBias,
                                                     PredictorsProviderSettings predictorsProviderCfg
                                                     )
        {
            //Check NP is not bypassed
            if (BypassedNP)
            {
                throw new InvalidOperationException("Neural preprocessor is bypassed thus LSM design can't be created.");
            }
            //Activation check
            if (ActivationFactory.CreateAF(spikingActivationCfg, new Random()).TypeOfActivation != ActivationType.Spiking)
            {
                throw new ArgumentException("Specified activation must be spiking.", "spikingActivationCfg");
            }
            //One neuron group
            SpikingNeuronGroupSettings grp = CreateSpikingGroup(spikingActivationCfg, predictorsProviderCfg, excitabilityCfg, steadyBias);
            //Simple spiking pool
            PoolSettings poolCfg = new PoolSettings(BuildPoolName(ActivationContent.Spiking, 0),
                                                    new ProportionsSettings(totalSize, 1, 1),
                                                    new NeuronGroupsSettings(grp),
                                                    new InterconnSettings(new RandomSchemaSettings(interconnectionDensity, 0d, false, false))
                                                    );
            //Simple reservoir structure
            ReservoirStructureSettings resStructCfg = new ReservoirStructureSettings(BuildResStructName(ActivationContent.Spiking, 0),
                                                                                     new PoolsSettings(poolCfg)
                                                                                     );
            //Input connections configuration
            List <InputConnSettings> inputConns = new List <InputConnSettings>(InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count);

            foreach (ExternalFieldSettings fieldCfg in InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
            {
                InputConnSettings inputConnCfg = new InputConnSettings(fieldCfg.Name,
                                                                       poolCfg.Name,
                                                                       inputConnectionDensity,
                                                                       0
                                                                       );
                inputConns.Add(inputConnCfg);
            }
            //Synapse general configuration
            SpikingSourceSTInputSettings      spikingSourceSTInputSettings      = new SpikingSourceSTInputSettings(new URandomValueSettings(0, 1), new PlasticitySTInputSettings(new NonlinearDynamicsSTInputSettings()));
            SpikingSourceSTExcitatorySettings spikingSourceSTExcitatorySettings = new SpikingSourceSTExcitatorySettings(new URandomValueSettings(0, 1), new PlasticitySTExcitatorySettings(new NonlinearDynamicsSTExcitatorySettings()));
            SpikingSourceSTInhibitorySettings spikingSourceSTInhibitorySettings = new SpikingSourceSTInhibitorySettings(new URandomValueSettings(0, 1), new PlasticitySTInhibitorySettings(new NonlinearDynamicsSTInhibitorySettings()));
            SynapseSTInputSettings            synapseSTInputSettings            = new SynapseSTInputSettings(Synapse.SynapticDelayMethod.Random, maxInputDelay, null, spikingSourceSTInputSettings);
            SynapseSTExcitatorySettings       synapseSTExcitatorySettings       = new SynapseSTExcitatorySettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay, 4, null, spikingSourceSTExcitatorySettings);
            SynapseSTInhibitorySettings       synapseSTInhibitorySettings       = new SynapseSTInhibitorySettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay, 1, null, spikingSourceSTInhibitorySettings);
            SynapseSTSettings synapseSTCfg = new SynapseSTSettings(synapseSTInputSettings, synapseSTExcitatorySettings, synapseSTInhibitorySettings);
            SynapseSettings   synapseCfg   = new SynapseSettings(synapseSTCfg, null);

            //Create reservoir instance
            ReservoirInstanceSettings resInstCfg = new ReservoirInstanceSettings(GetResInstName(ResDesign.PureLSM, 0),
                                                                                 resStructCfg.Name,
                                                                                 new InputConnsSettings(inputConns),
                                                                                 synapseCfg
                                                                                 );

            //Build and return SM configuration
            return(new StateMachineSettings(new NeuralPreprocessorSettings(InputEncoderCfg,
                                                                           new ReservoirStructuresSettings(resStructCfg),
                                                                           new ReservoirInstancesSettings(resInstCfg)
                                                                           ),
                                            ReadoutLayerCfg
                                            ));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates StateMachine configuration following pure LSM design
        /// </summary>
        /// <param name="proportionsCfg">LSM pool proportions</param>
        /// <param name="aFnCfg">Spiking activation function configuration</param>
        /// <param name="hes">Homogenous excitability configuration</param>
        /// <param name="inputConnectionDensity">Density of the input field connections to hidden neurons</param>
        /// <param name="maxInputDelay">Maximum delay of input synapse</param>
        /// <param name="interconnectionDensity">Density of the hidden neurons interconnection</param>
        /// <param name="maxInternalDelay">Maximum delay of internal synapse</param>
        /// <param name="steadyBias">Constant bias (0 means bias is not required)</param>
        /// <param name="predictorsParamsCfg">Predictors parameters (use null for defaults)</param>
        /// <param name="allowedPredictor">Allowed predictor(s)</param>
        public StateMachineSettings CreatePureLSMCfg(ProportionsSettings proportionsCfg,
                                                     RCNetBaseSettings aFnCfg,
                                                     HomogenousExcitabilitySettings hes,
                                                     double inputConnectionDensity,
                                                     int maxInputDelay,
                                                     double interconnectionDensity,
                                                     int maxInternalDelay,
                                                     double steadyBias,
                                                     PredictorsParamsSettings predictorsParamsCfg,
                                                     params PredictorsProvider.PredictorID[] allowedPredictor
                                                     )
        {
            //Activation check
            if (ActivationFactory.Create(aFnCfg, new Random()).TypeOfActivation != ActivationType.Spiking)
            {
                throw new ArgumentException("Specified activation must be spiking.", "aFnCfg");
            }
            //One neuron group
            SpikingNeuronGroupSettings grp = CreateSpikingGroup(aFnCfg, hes, steadyBias);
            //Simple spiking pool
            PoolSettings poolCfg = new PoolSettings(GetPoolName(ActivationContent.Spiking, 0),
                                                    proportionsCfg,
                                                    new NeuronGroupsSettings(grp),
                                                    new InterconnSettings(new RandomSchemaSettings(interconnectionDensity, 0d, false, false))
                                                    );
            //Simple reservoir structure
            ReservoirStructureSettings resStructCfg = new ReservoirStructureSettings(GetResStructName(ActivationContent.Spiking, 0),
                                                                                     new PoolsSettings(poolCfg)
                                                                                     );
            //Input connections configuration
            List <InputConnSettings> inputConns = new List <InputConnSettings>(InputCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count);

            foreach (ExternalFieldSettings fieldCfg in InputCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
            {
                InputConnSettings inputConnCfg = new InputConnSettings(fieldCfg.Name,
                                                                       poolCfg.Name,
                                                                       inputConnectionDensity,
                                                                       0
                                                                       );
                inputConns.Add(inputConnCfg);
            }
            //Synapse general configuration
            SynapseSTInputSettings      synapseSTInputSettings      = new SynapseSTInputSettings(Synapse.SynapticDelayMethod.Random, maxInputDelay);
            SynapseSTExcitatorySettings synapseSTExcitatorySettings = new SynapseSTExcitatorySettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay);
            SynapseSTInhibitorySettings synapseSTInhibitorySettings = new SynapseSTInhibitorySettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay);
            SynapseSTSettings           synapseSTCfg = new SynapseSTSettings(synapseSTInputSettings, synapseSTExcitatorySettings, synapseSTInhibitorySettings);
            SynapseSettings             synapseCfg   = new SynapseSettings(synapseSTCfg, null);

            //Initially set all switches to false - all available predictors are forbidden
            bool[] predictorSwitches = new bool[PredictorsProvider.NumOfSupportedPredictors];
            predictorSwitches.Populate(false);
            //Enable specified predictors
            foreach (PredictorsProvider.PredictorID predictorID in allowedPredictor)
            {
                predictorSwitches[(int)predictorID] = true;
            }
            //Create predictors configuration using default params
            PredictorsSettings predictorsCfg = new PredictorsSettings(predictorSwitches, predictorsParamsCfg);
            //Create reservoir instance
            ReservoirInstanceSettings resInstCfg = new ReservoirInstanceSettings(GetResInstName(ResDesign.PureLSM, 0),
                                                                                 resStructCfg.Name,
                                                                                 new InputConnsSettings(inputConns),
                                                                                 synapseCfg,
                                                                                 predictorsCfg
                                                                                 );

            //Build and return SM configuration
            return(new StateMachineSettings(new NeuralPreprocessorSettings(InputCfg,
                                                                           new ReservoirStructuresSettings(resStructCfg),
                                                                           new ReservoirInstancesSettings(resInstCfg)
                                                                           ),
                                            ReadoutCfg
                                            ));
        }