コード例 #1
0
 private Mutator(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer, MutationConfigurationSettings config)
 {
     _networkFactory    = networkFactory;
     _weightInitializer = weightInitializer;
     _config            = config;
     _random            = new Random();
 }
コード例 #2
0
 public GenomeFactory(
     INeuralNetworkFactory neuralNetworkFactory,
     IEvolutionSettings <TSimulation> evolutionSettings)
 {
     this.neuralNetworkFactory = neuralNetworkFactory;
     this.evolutionSettings    = evolutionSettings;
 }
コード例 #3
0
ファイル: Mutator.cs プロジェクト: jobeland/GeneticAlgorithm
 private Mutator(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer, MutationConfigurationSettings config)
 {
     _networkFactory = networkFactory;
     _weightInitializer = weightInitializer;
     _config = config;
     _random = new Random();
 }
コード例 #4
0
 private GeneticAlgorithmFactory(INeuralNetworkFactory networkFactory, IEvalWorkingSetFactory workingSetFactory, IEvaluatableFactory evaluatableFactory, IBreederFactory breederFactory, IMutatorFactory mutatorFactory)
 {
     _networkFactory = networkFactory;
     _workingSetFactory = workingSetFactory;
     _evaluatableFactory = evaluatableFactory;
     _breederFactory = breederFactory;
     _mutatorFactory = mutatorFactory;
 }
コード例 #5
0
 private GeneticAlgorithmFactory(INeuralNetworkFactory networkFactory, IEvalWorkingSetFactory workingSetFactory, IEvaluatableFactory evaluatableFactory, IBreederFactory breederFactory, IMutatorFactory mutatorFactory)
 {
     _networkFactory     = networkFactory;
     _workingSetFactory  = workingSetFactory;
     _evaluatableFactory = evaluatableFactory;
     _breederFactory     = breederFactory;
     _mutatorFactory     = mutatorFactory;
 }
コード例 #6
0
        public ConvolutionalLayer(INeuralNetworkFactory factory, ConvolutionDescriptor descriptor, int inputDepth, int inputWidth, bool disableUpdate = false)
        {
            _inputWidth = inputWidth;
            _lap        = factory.LinearAlgebraProvider;
            _descriptor = descriptor;
            var activation = factory.GetActivation(descriptor.Activation);
            var layer      = new InternalLayer(factory.LinearAlgebraProvider, descriptor.FilterSize * inputDepth, descriptor.FilterDepth, activation, descriptor, disableUpdate);

            _trainer = factory.CreateTrainer(layer, descriptor);
        }
コード例 #7
0
        public Lstm(int inputSize, int hiddenSize, INeuralNetworkFactory factory, LayerDescriptor template)
        {
            _lap        = factory.LinearAlgebraProvider;
            _activation = factory.GetActivation(template.Activation);

            _wc = CreateLayer(inputSize, hiddenSize, factory, template);
            _wi = CreateLayer(inputSize, hiddenSize, factory, template);
            _wf = CreateLayer(inputSize, hiddenSize, factory, template);
            _wo = CreateLayer(inputSize, hiddenSize, factory, template);

            _uc = CreateLayer(hiddenSize, hiddenSize, factory, template);
            _ui = CreateLayer(hiddenSize, hiddenSize, factory, template);
            _uf = CreateLayer(hiddenSize, hiddenSize, factory, template);
            _uo = CreateLayer(hiddenSize, hiddenSize, factory, template);
        }
