Exemple #1
0
        /// <summary>
        /// Creates configuration of the group of analog neurons having a TanH activation.
        /// </summary>
        /// <param name="groupName">The name of the group</param>
        /// <param name="relShare">The relative share. It determines how big part of the pool neurons will be occupied by this neuron group.</param>
        private AnalogNeuronGroupSettings CreateTanHGroup(string groupName, double relShare)
        {
            //Each neuron within the group will have its own constant bias
            //selected from the range -0.05 to 0.05 using gaussian (normal) distribution
            RandomValueSettings biasCfg = new RandomValueSettings(-0.05, 0.05, false, new GaussianDistrSettings(0, 1));
            //We want retainment property to be set for every neuron within the group
            const double RetainmentDensity = 1d;
            //Each neuron will have its own constant retainment strength
            //selected from the range 0 to 0.75 using uniform distribution
            URandomValueSettings retainmentStrengthCfg = new URandomValueSettings(0, 0.75);
            RetainmentSettings   retainmentCfg         = new RetainmentSettings(RetainmentDensity, retainmentStrengthCfg);
            //Predictors configuration
            //We will use the Activation and ActivationPower predictors
            PredictorsProviderSettings predictorsCfg = new PredictorsProviderSettings(new PredictorActivationSettings(),
                                                                                      new PredictorActivationPowerSettings()
                                                                                      );



            //Create the neuron group configuration
            AnalogNeuronGroupSettings groupCfg = new AnalogNeuronGroupSettings(groupName,
                                                                               relShare,
                                                                               new AFAnalogTanHSettings(),
                                                                               predictorsCfg,
                                                                               AnalogNeuronGroupSettings.DefaultFiringThreshold,
                                                                               AnalogNeuronGroupSettings.DefaultThresholdMaxRefDeepness,
                                                                               biasCfg,
                                                                               retainmentCfg
                                                                               );

            return(groupCfg);
        }
Exemple #2
0
        /// <summary>
        /// Creates the 3D pool of analog neurons.
        /// </summary>
        /// <param name="poolName">The name of the pool.</param>
        /// <param name="dimX">Size on X dimension.</param>
        /// <param name="dimY">Size on Y dimension.</param>
        /// <param name="dimZ">Size on Z dimension.</param>
        /// <param name="randomInterconnectionDensity">The density of the random interconnection.</param>
        private PoolSettings CreateAnalogPoolCfg(string poolName, int dimX, int dimY, int dimZ, double randomInterconnectionDensity)
        {
            //Create TanH group of neurons
            AnalogNeuronGroupSettings grpCfg = CreateTanHGroup("Exc-TanH-Grp", 1);
            //We use two interconnection schemas
            //Chain schema (circle shaped). We use ratio 1 so all the neurons within the pool will be connected into the circle shaped chain.
            ChainSchemaSettings chainSchemaCfg = new ChainSchemaSettings(1d, true);
            //Random schema
            RandomSchemaSettings randomSchemaCfg = new RandomSchemaSettings(randomInterconnectionDensity);
            //Create pool configuration
            PoolSettings poolCfg = new PoolSettings(poolName,
                                                    new ProportionsSettings(dimX, dimY, dimZ),
                                                    new NeuronGroupsSettings(grpCfg),
                                                    new InterconnSettings(chainSchemaCfg, randomSchemaCfg)
                                                    );

            return(poolCfg);
        }
Exemple #3
0
        /// <summary>
        /// Creates configuration of group of analog neurons having specified analog activation.
        /// </summary>
        /// <param name="activationCfg">Activation function configuration</param>
        /// <param name="maxAbsBias">Maximum absolute value of the bias (0 means bias is not required)</param>
        /// <param name="maxRetainmentStrength">Maximum retainment strength (0 means retainment property is not required)</param>
        private AnalogNeuronGroupSettings CreateAnalogGroup(RCNetBaseSettings activationCfg,
                                                            double maxAbsBias            = 0d,
                                                            double maxRetainmentStrength = 0d
                                                            )
        {
            //Bias configuration
            RandomValueSettings biasCfg = maxAbsBias == 0 ? null : new RandomValueSettings(-maxAbsBias, maxAbsBias);
            //Retainment configuration
            const double       RetainmentDensity = 1d;
            RetainmentSettings retainmentCfg     = maxRetainmentStrength == 0 ? null : new RetainmentSettings(RetainmentDensity, new URandomValueSettings(0, maxRetainmentStrength));
            //Create neuron group configuration
            AnalogNeuronGroupSettings groupCfg = new AnalogNeuronGroupSettings(GetNeuronGroupName(activationCfg),
                                                                               1d,
                                                                               activationCfg,
                                                                               AnalogNeuronGroupSettings.DefaultFiringThreshold,
                                                                               AnalogNeuronGroupSettings.DefaultThresholdMaxRefDeepness,
                                                                               biasCfg,
                                                                               retainmentCfg,
                                                                               null
                                                                               );

            return(groupCfg);
        }
