internal ITrainingSession ExtractSession(string serialized, double eval)
        {
            var networkGenes = JsonConvert.DeserializeObject <NeuralNetworkGene>(serialized);
            var network      = NeuralNetworkFactory.GetInstance().Create(networkGenes);
            var session      = new FakeTrainingSession(network, eval);

            return(session);
        }
        public INeuralNetwork LoadNeuralNetwork(string filename)
        {
            var jsonGenes   = File.ReadAllText(_directory + filename);
            var networkGene = JsonConvert.DeserializeObject <NeuralNetworkGene>(jsonGenes);
            var network     = NeuralNetworkFactory.GetInstance().Create(networkGene);

            return(network);
        }
        public static IGeneticAlgorithmFactory GetInstance(IEvaluatableFactory evaluatableFactory)
        {
            var networkFactory    = NeuralNetworkFactory.GetInstance();
            var workingSetFactory = EvalWorkingSetFactory.GetInstance();
            var random            = new Random();
            var breederFactory    = BreederFactory.GetInstance(networkFactory, new RandomWeightInitializer(random));
            var mutatorFactory    = MutatorFactory.GetInstance(networkFactory, new RandomWeightInitializer(random));

            return(new GeneticAlgorithmFactory(networkFactory, workingSetFactory, evaluatableFactory, breederFactory, mutatorFactory));
        }
Ejemplo n.º 4
0
        public async Task <ITrainingSession> GetBestSessionAsync()
        {
            var result = await ParseCloud.CallFunctionAsync <ParseObject>("bestNetwork", new Dictionary <string, object> {
                { "networkVersion", _networkVersion }
            });

            var networkGenes = JsonConvert.DeserializeObject <NeuralNetworkGene>((string)result["jsonNetwork"]);
            var network      = NeuralNetworkFactory.GetInstance().Create(networkGenes);
            var session      = new FakeTrainingSession(network, (double)result["eval"]);

            return(session);
        }
        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);
        }
Ejemplo n.º 7
0
 public ITrainingSession GetBestSession()
 {
     using (var client = new HttpClient())
     {
         // Replace this with the API key for the web service
         client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _apiKey);
         var networkEndpoint = _baseUrl + "/network/" + _networkVersion;
         var response        = client.GetAsync(networkEndpoint).Result;
         var responseObj     = response.Content.ReadAsAsync <NodeJsMessage>().Result;
         if (responseObj == null)
         {
             return(null);
         }
         var networkGenes = JsonConvert.DeserializeObject <NeuralNetworkGene>(responseObj.networkGenes);
         var network      = NeuralNetworkFactory.GetInstance().Create(networkGenes);
         var session      = new FakeTrainingSession(network, responseObj.eval);
         return(session);
     }
 }