コード例 #8
0
        static void Main(string[] args)
        {
            NeuralNetworkConfigurationSettings networkConfig = new NeuralNetworkConfigurationSettings
            {
                NumInputNeurons    = 1,
                NumOutputNeurons   = 1,
                NumHiddenLayers    = 2,
                NumHiddenNeurons   = 3,
                SummationFunction  = new SimpleSummation(),
                ActivationFunction = new TanhActivationFunction()
            };
            GenerationConfigurationSettings generationSettings = new GenerationConfigurationSettings
            {
                UseMultithreading    = true,
                GenerationPopulation = 500
            };
            EvolutionConfigurationSettings evolutionSettings = new EvolutionConfigurationSettings
            {
                NormalMutationRate  = 0.05,
                HighMutationRate    = 0.5,
                GenerationsPerEpoch = 10,
                NumEpochs           = 1000,
                NumTopEvalsToReport = 10
            };
            MutationConfigurationSettings mutationSettings = new MutationConfigurationSettings
            {
                MutateAxonActivationFunction       = true,
                MutateNumberOfHiddenLayers         = true,
                MutateNumberOfHiddenNeuronsInLayer = true,
                MutateSomaBiasFunction             = true,
                MutateSomaSummationFunction        = true,
                MutateSynapseWeights = true
            };
            var random = new RandomWeightInitializer(new Random());
            INeuralNetworkFactory factory          = NeuralNetworkFactory.GetInstance(SomaFactory.GetInstance(networkConfig.SummationFunction), AxonFactory.GetInstance(networkConfig.ActivationFunction), SynapseFactory.GetInstance(new RandomWeightInitializer(new Random()), AxonFactory.GetInstance(networkConfig.ActivationFunction)), SynapseFactory.GetInstance(new ConstantWeightInitializer(1.0), AxonFactory.GetInstance(new IdentityActivationFunction())), random);
            IBreeder            breeder            = BreederFactory.GetInstance(factory, random).Create();
            IMutator            mutator            = MutatorFactory.GetInstance(factory, random).Create(mutationSettings);
            IEvalWorkingSet     history            = EvalWorkingSetFactory.GetInstance().Create(50);
            IEvaluatableFactory evaluatableFactory = new GameEvaluationFactory();

            IStorageProxy proxy  = new NodeJSProxy(1, "http://localhost:3000", "123456789");
            IEpochAction  action = new BestPerformerUpdater(proxy);

            var GAFactory             = GeneticAlgorithmFactory.GetInstance(evaluatableFactory);
            IGeneticAlgorithm evolver = GAFactory.Create(networkConfig, generationSettings, evolutionSettings, factory, breeder, mutator, history, evaluatableFactory, action);

            evolver.RunSimulation();
        }
        public INeuralNetworkFactory BuildBackpropagationNetworkFactory(IWeightInitializer weightInitializer,
                                                                        ISomaFactory somaFactory,
                                                                        IActivationFunctionDerivative activationFunctionDerivative,
                                                                        IActivationFunction inputActivationFunction,
                                                                        INeuronFactory neuronFactory)
        {
            var axonFactory          = BackpropagationAxonFactory.GetInstance(activationFunctionDerivative);
            var hiddenSynapseFactory = DecoratedSynapseFactory.GetInstance(weightInitializer,
                                                                           AxonFactory.GetInstance(activationFunctionDerivative));
            var inputSynapseFactory = DecoratedSynapseFactory.GetInstance(new ConstantWeightInitializer(1.0),
                                                                          AxonFactory.GetInstance(inputActivationFunction));
            var decoratedNeuronFactory    = BackpropagationNeuronFactory.GetInstance(neuronFactory);
            INeuralNetworkFactory factory = NeuralNetworkFactory.GetInstance(somaFactory, axonFactory,
                                                                             hiddenSynapseFactory, inputSynapseFactory, weightInitializer, decoratedNeuronFactory);

            var backPropNetworkFactory = new BackpropagationNetworkFactoryDecorator(factory);

            return(backPropNetworkFactory);
        }
コード例 #10
0
        private GeneticAlgorithm(NeuralNetworkConfigurationSettings networkConfig, GenerationConfigurationSettings generationConfig, EvolutionConfigurationSettings evolutionConfig, INeuralNetworkFactory networkFactory, IBreeder breeder, IMutator mutator, IEvalWorkingSet workingSet, IEvaluatableFactory evaluatableFactory, IEpochAction epochAction)
        {
            _networkConfig    = networkConfig;
            _generationConfig = generationConfig;
            _evolutionConfig  = evolutionConfig;
            _epochAction      = epochAction;
            var sessions = new List <ITrainingSession>();

            _networkFactory     = networkFactory;
            _breeder            = breeder;
            _mutator            = mutator;
            _history            = workingSet;
            _evaluatableFactory = evaluatableFactory;
            for (int i = 0; i < _generationConfig.GenerationPopulation; i++)
            {
                var network = _networkFactory.Create(_networkConfig.NumInputNeurons, _networkConfig.NumOutputNeurons, _networkConfig.NumHiddenLayers, _networkConfig.NumHiddenNeurons);
                sessions.Add(new TrainingSession(network, _evaluatableFactory.Create(network), i));
            }
            _generation = new Generation(sessions, _generationConfig);
        }