Exemple #4
0
        /// <summary>
        /// Creates the simplified configuration of the state machine following the pure ESN design.
        /// </summary>
        /// <param name="totalSize">The total number of hidden neurons.</param>
        /// <param name="maxInputStrength">The max sum of weights of input synapses per an analog hidden neuron (see the constant DefaultAnalogMaxInputStrength).</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="maxAbsBias">The maximum absolute value of the bias (0 means no bias).</param>
        /// <param name="maxRetainmentStrength">The maximum retainment strength (0 means no retainment).</param>
        /// <param name="predictorsProviderCfg">The configuration of the predictors provider.</param>
        public StateMachineSettings CreatePureESNCfg(int totalSize,
                                                     double maxInputStrength,
                                                     double inputConnectionDensity,
                                                     int maxInputDelay,
                                                     double interconnectionDensity,
                                                     int maxInternalDelay,
                                                     double maxAbsBias,
                                                     double maxRetainmentStrength,
                                                     PredictorsProviderSettings predictorsProviderCfg
                                                     )
        {
            //Check NP is not bypassed
            if (BypassedNP)
            {
                throw new InvalidOperationException("Neural preprocessor is bypassed thus ESN design can't be created.");
            }
            //Default ESN activation
            IActivationSettings analogActivationCfg = new AFAnalogTanHSettings();
            //One neuron group
            AnalogNeuronGroupSettings grp = CreateAnalogGroup(analogActivationCfg, predictorsProviderCfg, maxAbsBias, maxRetainmentStrength);
            //Simple analog pool
            PoolSettings poolCfg = new PoolSettings(BuildPoolName(ActivationContent.Analog, 0),
                                                    new ProportionsSettings(totalSize, 1, 1),
                                                    new NeuronGroupsSettings(grp),
                                                    new InterconnSettings(new RandomSchemaSettings(interconnectionDensity))
                                                    );
            //Simple reservoir structure
            ReservoirStructureSettings resStructCfg = new ReservoirStructureSettings(BuildResStructName(ActivationContent.Analog, 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,
                                                                       0,
                                                                       inputConnectionDensity
                                                                       );
                inputConns.Add(inputConnCfg);
            }
            //Synapse general configuration
            SynapseATInputSettings       synapseATInputSettings       = new SynapseATInputSettings(Synapse.SynapticDelayMethod.Random, maxInputDelay, new AnalogSourceSettings(new URandomValueSettings(0d, maxInputStrength)));
            SynapseATIndifferentSettings synapseATIndifferentSettings = new SynapseATIndifferentSettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay);
            SynapseATSettings            synapseATCfg = new SynapseATSettings(SynapseATSettings.DefaultSpectralRadiusNum, synapseATInputSettings, synapseATIndifferentSettings);
            SynapseSettings synapseCfg = new SynapseSettings(null, synapseATCfg);

            //Create reservoir instance
            ReservoirInstanceSettings resInstCfg = new ReservoirInstanceSettings(GetResInstName(ResDesign.PureESN, 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
                                            ));
        }
Exemple #5
0
        /// <summary>
        /// Creates StateMachine configuration following pure ESN design
        /// </summary>
        /// <param name="totalSize">Total number of hidden neurons</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="maxAbsBias">Maximum absolute value of the bias (0 means bias is not required)</param>
        /// <param name="maxRetainmentStrength">Maximum retainment strength (0 means retainment property is not required)</param>
        /// <param name="predictorsParamsCfg">Predictors parameters (use null for defaults)</param>
        /// <param name="allowedPredictor">Allowed predictor(s)</param>
        public StateMachineSettings CreatePureESNCfg(int totalSize,
                                                     double inputConnectionDensity,
                                                     int maxInputDelay,
                                                     double interconnectionDensity,
                                                     int maxInternalDelay,
                                                     double maxAbsBias,
                                                     double maxRetainmentStrength,
                                                     PredictorsParamsSettings predictorsParamsCfg,
                                                     params PredictorsProvider.PredictorID[] allowedPredictor
                                                     )
        {
            const double MaxInputWeightSum = 2.75d;
            //Default ESN activation
            RCNetBaseSettings aFnCfg = new TanHSettings();
            //One neuron group
            AnalogNeuronGroupSettings grp = CreateAnalogGroup(aFnCfg, maxAbsBias, maxRetainmentStrength);
            //Simple analog pool
            PoolSettings poolCfg = new PoolSettings(GetPoolName(ActivationContent.Analog, 0),
                                                    new ProportionsSettings(totalSize, 1, 1),
                                                    new NeuronGroupsSettings(grp),
                                                    new InterconnSettings(new RandomSchemaSettings(interconnectionDensity))
                                                    );
            //Simple reservoir structure
            ReservoirStructureSettings resStructCfg = new ReservoirStructureSettings(GetResStructName(ActivationContent.Analog, 0),
                                                                                     new PoolsSettings(poolCfg)
                                                                                     );
            //Input connections configuration
            List <InputConnSettings> inputConns = new List <InputConnSettings>(InputCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count);
            double maxInpSynWeight = MaxInputWeightSum / InputCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count;

            foreach (ExternalFieldSettings fieldCfg in InputCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
            {
                InputConnSettings inputConnCfg = new InputConnSettings(fieldCfg.Name,
                                                                       poolCfg.Name,
                                                                       0,
                                                                       inputConnectionDensity
                                                                       );
                inputConns.Add(inputConnCfg);
            }
            //Synapse general configuration
            AnalogSourceSettings         asc = new AnalogSourceSettings(new URandomValueSettings(0, maxInpSynWeight));
            SynapseATInputSettings       synapseATInputSettings       = new SynapseATInputSettings(Synapse.SynapticDelayMethod.Random, maxInputDelay, asc, null);
            SynapseATIndifferentSettings synapseATIndifferentSettings = new SynapseATIndifferentSettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay);
            SynapseATSettings            synapseATCfg = new SynapseATSettings(SynapseATSettings.DefaultSpectralRadiusNum, synapseATInputSettings, synapseATIndifferentSettings);
            SynapseSettings synapseCfg = new SynapseSettings(null, synapseATCfg);

            //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.PureESN, 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
                                            ));
        }