/// <summary>
        /// Initialize the experiment with some optional XML configuration data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams                              = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount                  = _specieCount;
            _eaParams.SelectionProportion          = 0.5;
            _eaParams.ElitismProportion            = 0.5;
            _eaParams.OffspringAsexualProportion   = 0.95;
            _eaParams.OffspringSexualProportion    = 0.05;
            _eaParams.InterspeciesMatingProportion = 0.00;

            _neatGenomeParams = new NeatGenomeParameters();
            _neatGenomeParams.AddConnectionMutationProbability    = 0.1;
            _neatGenomeParams.AddNodeMutationProbability          = 0.01;
            _neatGenomeParams.ConnectionWeightMutationProbability = 0.89;
            _neatGenomeParams.InitialInterconnectionsProportion   = 0.05;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize the experiment with some optional XML configuration data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");

            _trialsPerEvaluation = XmlUtils.GetValueAsInt(xmlConfig, "TrialsPerEvaluation");
            _gridSize            = XmlUtils.GetValueAsInt(xmlConfig, "GridSize");
            _preyInitMoves       = XmlUtils.GetValueAsInt(xmlConfig, "PreyInitMoves");
            _preySpeed           = XmlUtils.GetValueAsDouble(xmlConfig, "PreySpeed");
            _sensorRange         = XmlUtils.GetValueAsDouble(xmlConfig, "SensorRange");
            _maxTimesteps        = XmlUtils.GetValueAsInt(xmlConfig, "MaxTimesteps");
            _description         = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions     = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams                     = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount         = _specieCount;
            _eaParams.ElitismProportion   = 0.66;
            _eaParams.SelectionProportion = 0.66;

            _neatGenomeParams = new NeatGenomeParameters();
            _neatGenomeParams.ActivationFn = LeakyReLU.__DefaultInstance;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize the experiment with some optional XML configuration data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams             = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount = _specieCount;

            _neatGenomeParams = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;

            // Determine what function to regress.
            string     fnIdStr = XmlUtils.GetValueAsString(xmlConfig, "Function");
            FunctionId fnId    = (FunctionId)Enum.Parse(typeof(FunctionId), fnIdStr);

            _fn = FunctionUtils.GetFunction(fnId);

            // Read parameter sampling scheme settings.
            int    sampleResolution = XmlUtils.GetValueAsInt(xmlConfig, "SampleResolution");
            double sampleMin        = XmlUtils.GetValueAsDouble(xmlConfig, "SampleMin");
            double sampleMax        = XmlUtils.GetValueAsDouble(xmlConfig, "SampleMax");

            _paramSamplingInfo = new ParamSamplingInfo(sampleMin, sampleMax, sampleResolution);
        }
