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