コード例 #11
0
        protected internal INeuralNetworkLayerUpdater CreateLayer(int inputSize, int outputSize, INeuralNetworkFactory factory, LayerDescriptor template)
        {
            var descriptor = template.Clone();

            descriptor.Activation = ActivationType.None;
            var layer = factory.CreateLayer(inputSize, outputSize, descriptor);

            return(factory.CreateUpdater(layer, template));
        }
コード例 #12
0
ファイル: Mutator.cs プロジェクト: jobeland/GeneticAlgorithm
 public static IMutator GetInstance(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer, MutationConfigurationSettings config)
 {
     return new Mutator(networkFactory, weightInitializer, config);
 }
コード例 #13
0
 public static IBreederFactory GetInstance(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer)
 {
     return new BreederFactory(networkFactory, weightInitializer);
 }
コード例 #14
0
 private BreederFactory(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer)
 {
     _networkFactory = networkFactory;
     _weightInitializer = weightInitializer;
 }
コード例 #15
0
 public IGeneticAlgorithm Create(NeuralNetworkConfigurationSettings networkConfig, GenerationConfigurationSettings generationConfig, EvolutionConfigurationSettings evolutionConfig, INeuralNetworkFactory networkFactory, IBreeder breeder, IMutator mutator, IEvalWorkingSet workingSet, IEvaluatableFactory evaluatableFactory, IEpochAction epochAction)
 {
     return GeneticAlgorithm.GetInstance(networkConfig, generationConfig, evolutionConfig, _networkFactory, breeder, mutator, workingSet, _evaluatableFactory, epochAction);
 }
コード例 #16
0
 public static IGeneticAlgorithmFactory GetInstance(INeuralNetworkFactory networkFactory, IEvalWorkingSetFactory workingSetFactory, IEvaluatableFactory evaluatableFactory, IBreederFactory breederFactory, IMutatorFactory mutatorFactory)
 {
     return new GeneticAlgorithmFactory(networkFactory, workingSetFactory, evaluatableFactory, breederFactory, mutatorFactory);
 }
コード例 #17
0
 public static IBreeder GetInstance(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer, double motherFatherBias = 0.5)
 {
     return(new Breeder(networkFactory, weightInitializer, motherFatherBias));
 }
コード例 #18
0
 public SimpleRecurrent(int inputSize, int hiddenSize, INeuralNetworkFactory factory, LayerDescriptor template)
 {
     _activation = factory.GetActivation(template.Activation);
     _input      = CreateLayer(inputSize, hiddenSize, factory, template);
     _memory     = CreateLayer(hiddenSize, hiddenSize, factory, template);
 }
コード例 #19
0
 public static IGeneticAlgorithmFactory GetInstance(INeuralNetworkFactory networkFactory, IEvalWorkingSetFactory workingSetFactory, IEvaluatableFactory evaluatableFactory, IBreederFactory breederFactory, IMutatorFactory mutatorFactory)
 {
     return(new GeneticAlgorithmFactory(networkFactory, workingSetFactory, evaluatableFactory, breederFactory, mutatorFactory));
 }
コード例 #20
0
 public static IMutatorFactory GetInstance(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer)
 {
     return(new MutatorFactory(networkFactory, weightInitializer));
 }
コード例 #21
0
 private MutatorFactory(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer)
 {
     _networkFactory    = networkFactory;
     _weightInitializer = weightInitializer;
 }
コード例 #22
0
 public IGeneticAlgorithm Create(NeuralNetworkConfigurationSettings networkConfig, GenerationConfigurationSettings generationConfig, EvolutionConfigurationSettings evolutionConfig, INeuralNetworkFactory networkFactory, IBreeder breeder, IMutator mutator, IEvalWorkingSet workingSet, IEvaluatableFactory evaluatableFactory, IEpochAction epochAction)
 {
     return(GeneticAlgorithm.GetInstance(networkConfig, generationConfig, evolutionConfig, _networkFactory, breeder, mutator, workingSet, _evaluatableFactory, epochAction));
 }
コード例 #23
0
 public static IMutator GetInstance(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer, MutationConfigurationSettings config)
 {
     return(new Mutator(networkFactory, weightInitializer, config));
 }
 public BackpropagationNetworkFactoryDecorator(INeuralNetworkFactory decoratedFactory)
 {
     _decoratedFactory = decoratedFactory;
 }
コード例 #25
0
 private Breeder(INeuralNetworkFactory networkFactory, IWeightInitializer weightInitializer, double motherFatherBias = 0.5)
 {
     _networkFactory    = networkFactory;
     _weightInitializer = weightInitializer;
     _motherFatherBias  = motherFatherBias;
 }