Exemplo n.º 1
0
        private void Initialize_private(string name, ExperimentInitArgs args)
        {
            Name        = name;
            Description = args.Description;

            _inputCount  = args.InputCount;
            _outputCount = args.OutputCount;

            DefaultPopulationSize = args.PopulationSize;

            IsHyperNEAT = args.IsHyperNEAT;
            if (args.IsHyperNEAT)
            {
                _activationSchemeCppn = GetActivationScheme_CPPN();
            }

            _activationDefinition = args.Activation;
            _activationScheme     = GetActivationScheme(args.Activation);

            _complexityRegulationStr = args.Complexity_RegulationStrategy?.ToString();
            _complexityThreshold     = args.Complexity_Threshold;

            _parallelOptions = args.MaxDegreeOfParallelism == null ?
                               new ParallelOptions() :
                               new ParallelOptions {
                MaxDegreeOfParallelism = args.MaxDegreeOfParallelism.Value
            };

            NeatEvolutionAlgorithmParameters             = new NeatEvolutionAlgorithmParameters();
            NeatEvolutionAlgorithmParameters.SpecieCount = args.SpeciesCount;
        }
Exemplo n.º 2
0
        public Evaluator_WeaponSpin(WorldAccessor worldAccessor, TrainingRoom room, BotTrackingStorage log, ExperimentInitArgs_Activation activation, double weaponSpeed_Min, double weaponSpeed_Max, HyperNEAT_Args hyperneatArgs = null, double maxEvalTime = 15)
        {
            _worldAccessor = worldAccessor;
            _room          = room;
            _log           = log;
            _activation    = activation;
            _hyperneatArgs = hyperneatArgs;
            _maxEvalTime   = maxEvalTime;

            // Set distances based on room size (or take as params?, or just a percent param?)
            double roomWidth = Math1D.Min
                               (
                room.AABB.Item2.X - room.AABB.Item1.X,
                room.AABB.Item2.Y - room.AABB.Item1.Y,
                room.AABB.Item2.Z - room.AABB.Item1.Z
                               );

            // Want radius, not diameter
            _roomRadius = roomWidth / 2;

            _maxDistance2 = _roomRadius * MULT_MAXDIST2;
            _maxDistance  = _roomRadius * MULT_MAXDIST;

            // Weapon Speed
            _weaponSpeed_Min  = weaponSpeed_Min;
            _weaponSpeed_Max  = weaponSpeed_Max;
            _weaponSpeed_Max2 = _weaponSpeed_Max + ((_weaponSpeed_Max - _weaponSpeed_Min) / 2);
        }
Exemplo n.º 3
0
        public Evaluator3(WorldAccessor worldAccessor, TrainingRoom room, BotTrackingStorage log, ExperimentInitArgs_Activation activation, HyperNEAT_Args hyperneatArgs = null, double maxEvalTime = 15, double?initialRandomVelocity = null)
        {
            _worldAccessor         = worldAccessor;
            _room                  = room;
            _log                   = log;
            _activation            = activation;
            _hyperneatArgs         = hyperneatArgs;
            _maxEvalTime           = maxEvalTime;
            _initialRandomVelocity = initialRandomVelocity;

            // Set distances based on room size (or take as params?, or just a percent param?)
            double roomWidth = Math1D.Min
                               (
                room.AABB.Item2.X - room.AABB.Item1.X,
                room.AABB.Item2.Y - room.AABB.Item1.Y,
                room.AABB.Item2.Z - room.AABB.Item1.Z
                               );

            // Want radius, not diameter
            _roomRadius = roomWidth / 2;

            _maxDistance2 = _roomRadius * MULT_MAXDIST2;
            _maxDistance  = _roomRadius * MULT_MAXDIST;
            _minDistance  = _roomRadius * MULT_MINDIST;
        }
Exemplo n.º 4
0
 /// <summary>
 /// This is inspired by ExperimentUtils.CreateActivationScheme, but can't be put there, because NeatConfigInfo_Activation isn't
 /// defined that low
 /// </summary>
 private static NetworkActivationScheme GetActivationScheme(ExperimentInitArgs_Activation scheme)
 {
     if (scheme == null)
     {
         throw new ArgumentNullException("scheme");
     }
     else if (scheme is ExperimentInitArgs_Activation_Acyclic)
     {
         return(NetworkActivationScheme.CreateAcyclicScheme());
     }
     else if (scheme is ExperimentInitArgs_Activation_CyclicFixedTimesteps)
     {
         ExperimentInitArgs_Activation_CyclicFixedTimesteps cast = (ExperimentInitArgs_Activation_CyclicFixedTimesteps)scheme;
         return(NetworkActivationScheme.CreateCyclicFixedTimestepsScheme(cast.TimestepsPerActivation, cast.FastFlag));
     }
     else if (scheme is ExperimentInitArgs_Activation_CyclicRelaxing)
     {
         ExperimentInitArgs_Activation_CyclicRelaxing cast = (ExperimentInitArgs_Activation_CyclicRelaxing)scheme;
         return(NetworkActivationScheme.CreateCyclicRelaxingActivationScheme(cast.SignalDeltaThreshold, cast.MaxTimesteps, cast.FastFlag));
     }
     else
     {
         throw new ArgumentException("Unknown scheme type: " + scheme.GetType().ToString());
     }
 }