Exemplo n.º 4
0
        public virtual void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig,
                                                                    "DefaultComplexityRegulationStrategy");
            _complexityThreshold = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description         = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions     = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams                         = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount             = _specieCount;
            _neatGenomeParams                 = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;

            DefaultComplexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(
                _complexityRegulationStr,
                _complexityThreshold);
            DefaultSpeciationStrategy     = new KMeansClusteringStrategy <NeatGenome>(new ManhattanDistanceMetric(1.0, 0.0, 10.0));
            DefaultNeatEvolutionAlgorithm = new NeatEvolutionAlgorithm <NeatGenome>(
                NeatEvolutionAlgorithmParameters,
                DefaultSpeciationStrategy,
                DefaultComplexityRegulationStrategy);
        }
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                = name;
            _populationSize      = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount         = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme    = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityThreshold = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description         = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions     = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _guesses          = XmlUtils.GetValueAsInt(xmlConfig, "Guesses");
            Hashed            = XmlUtils.TryGetValueAsBool(xmlConfig, "Hashed").HasValue ? XmlUtils.GetValueAsBool(xmlConfig, "Hashed") : false;
            ValidationGuesses = XmlUtils.GetValueAsInt(xmlConfig, "ValidationGuesses");

            // Load the passwords from file
            string pwdfile = XmlUtils.TryGetValueAsString(xmlConfig, "ValidationPasswordFile");

            if (pwdfile != null)
            {
                Console.Write("Loading passwords from [{0}]...", pwdfile);
                if (_passwords == null || _passwords.Count == 0)
                {
                    int?pwLength = XmlUtils.TryGetValueAsInt(xmlConfig, "PasswordLength");
                    if (pwLength.HasValue)
                    {
                        Console.Write("Filtering to {0}-character passwords...", pwLength.Value);
                    }
                    _passwords = PasswordUtil.LoadPasswords(pwdfile, pwLength);
                }
                else
                {
                    Console.WriteLine("WARNING: Not loading passwords for experiment (already set)");
                }
            }
            else
            {
                Console.WriteLine("WARNING: Not loading passwords for experiment (not provided in config file)");
            }
            _eaParams                                          = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount                              = _specieCount;
            _neatGenomeParams                                  = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly                  = false;
            _neatGenomeParams.AddNodeMutationProbability       = 0.03;
            _neatGenomeParams.AddConnectionMutationProbability = 0.05;

            // TODO: Load states from XML config file
            // Generates all the valid states in the MC using all viable ASCII characters
            var stateList = new List <string>();

            for (uint i = 32; i < 127; i++)
            {
                stateList.Add(((char)i).ToString());
            }
            stateList.Add(null);
            _states = stateList.ToArray();
            _activationFnLibrary = MarkovActivationFunctionLibrary.CreateLibraryMc(_states);
        }
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams = new NeatEvolutionAlgorithmParameters();
            _eaParams.OffspringAsexualProportion = 1.0;
            _eaParams.OffspringSexualProportion  = 0.0;
            _eaParams.SpecieCount = _specieCount;
            _eaParams.InterspeciesMatingProportion = 0.0;

            _neatGenomeParams = new NeatGenomeParameters();

            if (name == "Small mutation")
            {
                // Small mutation parameters
                _neatGenomeParams.ConnectionWeightMutationProbability = 0.43;
                _neatGenomeParams.AddConnectionMutationProbability    = 0.25;
                _neatGenomeParams.AddNodeMutationProbability          = 1.0;
                _neatGenomeParams.DeleteConnectionMutationProbability = 0.003;
                _neatGenomeParams.NodeAuxStateMutationProbability     = 0.0;
                _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
                //_neatGenomeParams.ConnectionMutationInfoList.Add(new ConnectionMutationInfo(1, ConnectionPerturbanceType.JiggleGaussian, ConnectionSelectionType.Proportional, 0.15, 0, 0.0, 0.4));
            }

            if (name == "Big mutation")
            {
                // Big mutation parameters
                _neatGenomeParams.ConnectionWeightMutationProbability = 0.65;
                _neatGenomeParams.AddConnectionMutationProbability    = 0.48;
                _neatGenomeParams.AddNodeMutationProbability          = 1.0;
                _neatGenomeParams.DeleteConnectionMutationProbability = 0.003;
                _neatGenomeParams.NodeAuxStateMutationProbability     = 0.0;
                _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
                //_neatGenomeParams.ConnectionMutationInfoList.Add(new ConnectionMutationInfo(1, ConnectionPerturbanceType.JiggleGaussian, ConnectionSelectionType.Proportional, 0.9, 0, 0.0, 0.4));
            }

            if (name == "Novelty")
            {
                //Novelty parameters
                _neatGenomeParams.ConnectionWeightMutationProbability = 0.87;
                _neatGenomeParams.AddConnectionMutationProbability    = 0.67;
                _neatGenomeParams.AddNodeMutationProbability          = 1.0;
                _neatGenomeParams.DeleteConnectionMutationProbability = 0.003;
                _neatGenomeParams.NodeAuxStateMutationProbability     = 0.0;
                _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
                //_neatGenomeParams.ConnectionMutationInfoList.Add(new ConnectionMutationInfo(1, ConnectionPerturbanceType.JiggleGaussian, ConnectionSelectionType.Proportional, 0.9, 0, 0.0, 0.4));
            }
        }
        public override void Initialize(string name, XmlElement xmlConfig)
        {
            base.Initialize(name, xmlConfig);
            var substrateElements = xmlConfig.GetElementsByTagName("Substrate");

            if (substrateElements.Count != 1)
            {
                throw new ArgumentException("Must be only one substrate element in the xml.");
            }
            _substrate =
                ExperimentUtils.ReadSubstrateFromXml(xmlConfig.GetElementsByTagName("Substrate")[0] as XmlElement, xmlConfig.GetElementsByTagName("SubstrateSettings")[0] as XmlElement);
            _cppnActivationScheme = ExperimentUtils.CreateActivationScheme(xmlConfig, "CPPNActivation");
            _cppnInputLength      = XmlUtils.TryGetValueAsBool(xmlConfig, "CPPNDistanceInput") ?? false;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");

            //snake specific params
            _swparams = SnakeUtils.GetParamsFromXml(xmlConfig);

            _trialsPerEvaluation   = XmlUtils.TryGetValueAsInt(xmlConfig, "TrialsPerEvaluation") ?? _trialsPerEvaluation;
            _maxTicksWithoutEating = XmlUtils.TryGetValueAsInt(xmlConfig, "MaxTicksWithoutEating") ?? (_swparams.Height * _swparams.Width + _swparams.TicksBetweenFood);


            _inputMapperName  = XmlUtils.TryGetValueAsString(xmlConfig, "InputMapping") ?? _inputMapperName;
            _outputMapperName = XmlUtils.TryGetValueAsString(xmlConfig, "OutputMapping") ?? _outputMapperName;

            _description     = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams                         = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount             = _specieCount;
            _neatGenomeParams                 = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;

            //string nameoftype = (string ) typeof(GridInputMapper).GetProperty("Name", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(null, null);

            Type inputType = Assembly.GetAssembly(typeof(IInputMapper)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && (typeof(IInputMapper).IsAssignableFrom(myType)) &&
                                                                                         _inputMapperName == (string)myType.GetProperty("Name", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(null, null)).First();

            _inputMapper = (IInputMapper)Activator.CreateInstance(inputType, _swparams);

            Type outputType = Assembly.GetAssembly(typeof(IOutputMapper)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && (typeof(IOutputMapper).IsAssignableFrom(myType)) &&
                                                                                           _outputMapperName == (string)myType.GetProperty("Name", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy).GetValue(null, null)).First();

            _outputMapper = (IOutputMapper)Activator.CreateInstance(outputType);

            //foreach (Type type in
            //Assembly.GetAssembly(typeof(IInputMapper)).GetTypes().Where(myType => myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(IInputMapper) )))
            //{
            //    SnakeRunnerFactory srf = (SnakeRunnerFactory) Activator.CreateInstance(type, swOriginal);
            //    if (srf.Name == _ioLayers)
            //    {
            //        _srf = srf;
            //        break;
            //    }
            //}
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams             = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount = _specieCount;
            _neatGenomeParams     = new NeatGenomeParameters();
        }
Exemplo n.º 10
0
    public void Initialize(string name, XmlElement xmlConfig, int input, int output, int populationSize, int specieCount)
    {
        _name                    = name;
        _populationSize          = populationSize; //XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
        _specieCount             = specieCount;    //XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
        _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
        _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
        _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
        _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");

        _eaParams                         = new NeatEvolutionAlgorithmParameters();
        _eaParams.SpecieCount             = _specieCount;
        _neatGenomeParams                 = new NeatGenomeParameters();
        _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;

        _inputCount  = input;
        _outputCount = output;
    }
Exemplo n.º 11
0
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationSchemeCppn    = ExperimentUtils.CreateActivationScheme(xmlConfig, "ActivationCppn");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);
            _lengthCppnInput         = XmlUtils.GetValueAsBool(xmlConfig, "LengthCppnInput");

            _eaParams                         = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount             = _specieCount;
            _neatGenomeParams                 = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationSchemeCppn.AcyclicNetwork;
            _neatGenomeParams.InitialInterconnectionsProportion = 0.5;
        }
