public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new KMeansClusteringStrategy <NeatGenome>(distanceMetric); IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create black box evaluator SimpleEvaluator evaluator = new SimpleEvaluator(_optimizer); IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); IGenomeListEvaluator <NeatGenome> innerEvaluator = new UnityParallelListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator, _optimizer); IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>(innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); //ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); //ea.Initialize(innerEvaluator, genomeFactory, genomeList);//this can be used if the currentGeneration does not need to be updated at the start of the training ea.Initialize(innerEvaluator, genomeFactory, genomeList, true); return(ea); }
/// <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; }
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); }
public void TestIsUserInExperimentReturnsFalseIfAnyAudienceInANDConditionDoesNotPass() { var experiment = Config.GetExperimentFromKey("audience_combinations_experiment"); var userAttributes = new UserAttributes { { "house", "Gryffindor" }, { "lasers", 50 } }; Assert.False(ExperimentUtils.IsUserInExperiment(Config, experiment, userAttributes, Logger)); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Evaluating audiences for experiment ""audience_combinations_experiment"": [""and"",[""or"",""3468206642"",""3988293898""],[""or"",""3988293899"",""3468206646"",""3468206647"",""3468206644"",""3468206643""]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206642"" with conditions: [""and"", [""or"", [""or"", {""name"": ""house"", ""type"": ""custom_attribute"", ""value"": ""Gryffindor""}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206642"" evaluated to TRUE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3988293899"" with conditions: [""and"",[""or"",[""or"",{""name"":""favorite_ice_cream"",""type"":""custom_attribute"",""match"":""exists""}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3988293899"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206646"" with conditions: [""and"",[""or"",[""or"",{""name"":""lasers"",""type"":""custom_attribute"",""match"":""exact"",""value"":45.5}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206646"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206647"" with conditions: [""and"",[""or"",[""or"",{""name"":""lasers"",""type"":""custom_attribute"",""match"":""gt"",""value"":70}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206647"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206644"" with conditions: [""and"",[""or"",[""or"",{""name"":""lasers"",""type"":""custom_attribute"",""match"":""lt"",""value"":1.0}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206644"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206643"" with conditions: [""and"",[""or"",[""or"",{""name"":""should_do_it"",""type"":""custom_attribute"",""match"":""exact"",""value"":true}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Audience condition {""type"":""custom_attribute"",""match"":""exact"",""name"":""should_do_it"",""value"":true} evaluated to UNKNOWN because no value was passed for user attribute ""should_do_it"""), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206643"" evaluated to UNKNOWN"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audiences for experiment ""audience_combinations_experiment"" collectively evaluated to FALSE"), Times.Once); }
/// <summary> /// Create and return a NeatEvolutionAlgorithm object ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// This overload accepts a pre-built genome population and their associated/parent genome factory. /// </summary> public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weight difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create IBlackBox evaluator. PreyCaptureEvaluator evaluator = new PreyCaptureEvaluator(_trialsPerEvaluation, _gridSize, _preyInitMoves, _preySpeed, _sensorRange, _maxTimesteps); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // TODO: evaluation scheme that re-evaluates existing genomes and takes average over time. // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator <NeatGenome> genomeListEvaluator = new ParallelGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator, _parallelOptions); // Initialize the evolution algorithm. ea.Initialize(genomeListEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
/// <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; }
/// <summary> /// Create and return a NeatEvolutionAlgorithm object ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// This overload accepts a pre-built genome2 population and their associated/parent genome2 factory. /// </summary> public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // Create a genome list evaluator. This packages up the genome decoder with the phenome evaluator. IGenomeListEvaluator <NeatGenome> genomeListEvaluator = new ParallelCoevolutionListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, PhenomeEvaluator); // Wrap a hall of fame evaluator around the baseline evaluator. genomeListEvaluator = new ParallelHallOfFameListEvaluator <NeatGenome, IBlackBox>(50, 0.5, ea, genomeListEvaluator, genomeDecoder, PhenomeEvaluator); // Initialize the evolution algorithm. ea.Initialize(genomeListEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
public void TestIsUserInExperimentReturnsFalseIfNoAudienceInORConditionPass() { var experiment = Config.GetExperimentFromKey("feat_with_var_test"); var userAttributes = new UserAttributes { { "house", "Ravenclaw" }, { "lasers", 50 }, { "should_do_it", false } }; Assert.False(ExperimentUtils.IsUserInExperiment(Config, experiment, userAttributes, Logger)); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Evaluating audiences for experiment ""feat_with_var_test"": [""3468206642"",""3988293898"",""3988293899"",""3468206646"",""3468206647"",""3468206644"",""3468206643""]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206642"" with conditions: [""and"", [""or"", [""or"", {""name"": ""house"", ""type"": ""custom_attribute"", ""value"": ""Gryffindor""}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206642"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3988293899"" with conditions: [""and"",[""or"",[""or"",{""name"":""favorite_ice_cream"",""type"":""custom_attribute"",""match"":""exists""}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3988293899"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206646"" with conditions: [""and"",[""or"",[""or"",{""name"":""lasers"",""type"":""custom_attribute"",""match"":""exact"",""value"":45.5}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206646"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206647"" with conditions: [""and"",[""or"",[""or"",{""name"":""lasers"",""type"":""custom_attribute"",""match"":""gt"",""value"":70}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206647"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206644"" with conditions: [""and"",[""or"",[""or"",{""name"":""lasers"",""type"":""custom_attribute"",""match"":""lt"",""value"":1.0}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206644"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Starting to evaluate audience ""3468206643"" with conditions: [""and"",[""or"",[""or"",{""name"":""should_do_it"",""type"":""custom_attribute"",""match"":""exact"",""value"":true}]]]"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audience ""3468206643"" evaluated to FALSE"), Times.Once); LoggerMock.Verify(l => l.Log(LogLevel.INFO, @"Audiences for experiment ""feat_with_var_test"" collectively evaluated to FALSE"), Times.Once); }
/// <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); }
public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new KMeansClusteringStrategy <NeatGenome>(distanceMetric); IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create black box evaluator AgarEvaluator evaluator = new AgarEvaluator(_optimizer); IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); IGenomeListEvaluator <NeatGenome> innerEvaluator = new UnitySingleGenomeEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator, _optimizer); IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>(innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); //ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); return(ea); }
/// <summary> /// Create and return a NeatEvolutionAlgorithm object ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// This overload accepts a pre-built genome population and their associated/parent genome factory. /// </summary> public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create IBlackBox evaluator. _evaluator = CreateEvaluator(); // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator <NeatGenome> innerEvaluator = new SerialGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, _evaluator); /*new ParallelGenomeListEvaluator<NeatGenome, IBlackBox>(genomeDecoder, _evaluator, _parallelOptions);*/ // Wrap the list evaluator in a 'selective' evaulator that will only evaluate new genomes. That is, we skip re-evaluating any genomes // that were in the population in previous generations (elite genomes). This is determined by examining each genome's evaluation info object. IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>( innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); // Initialize the evolution algorithm. ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
/// <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); }
public void TestDoesUserMeetAudienceConditionsAudienceNoMatch() { var userAttributes = new UserAttributes { { "device_type", "Android" }, { "location", "San Francisco" } }; Assert.IsFalse(ExperimentUtils.DoesUserMeetAudienceConditions(Config, Config.GetExperimentFromKey("test_experiment"), null, "experiment", "test_experiment", Logger).ResultObject); }
public void TestUserInExperimentAudienceMatch() { var userAttributes = new UserAttributes { { "device_type", "iPhone" }, { "location", "San Francisco" } }; Assert.IsTrue(ExperimentUtils.DoesUserMeetAudienceConditions(Config, Config.GetExperimentFromKey("test_experiment"), userAttributes, "experiment", "test_experiment", Logger).ResultObject); }
public void TestIsUserInExperimentAudienceNoMatch() { var userAttributes = new UserAttributes { { "device_type", "Android" }, { "location", "San Francisco" } }; Assert.IsFalse(ExperimentUtils.IsUserInExperiment(Config, Config.GetExperimentFromKey("test_experiment"), null)); }
public void TestUserInExperimentAudienceMatch() { var userAttributes = new UserAttributes { { "device_type", "iPhone" }, { "location", "San Francisco" } }; Assert.IsTrue(ExperimentUtils.IsUserInExperiment(Config, Config.GetExperimentFromKey("test_experiment"), userAttributes)); }
/// <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)); } }
/// <summary> /// Create and return a NeatEvolutionAlgorithm list ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// </summary> public ModuleNeatEvolutionAlgorithm <NeatGenome>[] CreateEvolutionAlgorithms(int populationSize) { // Create the modules. List <Module> modules = new List <Module>(); for (int i = 0; i < _moduleCount; i++) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetricPitch = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategyPitch = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetricPitch, _parallelOptions); IDistanceMetric distanceMetricRhythm = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategyRhythm = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetricRhythm, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationPitch = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); IComplexityRegulationStrategy complexityRegulationRhythm = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create and add a new module with strategies and the evolution parameters. Module module = new Module((i + 1), _eaParams, speciationStrategyPitch, speciationStrategyRhythm, complexityRegulationPitch, complexityRegulationRhythm); modules.Add(module); } // Hook-up the modules with each other in circular order. // TODO Right now, they are hooked-up in circular order. Check whether it should be done otherwise. //for (int i = 0; i < modules.Count; i++) //{ // modules[i].SetParasiteModule(i != modules.Count - 1 ? modules[i + 1] : modules[0], _parasiteCount, // _championCount, CreateGenomeDecoder()); //} foreach (var module in modules) { module.SetParasiteModules(modules.Except(new List <Module>() { module }).ToList(), _parasiteCount, _championCount, CreateGenomeDecoder(), CreateGenomeDecoder()); } // Initialize each module. foreach (var module in modules) { var rhythmFactory = CreateGenomeFactory(); var pitchFactory = CreateGenomeFactory(); module.Initialize(rhythmFactory, pitchFactory, populationSize); } // Finished. Return the evolution algorithms return (modules.Select(m => m.RhythmEvolutionAlgorithm).Concat(modules.Select(m => m.PitchEvolutionAlgorithm)).ToArray()); }
public void TestDoesUserMeetAudienceConditionsReturnsTrueIfAllAudiencesInANDConditionPass() { var experiment = Config.GetExperimentFromKey("audience_combinations_experiment"); var userAttributes = new UserAttributes { { "house", "Gryffindor" }, { "favorite_ice_cream", "walls" } }; Assert.True(ExperimentUtils.DoesUserMeetAudienceConditions(Config, experiment, userAttributes, "experiment", experiment.Key, Logger).ResultObject); }
public void TestDoesUserMeetAudienceConditionsReturnsTrueWithNoAudience() { var experiment = Config.GetExperimentFromKey("feat_with_var_test"); experiment.AudienceIds = new string[] { }; experiment.AudienceConditions = null; Assert.True(ExperimentUtils.DoesUserMeetAudienceConditions(Config, experiment, null, "experiment", experiment.Key, Logger).ResultObject); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Evaluating audiences for experiment ""feat_with_var_test"": []."), Times.Once); }
public void TestIsUserInExperimentReturnsTrueWithNoAudience() { var experiment = Config.GetExperimentFromKey("feat_with_var_test"); experiment.AudienceIds = new string[] { }; experiment.AudienceConditions = null; Assert.True(ExperimentUtils.IsUserInExperiment(Config, experiment, null, Logger)); LoggerMock.Verify(l => l.Log(LogLevel.DEBUG, @"Evaluating audiences for experiment ""feat_with_var_test"": []"), Times.Once); }
public void TestIsUserInExperimentReturnsTrueIfAllAudiencesInANDConditionPass() { var experiment = Config.GetExperimentFromKey("audience_combinations_experiment"); var userAttributes = new UserAttributes { { "house", "Gryffindor" }, { "favorite_ice_cream", "walls" } }; Assert.True(ExperimentUtils.IsUserInExperiment(Config, experiment, userAttributes, Logger)); }
public void TestIsUserInExperimentReturnsFalseIfAudienceInNOTConditionGetsPassed() { var experiment = Config.GetExperimentFromKey("feat_with_var_test"); experiment.AudienceIds = new string[] { "3468206645" }; var userAttributes = new UserAttributes { { "browser_type", "Chrome" } }; Assert.False(ExperimentUtils.IsUserInExperiment(Config, experiment, userAttributes, Logger)); }
private NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm_private(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList, HyperNEAT_Args args = null) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1, 0, 10); ISpeciationStrategy <NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> retVal = new NeatEvolutionAlgorithm <NeatGenome>(NeatEvolutionAlgorithmParameters, speciationStrategy, complexityRegulationStrategy); // Genome Decoder IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = null; if (args == null) { genomeDecoder = CreateGenomeDecoder(); } else { genomeDecoder = CreateGenomeDecoder(args); } // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator <NeatGenome> genomeEvaluator = null; if (_phenomeEvaluator != null) { IGenomeListEvaluator <NeatGenome> innerEvaluator = new ParallelGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, _phenomeEvaluator, _parallelOptions); // Wrap the list evaluator in a 'selective' evaluator that will only evaluate new genomes. That is, we skip re-evaluating any genomes // that were in the population in previous generations (elite genomes). This is determined by examining each genome's evaluation info object. genomeEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>( innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); } else if (_phenomeEvaluators != null) { // Use the multi tick evaluator genomeEvaluator = new TickGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, _phenomeEvaluators, _phenometickeval_roundRobinManager, _phenometickeval_worldTick); } else { throw new ApplicationException("One of the phenome evaluators needs to be populated"); } // Initialize the evolution algorithm. retVal.Initialize(genomeEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(retVal); }
public void TestDoesUserMeetAudienceConditionsReturnsTrueIfAudienceInNOTConditionDoesNotPass() { var experiment = Config.GetExperimentFromKey("feat_with_var_test"); experiment.AudienceIds = new string[] { "3468206645" }; var userAttributes = new UserAttributes { { "browser_type", "Safari" } }; Assert.True(ExperimentUtils.DoesUserMeetAudienceConditions(Config, experiment, userAttributes, "experiment", experiment.Key, Logger)); }
public void TestDoesUserMeetAudienceConditionsReturnsFalseIfAudienceInNOTConditionGetsPassed() { var experiment = Config.GetExperimentFromKey("feat_with_var_test"); experiment.AudienceIds = new string[] { "3468206645" }; var userAttributes = new UserAttributes { { "browser_type", "Chrome" } }; Assert.False(ExperimentUtils.DoesUserMeetAudienceConditions(Config, experiment, userAttributes, "experiment", experiment.Key, Logger).ResultObject); }
/// <summary> /// Create and return a NeatEvolutionAlgorithm object ready for running the NEAT algorithm/search. Various sub-parts /// of the algorithm are also constructed and connected up. /// This overload accepts a pre-built genome population and their associated/parent genome factory. /// </summary> public NeatEvolutionAlgorithm <NeatGenome> CreateEvolutionAlgorithm(IGenomeFactory <NeatGenome> genomeFactory, List <NeatGenome> genomeList) { // Create distance metric. Mismatched genes have a fixed distance of 10; for matched genes the distance is their weigth difference. IDistanceMetric distanceMetric = new ManhattanDistanceMetric(1.0, 0.0, 10.0); ISpeciationStrategy <NeatGenome> speciationStrategy = new ParallelKMeansClusteringStrategy <NeatGenome>(distanceMetric, _parallelOptions); // Create complexity regulation strategy. IComplexityRegulationStrategy complexityRegulationStrategy = ExperimentUtils.CreateComplexityRegulationStrategy(_complexityRegulationStr, _complexityThreshold); // Create the evolution algorithm. NeatEvolutionAlgorithm <NeatGenome> ea = new NeatEvolutionAlgorithm <NeatGenome>(_eaParams, speciationStrategy, complexityRegulationStrategy); // Create IBlackBox evaluator. DoublePoleBalancingEvaluator evaluator; switch (_variantStr) { case "DoublePole": evaluator = new DoublePoleBalancingEvaluator(); break; case "DoublePoleNv": evaluator = new DoublePoleBalancingEvaluatorNv(); break; case "DoublePoleNvAntiWiggle": evaluator = new DoublePoleBalancingEvaluatorNvAntiWiggle(); break; default: throw new SharpNeatException(string.Format("DoublePoleBalancing experiment config XML specifies unknown variant [{0}]", _variantStr)); } // Create genome decoder. IGenomeDecoder <NeatGenome, IBlackBox> genomeDecoder = CreateGenomeDecoder(); // Create a genome list evaluator. This packages up the genome decoder with the genome evaluator. IGenomeListEvaluator <NeatGenome> innerEvaluator = new ParallelGenomeListEvaluator <NeatGenome, IBlackBox>(genomeDecoder, evaluator, _parallelOptions); // Wrap the list evaluator in a 'selective' evaulator that will only evaluate new genomes. That is, we skip re-evaluating any genomes // that were in the population in previous generations (elite genomes). This is determiend by examining each genome's evaluation info object. IGenomeListEvaluator <NeatGenome> selectiveEvaluator = new SelectiveGenomeListEvaluator <NeatGenome>( innerEvaluator, SelectiveGenomeListEvaluator <NeatGenome> .CreatePredicate_OnceOnly()); // Initialize the evolution algorithm. ea.Initialize(selectiveEvaluator, genomeFactory, genomeList); // Finished. Return the evolution algorithm return(ea); }
/// <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; // } //} }
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; }
/// <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(); }