Exemplo n.º 5
0
 private static NeatGenomeParameters GetNewNeatGenomeParameters(ExperimentInitArgs_Activation activation)
 {
     return(new NeatGenomeParameters
     {
         FeedforwardOnly = activation is ExperimentInitArgs_Activation_Acyclic      // if this is false while activation is acyclic, then the genome generator will create the wrong types of genomes, and later code with throw an exception
     });
 }
Exemplo n.º 6
0
        public static List <NeatGenome> LoadPopulation(string xml, ExperimentInitArgs_Activation activation, HyperNEAT_Args hyperneatArgs)
        {
            List <NeatGenome> retVal = null;

            using (XmlReader xr = XmlReader.Create(new MemoryStream(Encoding.Unicode.GetBytes(xml))))
            {
                retVal = LoadPopulation_static(xr, activation, hyperneatArgs);
            }

            return(retVal);
        }
Exemplo n.º 7
0
        //NOTE: These methods don't belong in experiment, they don't change it's state, and are just wrappers to static methods.  It's ugly having both
        //instance and static methods, but the INeatExperiment has the xml versions of the save/load
        public static List <NeatGenome> LoadPopulation(string xml, ExperimentInitArgs_Activation activation, int inputCount, int outputCount)
        {
            //TODO: activation, inputCount, outputCount could all be extracted from the xml, if it's too painful to also remember those settings

            List <NeatGenome> retVal = null;

            using (XmlReader xr = XmlReader.Create(new MemoryStream(Encoding.Unicode.GetBytes(xml))))
            {
                retVal = LoadPopulation_static(xr, activation, inputCount, outputCount);
            }

            return(retVal);
        }
Exemplo n.º 8
0
        public static IBlackBox GetBlackBox(NeatGenome genome, ExperimentInitArgs_Activation activation, HyperNEAT_Args hyperneatArgs = null)
        {
            IGenomeDecoder <NeatGenome, IBlackBox> decoder = null;

            if (hyperneatArgs == null)
            {
                decoder = CreateGenomeDecoder(activation);
            }
            else
            {
                decoder = CreateGenomeDecoder(activation, hyperneatArgs);
            }

            return(decoder.Decode(genome));
        }