Exemplo n.º 12
0
        public void Initialize(string name, XmlElement xmlConfig)
        {
            // Read these from Domain XML file

            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationSchemeCppn    = ExperimentUtils.CreateActivationScheme(xmlConfig, "ActivationCppn");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);
            _parallelOptions.MaxDegreeOfParallelism = Environment.ProcessorCount / 2;


            _visualFieldResolution = XmlUtils.GetValueAsInt(xmlConfig, "Resolution");
            _visualFieldPixelCount = _visualFieldResolution * _visualFieldResolution;
            _lengthCppnInput       = XmlUtils.GetValueAsBool(xmlConfig, "LengthCppnInput");

            _eaParams             = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount = _specieCount;

            // Set these manually, use a high mutator just to test the water

            _neatGenomeParams = new NeatGenomeParameters()
            {
                AddConnectionMutationProbability    = 0.10,
                DeleteConnectionMutationProbability = 0.10,
                ConnectionWeightMutationProbability = 0.90,
                AddNodeMutationProbability          = 0.05,
                InitialInterconnectionsProportion   = 0.10
            };

            // Clear OUTPUT and FITNESS directories before starting
            var directory = new DirectoryInfo(Constants.OUTPUT_DIR);

            directory.Empty();
            directory = new DirectoryInfo(Constants.FITNESS_DIR);
            directory.Empty();
            directory = new DirectoryInfo(Constants.PLOTS_DIR);
            directory.Empty();
        }
Exemplo n.º 13
0
        public void Initialize(string name, XmlElement xmlConfig)
        {
            Name = name;
            DefaultPopulationSize    = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            Description      = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions = ExperimentUtils.ReadParallelOptions(xmlConfig);

            NeatEvolutionAlgorithmParameters = new NeatEvolutionAlgorithmParameters {
                SpecieCount = _specieCount
            };
            NeatGenomeParameters = new NeatGenomeParameters {
                FeedforwardOnly = _activationScheme.AcyclicNetwork
            };
//            var figterType = XmlUtils.TryGetValueAsString(xmlConfig, "Figter");
//            var type = Type.GetType(figterType);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);
            ExperimentUtils.ReadRbfAuxArgMutationConfig(xmlConfig, out _rbfMutationSigmaCenter, out _rbfMutationSigmaRadius);

            _eaParams                         = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount             = _specieCount;
            _neatGenomeParams                 = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
            _neatGenomeParams.ConnectionWeightMutationProbability = 0.788;
            _neatGenomeParams.AddConnectionMutationProbability    = 0.001;
            _neatGenomeParams.AddConnectionMutationProbability    = 0.01;
            _neatGenomeParams.NodeAuxStateMutationProbability     = 0.2;
            _neatGenomeParams.DeleteConnectionMutationProbability = 0.001;

            // Determine what function to regress.
            string     fnIdStr = XmlUtils.GetValueAsString(xmlConfig, "Function");
            FunctionId fnId    = (FunctionId)Enum.Parse(typeof(FunctionId), fnIdStr);

            _func = FunctionRegressionEvaluator.GetFunction(fnId);

            // Read parameter sampling scheme settings.
            int    sampleResolution = XmlUtils.GetValueAsInt(xmlConfig, "SampleResolution");
            double sampleMin        = XmlUtils.GetValueAsDouble(xmlConfig, "SampleMin");
            double sampleMax        = XmlUtils.GetValueAsDouble(xmlConfig, "SampleMax");

            int paramCount = _func.InputCount;

            _paramSamplingInfoArr = new ParameterSamplingInfo[paramCount];
            for (int i = 0; i < paramCount; i++)
            {
                _paramSamplingInfoArr[i] = new ParameterSamplingInfo(sampleMin, sampleMax, sampleResolution);
            }
        }
Exemplo n.º 15
0
 public void Initialize(string name, XmlElement xmlConfig, string givenUserName)
 {
     _name           = name;
     _populationSize = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
     ActiveUsersList <NeatGenome> .PopulationSize = _populationSize;
     _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
     _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
     _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
     _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
     _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
     ActiveUsersList <NeatGenome> .MaxNumberOfUsers =
         XmlUtils.GetValueAsInt(xmlConfig, "MaxSimultaneousUsers");
     ActiveUsersList <NeatGenome> .PortsPerUser =
         XmlUtils.GetValueAsInt(xmlConfig, "PortsPerUser");
     _parallelOptions      = ExperimentUtils.ReadParallelOptions(xmlConfig);
     _eaParams             = new NeatEvolutionAlgorithmParameters();
     _eaParams.SpecieCount = _specieCount;
     _neatGenomeParams     = new NeatGenomeParameters();
     System.Diagnostics.Debug.Assert(CheckActivationScheme(_activationScheme));
     userName = givenUserName;
 }
