/// <summary> /// Tests whether the activation function can be used as the FF network's hidden layer activation. /// </summary> /// <param name="activationCfg">The configuration of the activation function.</param> public static bool IsAllowedHiddenAF(IActivationSettings activationCfg) { if (activationCfg.TypeOfActivation != ActivationType.Analog) { return(false); } AFAnalogBase analogAF = (AFAnalogBase)ActivationFactory.CreateAF(activationCfg, new Random(0)); if (!analogAF.SupportsDerivative || analogAF.DependsOnSorround) { return(false); } return(true); }
/// <summary> /// Creates an initialized instance. /// </summary> /// <param name="numOfInputValues">The number of the network's input values.</param> /// <param name="numOfOutputValues">The number of the network's output values.</param> /// <param name="cfg">The configuration of the network and associated trainer.</param> public FeedForwardNetwork(int numOfInputValues, int numOfOutputValues, FeedForwardNetworkSettings cfg) : this(numOfInputValues, numOfOutputValues) { Random rand = new Random(1); //Initialize FF network for (int i = 0; i < cfg.HiddenLayersCfg.HiddenLayerCfgCollection.Count; i++) { AddLayer(cfg.HiddenLayersCfg.HiddenLayerCfgCollection[i].NumOfNeurons, (AFAnalogBase)ActivationFactory.CreateAF(cfg.HiddenLayersCfg.HiddenLayerCfgCollection[i].ActivationCfg, rand) ); } FinalizeStructure((AFAnalogBase)ActivationFactory.CreateAF(cfg.OutputActivationCfg, rand)); return; }
/// <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 )); }
//Methods /// <summary> /// Builds the name of the specified activation function. /// </summary> /// <param name="activationCfg">The activation function configuration.</param> private string BuildActivationName(IActivationSettings activationCfg) { IActivation aFn = ActivationFactory.CreateAF(activationCfg, _rand); return(aFn.TypeOfActivation.ToString() + "-" + aFn.GetType().Name.Replace("Settings", string.Empty)); }