Exemplo n.º 9
0
        //TODO: In more complete evaluators, take in an arena manager that lets you check out a room.  That will return the bot/brain that was
        //created for that room (request a room each time StartNewEvaluation is called, or if no rooms available at that moment, each tick until
        //a room is free - then start evaluating from that moment)
        public Evaluator1_FAIL(Bot bot, BrainNEAT brainPart, SensorHoming[] homingParts, Point3D homePoint, ExperimentInitArgs_Activation activation, HyperNEAT_Args hyperneatArgs = null)
        {
            _bot         = bot;
            _brainPart   = brainPart;
            _homingParts = homingParts;

            _homePoint = homePoint;

            _activation    = activation;
            _hyperneatArgs = hyperneatArgs;

            foreach (SensorHoming homingPart in homingParts)
            {
                homingPart.HomePoint  = homePoint;
                homingPart.HomeRadius = _maxDistance * 1.25;
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// This replaces the internal neural net with a new one.  If the part is created with dna that has an internal NN, then there is
        /// no need to call this method
        /// </summary>
        /// <remarks>
        /// TODO: For hyperneat, see if genome is CPPN (it should be).  Then is activation cppn or final?
        /// </remarks>
        /// <param name="phenome">
        /// This is the actual neural net
        /// NOTE: If this is hyperneat, the phenome is still the final neural net, not the cppn
        /// </param>
        public void SetPhenome(IBlackBox phenome, NeatGenome genome, ExperimentInitArgs_Activation activation, HyperNEAT_Args hyperneatArgs = null)
        {
            if (phenome.InputCount != _neuronsInput.Length || phenome.OutputCount != _neuronsOutput.Length)
            {
                // Without this constraint, it would be difficult to map between external and phenome, because it can't be known
                // what the phenome's intended neuron positions would be.  It's expected that during training, a candidate phenome
                // will be placed into a BrainNEAT, then the bot will be tested and scored.  So that during training there is always a
                // 1:1 between external and phenome.  It's only future generations that mutate where a fuzzy mapping needs to be
                // done
                throw new ArgumentException(string.Format("The phenome passed in must have the same number of inputs and outputs as this wrapper brain's external inputs and outputs. Phenome ({0}, {1}), External ({2}, {3})", phenome.InputCount, phenome.OutputCount, _neuronsInput.Length, _neuronsOutput.Length));
            }

            _brain         = phenome;
            _genome        = genome;
            _activation    = activation;
            _hyperneatArgs = hyperneatArgs;

            _neatPositions_Input = _neuronsInput.
                                   Select(o => o.Position).
                                   ToArray();

            _neatPositions_Output = _neuronsOutput.
                                    Select(o => o.Position).
                                    ToArray();

            // It's a 1:1 mapping between external and internal
            _inputsMap = Enumerable.Range(0, _neuronsInput.Length).
                         Select(o => new NeuronMapping()
            {
                Index_External = o,
                Index_NEAT     = o,
                Weight         = 1d,
            }).
                         ToArray();

            _outputsMap = Enumerable.Range(0, _neuronsOutput.Length).
                          Select(o => new NeuronMapping()
            {
                Index_External = o,
                Index_NEAT     = o,
                Weight         = 1d,
            }).
                          ToArray();
        }
Exemplo n.º 11
0
        private void BuildNEATBrain(BrainNEATDNA dna)
        {
            var nn = DeserializeBrain(dna);

            if (nn == null)
            {
                return;
            }

            _inputsMap  = MapNeurons(_neuronsInput.Select(o => o.Position).ToArray(), dna.NEATPositions_Input);
            _outputsMap = MapNeurons(_neuronsOutput.Select(o => o.Position).ToArray(), dna.NEATPositions_Output);

            _neatPositions_Input  = dna.NEATPositions_Input;
            _neatPositions_Output = dna.NEATPositions_Output;

            _activation    = dna.Activation;
            _hyperneatArgs = dna.Hyper;

            _genome = nn.Value.genome;
            _brain  = nn.Value.phenome;
        }
Exemplo n.º 12
0
        private static List <NeatGenome> LoadPopulation_static(XmlReader xr, ExperimentInitArgs_Activation activation, HyperNEAT_Args hyperneatArgs)
        {
            NeatGenomeFactory genomeFactory = (NeatGenomeFactory)CreateGenomeFactory(hyperneatArgs, activation);

            return(NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, genomeFactory));
        }
Exemplo n.º 13
0
        private static List <NeatGenome> LoadPopulation_static(XmlReader xr, ExperimentInitArgs_Activation activation, int inputCount, int outputCount)
        {
            NeatGenomeFactory genomeFactory = (NeatGenomeFactory)CreateGenomeFactory(inputCount, outputCount, activation);

            return(NeatGenomeXmlIO.ReadCompleteGenomeList(xr, false, genomeFactory));
        }
Exemplo n.º 14
0
 public static IGenomeFactory <NeatGenome> CreateGenomeFactory(int inputCount, int outputCount, ExperimentInitArgs_Activation activation)
 {
     return(new NeatGenomeFactory(inputCount, outputCount, GetNewNeatGenomeParameters(activation)));
 }
Exemplo n.º 15
0
 public static IGenomeDecoder <NeatGenome, IBlackBox> CreateGenomeDecoder(ExperimentInitArgs_Activation activation, HyperNEAT_Args args)
 {
     return(CreateGenomeDecoder_Finish(args, GetActivationScheme_CPPN(), GetActivationScheme(activation)));
 }
Exemplo n.º 16
0
 public static IGenomeDecoder <NeatGenome, IBlackBox> CreateGenomeDecoder(ExperimentInitArgs_Activation activation)
 {
     return(new NeatGenomeDecoder(GetActivationScheme(activation)));
 }
Exemplo n.º 17
0
        public static IGenomeFactory <NeatGenome> CreateGenomeFactory(HyperNEAT_Args args, ExperimentInitArgs_Activation activation)
        {
            // The cppn gets handed pairs of points, and there is an extra neuron for something.  See Substrate.CreateNetworkDefinition()
            // Adding 1 to the dimension because a pair of points needs an extra dimension to separate them (2 2D squares would have Z=-1 and 1)
            // Multiplying by 2 because a pair of points is loaded into the cppn at a time
            // Adding the final 1 to store the pair's connection length
            int inputCount = ((args.InputShapeDimensions + 1) * 2) + 1;

            int outputCount = args.OutputShapeDimensions;

            //NOTE: Can't use args.NeuronCount_Input and args.NeuronCount_Output.  This genome factory is for the CPPN which
            //uses the dimensions of the positions as input/output size
            return(new NeatGenomeFactory(inputCount, outputCount, DefaultActivationFunctionLibrary.CreateLibraryCppn(), GetNewNeatGenomeParameters(activation)));
        }