Exemplo n.º 16
0
        /// <summary>
        /// Initialize the experiment with some optional XML configuration data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            T GetValueAsEnum <T>(string e)
            {
                string r = XmlUtils.GetValueAsString(xmlConfig, e);

                return((T)System.Enum.Parse(typeof(T), r));
            }

            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");

            _numberOfGames = XmlUtils.GetValueAsInt(xmlConfig, "IPDGames");
            int seed    = XmlUtils.GetValueAsInt(xmlConfig, "RandomPlayerSeed");
            int randoms = XmlUtils.GetValueAsInt(xmlConfig, "RandomPlayerCount");

            string os = XmlUtils.TryGetValueAsString(xmlConfig, "StaticOpponents");

            _opponentPool = CreatePool(seed, randoms, (os == null) ? new Opponent[0] : System.Array.ConvertAll(os.Split(','), (string o) => { return((Opponent)System.Enum.Parse(typeof(Opponent), o, true)); }));

            _evaluationLimit = (ulong)XmlUtils.GetValueAsInt(xmlConfig, "EvaluationLimit");
            _evaluationMode  = GetValueAsEnum <EvaluationMode>("EvaluationMode");
            _noveltyMetric   = GetValueAsEnum <NoveltyMetric>("NoveltyMetric");
            _noveltyK        = XmlUtils.GetValueAsInt(xmlConfig, "NoveltyK");

            _randomRobustCheck = XmlUtils.GetValueAsInt(xmlConfig, "RandomRobustCheck");
            _pastInputReach    = XmlUtils.GetValueAsInt(xmlConfig, "PastInputReach");

            _description     = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams                         = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount             = _specieCount;
            _neatGenomeParams                 = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
        }
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);
            ExperimentUtils.ReadRbfAuxArgMutationConfig(xmlConfig, out _rbfMutationSigmaCenter, out _rbfMutationSigmaRadius);

            _eaParams             = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount = _specieCount;
            _neatGenomeParams     = new NeatGenomeParameters();
            _neatGenomeParams.ConnectionWeightMutationProbability = 0.788;
            _neatGenomeParams.AddConnectionMutationProbability    = 0.001;
            _neatGenomeParams.AddConnectionMutationProbability    = 0.01;
            _neatGenomeParams.NodeAuxStateMutationProbability     = 0.2;
            _neatGenomeParams.DeleteConnectionMutationProbability = 0.001;
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
        }
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name = name;
            var outputs = XmlUtils.TryGetValueAsInt(xmlConfig, "Outputs");

            _outputs                 = outputs.HasValue ? outputs.Value : 2;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _timeStepsPerGeneration  = (ulong)XmlUtils.GetValueAsInt(xmlConfig, "TimeStepsPerGeneration");


            _eaParams             = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount = _specieCount;
            _neatGenomeParams     = new NeatGenomeParameters()
            {
                ActivationFn = PlainSigmoid.__DefaultInstance,
                InitialInterconnectionsProportion = 1,
            };
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initialize the experiment with some optional XML configuration data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _parallelOptions         = ExperimentUtils.ReadParallelOptions(xmlConfig);

            _eaParams                         = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount             = _specieCount;
            _neatGenomeParams                 = new NeatGenomeParameters();
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
            //_neatGenomeParams.ActivationFn = BipolarSigmoid.__DefaultInstance;
            //_neatGenomeParams.ActivationFn = LeakyReLU.__DefaultInstance; //Muy buen desempeño
            //_neatGenomeParams.ActivationFn = Linear.__DefaultInstance; //Meeh
            //_neatGenomeParams.ActivationFn = LogisticFunction.__DefaultInstance; //Estancamiento
            //_neatGenomeParams.ActivationFn = PolynomialApproximantSteep.__DefaultInstance; //Buen desempeño, permite mas complejidad
            //_neatGenomeParams.ActivationFn = SReLU.__DefaultInstance; //No ha mucha mejora respecto a los anteriores
            _neatGenomeParams.ActivationFn = PureLinear.__DefaultInstance;
        }
 /// <summary>
 /// Initialize the experiment with some optional XML configuration data.
 /// </summary>
 public void Initialize(string name, XmlElement xmlConfig)
 {
     _name                             = name;
     _populationSize                   = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
     _specieCount                      = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
     _activationScheme                 = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
     _complexityRegulationStr          = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
     _complexityThreshold              = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
     _description                      = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
     _parallelOptions                  = ExperimentUtils.ReadParallelOptions(xmlConfig);
     _seed                             = XmlUtils.GetValueAsInt(xmlConfig, "Seed");
     _datasetPath                      = XmlUtils.TryGetValueAsString(xmlConfig, "DatasetPath");
     _normalizeData                    = XmlUtils.GetValueAsBool(xmlConfig, "NormalizeData");
     _normalizeRange                   = XmlUtils.GetValueAsInt(xmlConfig, "NormalizeRange");
     _dataLoader                       = new EasyChangeDataLoader();
     _eaParams                         = new NeatEvolutionAlgorithmParameters();
     _eaParams.SpecieCount             = _specieCount;
     _neatGenomeParams                 = new NeatGenomeParameters();
     _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;
     _neatGenomeParams.ActivationFn    = LeakyReLU.__DefaultInstance;
     _maxGen                           = XmlUtils.GetValueAsInt(xmlConfig, "MaxGen");
     _testPorcentage                   = (XmlUtils.GetValueAsInt(xmlConfig, "TestPorcentage") * 1.0) / 100;
     _savePeriod                       = XmlUtils.GetValueAsInt(xmlConfig, "SavePeriod");
 }
