Exemplo n.º 1
0
        /// <summary>
        /// Creates the reservoir instance configuration.
        /// </summary>
        /// <param name="instName">The name of the reservoir instance.</param>
        /// <param name="structName">The name of the reservoir structure configuration.</param>
        /// <param name="pool1Name">The name of the first pool.</param>
        /// <param name="pool2Name">The name of the second pool.</param>
        /// <param name="inputMaxDelay">The maximum delay of input synapses.</param>
        /// <param name="internalMaxDelay">The maximum delay of internal synapses.</param>
        private ReservoirInstanceSettings CreateResInstCfg(string instName,
                                                           string structName,
                                                           string pool1Name,
                                                           string pool2Name,
                                                           int inputMaxDelay,
                                                           int internalMaxDelay
                                                           )
        {
            //Maximum weight of input connection
            const double ConnMaxWeight = 0.6d;
            //Create input connections configurations for each input field
            //We connect High input field to Pool1
            InputConnSettings inpConnHighCfg = CreateInputConnCfg("High", pool1Name);
            //We connect Low input field to Pool2
            InputConnSettings inpConnLowCfg = CreateInputConnCfg("Low", pool2Name);
            //We connect Adj Close input field to both pools
            InputConnSettings inpConnAdjCloseP1Cfg = CreateInputConnCfg("Adj Close", pool1Name);
            InputConnSettings inpConnAdjCloseP2Cfg = CreateInputConnCfg("Adj Close", pool2Name);
            //Synapse general configuration
            AnalogSourceSettings         asc = new AnalogSourceSettings(new URandomValueSettings(0, ConnMaxWeight));
            SynapseATInputSettings       synapseATInputSettings       = new SynapseATInputSettings(Synapse.SynapticDelayMethod.Random, inputMaxDelay, asc, null);
            SynapseATIndifferentSettings synapseATIndifferentSettings = new SynapseATIndifferentSettings(Synapse.SynapticDelayMethod.Random, internalMaxDelay);
            SynapseATSettings            synapseATCfg = new SynapseATSettings(SynapseATSettings.DefaultSpectralRadiusNum, synapseATInputSettings, synapseATIndifferentSettings);
            SynapseSettings synapseCfg = new SynapseSettings(null, synapseATCfg);
            //Create the reservoir instance configuration
            ReservoirInstanceSettings resInstCfg = new ReservoirInstanceSettings(instName,
                                                                                 structName,
                                                                                 new InputConnsSettings(inpConnHighCfg, inpConnLowCfg, inpConnAdjCloseP1Cfg, inpConnAdjCloseP2Cfg),
                                                                                 synapseCfg
                                                                                 );

            return(resInstCfg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates reservoir instance configuration
        /// </summary>
        /// <param name="instName">Name of the reservoir instance</param>
        /// <param name="structName">Name of the associated reservoir structure configuration</param>
        /// <param name="pool1Name">Name of the first pool</param>
        /// <param name="pool2Name">Name of the second pool</param>
        /// <param name="inputMaxDelay">Maximum delay of input synapses</param>
        /// <param name="internalMaxDelay">Maximum delay of internal synapses</param>
        private ReservoirInstanceSettings CreateResInstCfg(string instName,
                                                           string structName,
                                                           string pool1Name,
                                                           string pool2Name,
                                                           int inputMaxDelay,
                                                           int internalMaxDelay
                                                           )
        {
            //Maximum weight of input connection
            const double ConnMaxWeight = 0.6d;
            //Create input connections configurations for each input field
            //We connect High input field to Pool1
            InputConnSettings inpConnHighCfg = CreateInputConnCfg("High", pool1Name);
            //We connect Low input field to Pool2
            InputConnSettings inpConnLowCfg = CreateInputConnCfg("Low", pool2Name);
            //We connect Adj Close input field to both pools
            InputConnSettings inpConnAdjCloseP1Cfg = CreateInputConnCfg("Adj Close", pool1Name);
            InputConnSettings inpConnAdjCloseP2Cfg = CreateInputConnCfg("Adj Close", pool2Name);
            //Synapse general configuration
            AnalogSourceSettings         asc = new AnalogSourceSettings(new URandomValueSettings(0, ConnMaxWeight));
            SynapseATInputSettings       synapseATInputSettings       = new SynapseATInputSettings(Synapse.SynapticDelayMethod.Random, inputMaxDelay, asc, null);
            SynapseATIndifferentSettings synapseATIndifferentSettings = new SynapseATIndifferentSettings(Synapse.SynapticDelayMethod.Random, internalMaxDelay);
            SynapseATSettings            synapseATCfg = new SynapseATSettings(SynapseATSettings.DefaultSpectralRadiusNum, synapseATInputSettings, synapseATIndifferentSettings);
            SynapseSettings synapseCfg = new SynapseSettings(null, synapseATCfg);

            //Predictors configuration
            //We use constructor accepting array of boolean switches
            //Initially we set all switches to false - all available predictors are forbidden
            bool[] predictorSwitches = new bool[PredictorsProvider.NumOfSupportedPredictors];
            predictorSwitches.Populate(false);
            //Now we enable Activation and ActivationMWAvg predictors
            predictorSwitches[(int)PredictorsProvider.PredictorID.Activation]      = true;
            predictorSwitches[(int)PredictorsProvider.PredictorID.ActivationMWAvg] = true;
            //We configure activation moving average predictor to use constant weights and last 7 values without the leaks
            ActivationMWAvgSettings activationMWAvgCfg = new ActivationMWAvgSettings(7, PredictorsProvider.PredictorMWAvgWeightsType.Constant);
            //We create predictors parameters configuration including custom configuration of activation moving average predictor
            PredictorsParamsSettings predictorsParamsCfg = new PredictorsParamsSettings(activationMWAvgCfg);
            //Create predictors configuration using prepared boolean switches and predictors parameters
            PredictorsSettings predictorsCfg = new PredictorsSettings(predictorSwitches, predictorsParamsCfg);
            //Create reservoir instance configuration
            ReservoirInstanceSettings resInstCfg = new ReservoirInstanceSettings(instName,
                                                                                 structName,
                                                                                 new InputConnsSettings(inpConnHighCfg, inpConnLowCfg, inpConnAdjCloseP1Cfg, inpConnAdjCloseP2Cfg),
                                                                                 synapseCfg,
                                                                                 predictorsCfg
                                                                                 );

            return(resInstCfg);
        }
Exemplo n.º 3
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
                                            ));
        }
Exemplo n.º 4
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
                                            ));
        }