Exemplo n.º 21
0
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public void Initialize(string name, XmlElement xmlConfig)
        {
            _name                    = name;
            _populationSize          = XmlUtils.GetValueAsInt(xmlConfig, "PopulationSize");
            _specieCount             = XmlUtils.GetValueAsInt(xmlConfig, "SpecieCount");
            _activationScheme        = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            _complexityRegulationStr = XmlUtils.TryGetValueAsString(xmlConfig, "ComplexityRegulationStrategy");
            _complexityThreshold     = XmlUtils.TryGetValueAsInt(xmlConfig, "ComplexityThreshold");
            _description             = XmlUtils.TryGetValueAsString(xmlConfig, "Description");
            _timeStepsPerGeneration  = (ulong)XmlUtils.GetValueAsInt(xmlConfig, "TimeStepsPerGeneration");
            _stepReward              = XmlUtils.GetValueAsInt(xmlConfig, "StepReward");
            _agentType               = (AgentTypes)Enum.Parse(typeof(AgentTypes), XmlUtils.TryGetValueAsString(xmlConfig, "AgentType"));
            _plantLayout             = (PlantLayoutStrategies)Enum.Parse(typeof(PlantLayoutStrategies), XmlUtils.TryGetValueAsString(xmlConfig, "PlantLayout"));
            _paradigm                = (EvolutionParadigm)Enum.Parse(typeof(EvolutionParadigm), XmlUtils.TryGetValueAsString(xmlConfig, "EvolutionParadigm"));
            bool?diverse = XmlUtils.TryGetValueAsBool(xmlConfig, "LogDiversity");

            if (diverse.HasValue && diverse.Value)
            {
                _logDiversity = true;
            }
            if (_agentType == AgentTypes.Social)
            {
                var memSection = xmlConfig.GetElementsByTagName("Memory")[0] as XmlElement;
                _memory = (MemoryParadigm)Enum.Parse(typeof(MemoryParadigm), XmlUtils.TryGetValueAsString(memSection, "Paradigm"));
                SocialAgent.DEFAULT_MEMORY_SIZE = XmlUtils.GetValueAsInt(memSection, "Size");
                if (_memory == MemoryParadigm.IncrementalGrowth)
                {
                    _memGens       = XmlUtils.GetValueAsInt(memSection, "GrowthGenerations");
                    _maxMemorySize = XmlUtils.GetValueAsInt(memSection, "MaxSize");
                }
                _teaching = (TeachingParadigm)Enum.Parse(typeof(TeachingParadigm), XmlUtils.TryGetValueAsString(xmlConfig, "TeachingParadigm"));
            }
            var species = new List <PlantSpecies>();

            var plants = xmlConfig.GetElementsByTagName("Plant");

            for (int i = 0; i < plants.Count; i++)
            {
                var plant = plants[i] as XmlElement;
                species.Add(new PlantSpecies(i)
                {
                    Name   = XmlUtils.GetValueAsString(plant, "Name"),
                    Radius = XmlUtils.GetValueAsInt(plant, "Radius"),
                    Reward = XmlUtils.GetValueAsInt(plant, "Reward"),
                    Count  = XmlUtils.GetValueAsInt(plant, "Count")
                });
            }

            Random    random     = new Random();
            var       agents     = new List <ForagingAgent>();
            const int NUM_AGENTS = 10;

            for (int i = 0; i < NUM_AGENTS; i++)
            {
                agents.Add(new SpinningAgent(i)
                {
                    X = random.Next(500), Y = random.Next(500), Orientation = random.Next(360)
                });
            }

            List <Predator> predators = new List <Predator>();

            _predCount = XmlUtils.GetValueAsInt(xmlConfig, "Predators");
            var predStr = XmlUtils.TryGetValueAsString(xmlConfig, "PredatorDistribution");

            if (predStr != null)
            {
                PredatorDistribution = (PredatorDistributionTypes)Enum.Parse(typeof(PredatorDistributionTypes), predStr, true);
            }
            _predTypes = XmlUtils.GetValueAsInt(xmlConfig, "PredatorTypes");
            if (PredatorDistribution == PredatorDistributionTypes.Alternating)
            {
                _predGens = XmlUtils.GetValueAsDouble(xmlConfig, "PredatorGenerations");
            }
            _distinguishPreds = XmlUtils.GetValueAsBool(xmlConfig, "DistinguishPredators");

            _world = new World(agents, XmlUtils.GetValueAsInt(xmlConfig, "WorldHeight"), XmlUtils.GetValueAsInt(xmlConfig, "WorldHeight"), species, predators)
            {
                AgentHorizon        = XmlUtils.GetValueAsInt(xmlConfig, "AgentHorizon"),
                PlantLayoutStrategy = _plantLayout,
                StepReward          = _stepReward,
                PredatorTypes       = _predTypes
            };

            var outputs    = XmlUtils.TryGetValueAsInt(xmlConfig, "Outputs");
            var navigation = XmlUtils.TryGetValueAsBool(xmlConfig, "AgentsNavigate");
            var hiding     = XmlUtils.TryGetValueAsBool(xmlConfig, "AgentsHide");

            _navigationEnabled = navigation.HasValue ? navigation.Value : false;
            _hidingEnabled     = hiding.HasValue ? hiding.Value : false;
            if (!outputs.HasValue)
            {
                if (_navigationEnabled || _hidingEnabled)
                {
                    _outputs = (_navigationEnabled ? 2 : 0) + (_hidingEnabled ? _predTypes + 1 : 0);
                }
                else
                {
                    _outputs = outputs.HasValue ? outputs.Value : 2;
                }
            }
            else
            {
                _outputs = outputs.Value;
            }
            var inputs = XmlUtils.TryGetValueAsInt(xmlConfig, "Inputs");

            _inputs = inputs.HasValue ? inputs.Value : _world.PlantTypes.Count() * World.SENSORS_PER_OBJECT_TYPE + (_distinguishPreds ? _predTypes : 1) * World.SENSORS_PER_OBJECT_TYPE + 1;

            _eaParams             = new NeatEvolutionAlgorithmParameters();
            _eaParams.SpecieCount = _specieCount;
            _neatGenomeParams     = new NeatGenomeParameters()
            {
                ActivationFn = PlainSigmoid.__DefaultInstance
            };
            if (_teaching != TeachingParadigm.EgalitarianEvolvedAcceptability)
            {
                _neatGenomeParams.InitialInterconnectionsProportion = 0.1;
            }
        }
Exemplo n.º 22
0
        /// <inheritdoc />
        /// <summary>
        ///     Initializes the MCC maze navigation experiment by reading in all of the configuration parameters and
        ///     setting up the bootstrapping/initialization algorithm.
        /// </summary>
        /// <param name="name">The name of the experiment.</param>
        /// <param name="xmlConfig">The reference to the XML configuration file.</param>
        /// <param name="population1EvolutionLogger">The navigator evolution data logger.</param>
        /// <param name="population1PopulationLogger">The navigator population logger.</param>
        /// <param name="population1GenomeLogger">The navigator genome logger.</param>
        /// <param name="population2EvolutionLogger">The maze evolution data logger.</param>
        /// <param name="population2PopulationLogger">The maze population logger.</param>
        /// <param name="population2GenomeLogger">The maze genome logger.</param>
        public virtual void Initialize(string name, XmlElement xmlConfig,
                                       IDataLogger population1EvolutionLogger  = null, IDataLogger population1PopulationLogger = null,
                                       IDataLogger population1GenomeLogger     = null, IDataLogger population2EvolutionLogger  = null,
                                       IDataLogger population2PopulationLogger = null, IDataLogger population2GenomeLogger     = null)
        {
            // Set boiler plate properties
            Name             = name;
            Description      = XmlUtils.GetValueAsString(xmlConfig, "Description");
            ActivationScheme = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            ParallelOptions  = ExperimentUtils.ReadParallelOptions(xmlConfig);

            // Set the genome parameters
            NeatGenomeParameters = ExperimentUtils.ReadNeatGenomeParameters(xmlConfig);
            NeatGenomeParameters.FeedforwardOnly = ActivationScheme.AcyclicNetwork;
            MazeGenomeParameters = ExperimentUtils.ReadMazeGenomeParameters(xmlConfig);

            // Configure evolutionary algorithm parameters
            AgentDefaultPopulationSize      = XmlUtils.GetValueAsInt(xmlConfig, "AgentPopulationSize");
            MazeDefaultPopulationSize       = XmlUtils.GetValueAsInt(xmlConfig, "MazePopulationSize");
            AgentSeedGenomeCount            = XmlUtils.GetValueAsInt(xmlConfig, "AgentSeedGenomeCount");
            MazeSeedGenomeCount             = XmlUtils.GetValueAsInt(xmlConfig, "MazeSeedGenomeCount");
            AgentNumSpecies                 = XmlUtils.GetValueAsInt(xmlConfig, "AgentNumSpecies");
            MazeNumSpecies                  = XmlUtils.GetValueAsInt(xmlConfig, "MazeNumSpecies");
            BehaviorCharacterizationFactory = ExperimentUtils.ReadBehaviorCharacterizationFactory(xmlConfig,
                                                                                                  "BehaviorConfig");
            NavigatorBatchSize = XmlUtils.GetValueAsInt(xmlConfig, "NavigatorOffspringBatchSize");
            MazeBatchSize      = XmlUtils.GetValueAsInt(xmlConfig, "MazeOffspringBatchSize");

            // Set run-time bounding parameters
            MaxGenerations = XmlUtils.TryGetValueAsInt(xmlConfig, "MaxGenerations");
            MaxEvaluations = XmlUtils.TryGetValueAsULong(xmlConfig, "MaxEvaluations");

            // Set experiment-specific parameters
            MinSuccessDistance  = XmlUtils.GetValueAsInt(xmlConfig, "MinSuccessDistance");
            MazeHeight          = XmlUtils.GetValueAsInt(xmlConfig, "MazeHeight");
            MazeWidth           = XmlUtils.GetValueAsInt(xmlConfig, "MazeWidth");
            MazeQuadrantHeight  = XmlUtils.GetValueAsInt(xmlConfig, "MazeQuadrantHeight");
            MazeQuadrantWidth   = XmlUtils.GetValueAsInt(xmlConfig, "MazeQuadrantWidth");
            MazeScaleMultiplier = XmlUtils.GetValueAsInt(xmlConfig, "MazeScaleMultiplier");

            // Get success/failure criteria constraints
            NumMazeSuccessCriteria  = XmlUtils.GetValueAsInt(xmlConfig, "NumMazesSolvedCriteria");
            NumAgentSuccessCriteria = XmlUtils.GetValueAsInt(xmlConfig, "NumAgentsSolvedCriteria");
            NumAgentFailedCriteria  = XmlUtils.GetValueAsInt(xmlConfig, "NumAgentsFailedCriteria");

            // Read in the maximum number of initialization evaluations
            _maxInitializationEvaluations = XmlUtils.GetValueAsUInt(xmlConfig, "MaxInitializationEvaluations");

            // Initialize the initialization algorithm
            _mazeNavigationInitializer =
                ExperimentUtils.DetermineMCCInitializer(
                    xmlConfig.GetElementsByTagName("InitializationAlgorithmConfig", "")[0] as XmlElement);

            // Setup initialization algorithm
            _mazeNavigationInitializer.SetAlgorithmParameters(
                xmlConfig.GetElementsByTagName("InitializationAlgorithmConfig", "")[0] as XmlElement,
                ActivationScheme.AcyclicNetwork, NumAgentSuccessCriteria, 0);

            // Pass in maze experiment specific parameters
            // (note that a new maze structure is created here for the sole purpose of extracting the maze dimensions and calculating max distance to target)
            _mazeNavigationInitializer.SetEnvironmentParameters(MinSuccessDistance,
                                                                new MazeDecoder(MazeScaleMultiplier).Decode(
                                                                    new MazeGenomeFactory(MazeGenomeParameters, MazeHeight, MazeWidth, MazeQuadrantHeight,
                                                                                          MazeQuadrantWidth).CreateGenome(0)));

            // The size of the randomly generated agent genome pool from which to evolve agent bootstraps
            AgentInitializationGenomeCount = _mazeNavigationInitializer.PopulationSize;
        }
Exemplo n.º 23
0
        /// <summary>
        /// Initialize the experiment with some optional XML configutation data.
        /// </summary>
        public virtual void Initialize(string name, XmlElement xmlConfig)
        {
            _name             = name;
            _description      = XmlUtils.TryGetValueAsString(xmlConfig, "Description") ?? "";
            _comment          = XmlUtils.TryGetValueAsString(xmlConfig, "Comment") ?? "";
            _populationSize   = XmlUtils.TryGetValueAsInt(xmlConfig, "PopulationSize") ?? 100;
            _maxGenerations   = XmlUtils.TryGetValueAsInt(xmlConfig, "MaxGenerations") ?? 1000;
            _activationScheme = ExperimentUtils.CreateActivationScheme(xmlConfig, "Activation");
            SeedGenome        = XmlUtils.TryGetValueAsString(xmlConfig, "SeedGenome");
            try
            {
                _complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(xmlConfig, "ComplexityRegulation");
            }
            catch (ArgumentException e)
            {
                _logger.Warn(e.Message);
            }

            _parallelOptions = ExperimentUtils.ReadParallelOptions(xmlConfig);
            _multiThreading  = XmlUtils.TryGetValueAsBool(xmlConfig, "MultiThreading") ?? true;
            _logInterval     = XmlUtils.TryGetValueAsInt(xmlConfig, "LogInterval") ?? 10;

            // Evolutionary algorithm parameters
            _eaParams = new NeatEvolutionAlgorithmParameters();

            XmlElement xmlEAParams = xmlConfig.SelectSingleNode("EAParams") as XmlElement;

            if (xmlEAParams != null)
            {
                _eaParams.SpecieCount                  = XmlUtils.GetValueAsInt(xmlEAParams, "SpecieCount");
                _eaParams.ElitismProportion            = XmlUtils.GetValueAsDouble(xmlEAParams, "ElitismProportion");
                _eaParams.SelectionProportion          = XmlUtils.GetValueAsDouble(xmlEAParams, "SelectionProportion");
                _eaParams.OffspringAsexualProportion   = XmlUtils.GetValueAsDouble(xmlEAParams, "OffspringAsexualProportion");
                _eaParams.OffspringSexualProportion    = XmlUtils.GetValueAsDouble(xmlEAParams, "OffspringSexualProportion");
                _eaParams.InterspeciesMatingProportion = XmlUtils.GetValueAsDouble(xmlEAParams, "InterspeciesMatingProportion");
            }
            else
            {
                _logger.Info("EA parameters not found. Using default.");
            }

            // NEAT Genome parameters
            _neatGenomeParams = new NeatGenomeParameters();

            // Prevent recurrent connections if the activation scheme is acyclic
            _neatGenomeParams.FeedforwardOnly = _activationScheme.AcyclicNetwork;

            XmlElement xmlGenomeParams = xmlConfig.SelectSingleNode("GenomeParams") as XmlElement;

            if (xmlGenomeParams != null)
            {
                _neatGenomeParams.ConnectionWeightRange                    = XmlUtils.GetValueAsDouble(xmlGenomeParams, "ConnectionWeightRange");
                _neatGenomeParams.InitialInterconnectionsProportion        = XmlUtils.GetValueAsDouble(xmlGenomeParams, "InitialInterconnectionsProportion");
                _neatGenomeParams.DisjointExcessGenesRecombinedProbability = XmlUtils.GetValueAsDouble(xmlGenomeParams, "DisjointExcessGenesRecombinedProbability");
                _neatGenomeParams.ConnectionWeightMutationProbability      = XmlUtils.GetValueAsDouble(xmlGenomeParams, "ConnectionWeightMutationProbability");
                _neatGenomeParams.AddNodeMutationProbability               = XmlUtils.GetValueAsDouble(xmlGenomeParams, "AddNodeMutationProbability");
                _neatGenomeParams.AddConnectionMutationProbability         = XmlUtils.GetValueAsDouble(xmlGenomeParams, "AddConnectionMutationProbability");
                _neatGenomeParams.DeleteConnectionMutationProbability      = XmlUtils.GetValueAsDouble(xmlGenomeParams, "DeleteConnectionMutationProbability");
            }
            else
            {
                _logger.Info("Genome parameters not found. Using default.");
            }

            XmlElement xmlNoveltySearchParams = xmlConfig.SelectSingleNode("NoveltySearch") as XmlElement;

            if (xmlNoveltySearchParams != null)
            {
                _noveltySearchParams = NoveltySearchParameters.ReadXmlProperties(xmlNoveltySearchParams);
            }
            else
            {
                _logger.Info("Novelty search parameters not found");
            }

            XmlElement xmlMultiObjectiveParams = xmlConfig.SelectSingleNode("MultiObjective") as XmlElement;

            if (xmlMultiObjectiveParams != null)
            {
                _multiObjectiveParams = MultiObjectiveParameters.ReadXmlProperties(xmlMultiObjectiveParams);
            }
            else
            {
                _logger.Info("Multi objective parameters not found");
            }

            // Create IBlackBox evaluator.
            _evaluator = new TEvaluator();
            _evaluator.Initialize(xmlConfig);
            _evaluator.NoveltySearchParameters = _noveltySearchParams;
        }
Exemplo n.º 24
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            try
            {
                #region NNInit
                IDMotorExperiment _experiment = new IDMotorExperiment();
                xmlConfig = new XmlDocument();
                xmlConfig.Load("IDMotor.config.xml");
                _experiment.Initialize("IDMotor", xmlConfig.DocumentElement);
                _activationScheme = ExperimentUtils.CreateActivationScheme(xmlConfig.DocumentElement, "Activation");
                XmlReader         xr          = XmlReader.Create(genomeFile);
                List <NeatGenome> _genomeList = _experiment.LoadPopulation(xr);
                _genomeDecoder = new NeatGenomeDecoder(_activationScheme);
                neatGenome     = _genomeList[0];
                box            = _genomeDecoder.Decode(neatGenome);
                #endregion

                if (chkMotor.Checked)
                {
                    #region Encoder Init
                    digitalTask = new Task("digitalTask");

                    double zIndexValue = Convert.ToDouble(zIndexValueTextBox.Text);
                    int    pulsePerRev = Convert.ToInt32(pulsePerRevTextBox.Text);
                    zIndexEnable = zIndexEnabledCheckBox.Checked;

                    switch (decodingTypeComboBox.SelectedIndex)
                    {
                    case 0:     //X1
                        encoderType = CIEncoderDecodingType.X1;
                        break;

                    case 1:     //X2
                        encoderType = CIEncoderDecodingType.X2;
                        break;

                    case 2:     //X4
                        encoderType = CIEncoderDecodingType.X4;
                        break;
                    }

                    switch (zIndexPhaseComboBox.SelectedIndex)
                    {
                    case 0:     //A High B High
                        encoderPhase = CIEncoderZIndexPhase.AHighBHigh;
                        break;

                    case 1:     //A High B Low
                        encoderPhase = CIEncoderZIndexPhase.AHighBLow;
                        break;

                    case 2:     //A Low B High
                        encoderPhase = CIEncoderZIndexPhase.ALowBHigh;
                        break;

                    case 3:     //A Low B Low
                        encoderPhase = CIEncoderZIndexPhase.ALowBLow;
                        break;
                    }

                    digitalTask.CIChannels.CreateAngularEncoderChannel(counterComboBox.Text,
                                                                       "", encoderType, zIndexEnable, zIndexValue, encoderPhase, pulsePerRev,
                                                                       0.0, CIAngularEncoderUnits.Radians);

                    digitalTask.Control(TaskAction.Verify);

                    digitalReader = new CounterMultiChannelReader(digitalTask.Stream);
                    digitalTask.Start();

                    #endregion

                    #region Vout Init
                    waveTask = new Task("ControlVoltageTask");
                    waveTask.AOChannels.CreateVoltageChannel(physicalChannelComboBox.Text,
                                                             "",
                                                             Convert.ToDouble(minimumTextBox.Text),
                                                             Convert.ToDouble(maximumTextBox.Text),
                                                             AOVoltageUnits.Volts);

                    // verify the task before doing the waveform calculations
                    waveTask.Control(TaskAction.Verify);

                    writer = new AnalogSingleChannelWriter(waveTask.Stream);


                    waveTask.Start();

                    #endregion
                }
                box.ResetState();
                actualPos           = 0;
                n                   = 0;
                tmrRefresh.Enabled  = true;
                btnStart.Enabled    = false;
                btnStopDemo.Enabled = true;
                motorPos            = 0;
                ti                  = DateTime.Now;
                ta                  = ti;

                if (csFile != null && ControlSignal == null)
                {
                    ControlSignal = unpackControlSignal(csFile);
                }
                i = 0;

                if (!chckBoxWarmUp.Checked)
                {
                    csvWriter = new StreamWriter(dataFile);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 25
0
        public override void Create()
        {
            double[] currentDurationPhrase = MusicLibrary.CurrentSongDuration();
            int[]    currentPitchPhrase    = MusicLibrary.CurrentSongPitch();

            double[] rhythmInputs = MusicEnvironment.createDurationInputs(currentDurationPhrase);
            int[]    pitchInputs  = MusicEnvironment.createPitchInputs(currentPitchPhrase, currentDurationPhrase);

            string CHAMPION_FILE = @"..\..\..\NeatMusic\bin\Debug\host_parasite_champion.xml";

            List <NeatGenome> anns;

            XmlConfigurator.Configure(new System.IO.FileInfo("log4net.properties"));

            // Load config XML.
            XmlDocument xmlConfig = new XmlDocument();
            //load genomes
            // Save the best genome to file
            XmlReaderSettings xwSettings = new XmlReaderSettings();

            using (XmlReader xw = XmlReader.Create(CHAMPION_FILE, xwSettings))
            {
                anns = NeatGenomeXmlIO.ReadCompleteGenomeList(xw, false);
            }

            foreach (var neatGenome in anns)
            {
                Console.WriteLine("id_" + neatGenome.Id);
            }



            // Load config XML.
            XmlDocument xmlConfig1 = new XmlDocument();

            xmlConfig1.Load(@"..\..\..\NeatMusic\bin\Debug\config.xml");
            XmlElement xmlElement = xmlConfig1.DocumentElement;
            var        activation = ExperimentUtils.CreateActivationScheme(xmlElement, "Activation");

            IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = new NeatGenomeDecoder(activation);

            int MODULE_COUNT = anns.Count / 2;
            int LENGHT       = rhythmInputs.Length;
            int LENGTHPITCH  = currentPitchPhrase.Length;
            //int LENGTHPITCH = LENGHT;
            int SEED_PITCH = 0;

            var rhythmPlayers = new List <NeatPlayer>();
            var pitchPlayers  = new List <NeatPlayer>();

            for (int i = 0; i < MODULE_COUNT; i++)
            {
                rhythmPlayers.Add(new NeatPlayer(genomeDecoder.Decode(anns[i])));
            }
            for (int i = MODULE_COUNT; i < MODULE_COUNT * 2; i++)
            {
                pitchPlayers.Add(new NeatPlayer(genomeDecoder.Decode(anns[i])));
            }

            double[][] rhythmOutput = new double[MODULE_COUNT][];
            int[][]    pitchOutput  = new int[MODULE_COUNT][];


            for (int i = 0; i < MODULE_COUNT; i++)
            {
                rhythmOutput[i] = new double[LENGHT];
                pitchOutput[i]  = new int[LENGTHPITCH];
            }

            for (int i = 0; i < MODULE_COUNT; i++)
            {
                rhythmOutput[i] = new double[LENGHT];
                pitchOutput[i]  = new int[LENGHT];
            }

            for (int i = 0; i < LENGHT; i++)
            {
                for (int p = 0; p < MODULE_COUNT; p++)
                {
                    var brainInput = MusicEnvironment.getBrainInputDelayed(pitchOutput, pitchInputs, p, MODULE_COUNT, i);

                    pitchOutput[p][i] = MusicEnvironment.convertToMidiClass(pitchPlayers[p].calculateOutput(brainInput));
                }
            }

            for (int i = 0; i < LENGHT; i++)
            {
                for (int p = 0; p < MODULE_COUNT; p++)
                {
                    var brainInput = MusicEnvironment.getBrainInputDelayed(rhythmOutput, rhythmInputs, p, MODULE_COUNT, i);

                    rhythmOutput[p][i] = rhythmPlayers[p].calculateOutput(brainInput);
                }
            }


            printFitness(MODULE_COUNT, pitchPlayers, rhythmPlayers);

            //get standard deviation
            Console.WriteLine(@"Input deviation: {0}", SmoothedZSmoothening.StandardDeviation(rhythmInputs));

            for (int i = 0; i < rhythmOutput.Length; i++)
            {
                double standardDev = SmoothedZSmoothening.StandardDeviation(rhythmOutput[i]);

                Console.WriteLine(@"Module {0} deviation: {1}", i, standardDev);
            }

            //look at outputs and find out when there are new notes and what they are
            //new note when current value is higher than previous one

            List <double>[] durationsLists = new List <double> [MODULE_COUNT];
            List <int>[]    pitchLists     = new List <int> [MODULE_COUNT];

            for (int i = 0; i < MODULE_COUNT; i++)
            {
                durationsLists[i] = new List <double>();
                pitchLists[i]     = new List <int>();
                findNewNotesFromOutput(rhythmOutput[i], pitchOutput[i], LENGHT, out durationsLists[i], out pitchLists[i]);
                mergeRests(durationsLists[i], pitchLists[i]);
                printResults(durationsLists[i], pitchLists[i], i + 1);
            }

            Sequence seq = new Sequence();

            seq.Add(getTrack(currentPitchPhrase, currentDurationPhrase, 60));
            //save input phrase in separate file
            seq.Save("base.mid");

            for (int i = 0; i < MODULE_COUNT; i++)
            {
                //int offset = i%2 == 0 ? 60 + 12 * (i/2 + 1) : 48 - 12 * (i/2 + 1); //how should this be done?
                int offset = 48;

                Track t = getTrack(pitchLists[i].ToArray(), durationsLists[i].ToArray(), offset);

                Sequence singleTrack = new Sequence();
                singleTrack.Add(t);
                singleTrack.Save("track" + (i + 1) + ".mid");

                seq.Add(t);
            }

            seq.Save("test.mid");

            // Hit return to quit.
            Console.ReadLine();
        }