private void setupSubstrate() { if (isMulti) { substrate = new SkirmishSubstrate(25, 15, 25, HyperNEATParameters.substrateActivationFunction); network = substrate.generateMultiGenomeModulus(seedGenome.Decode(null), 5).Decode(null); } else { substrate = new SkirmishSubstrate(5, 3, 5, HyperNEATParameters.substrateActivationFunction); network = substrate.generateGenome(seedGenome.Decode(null)).Decode(null); } }
public void calcFitness(string genomeFile, int type) { XmlDocument doc = new XmlDocument(); doc.Load(genomeFile); NeatGenome genome = XmlNeatGenomeReaderStatic.Read(doc); INetworkEvaluator eval; if (type == 0) { eval = new CTRNNNetworkEvaluator(4, 12, 12); } else if (type == 1) { eval = new SUPGNetworkEvaluator(4, 12, 12); } else { doClune = true; eval = new CluneNetworkEvaluator(20, 20, 20); } var tempNet = genome.Decode(null); MessageBox.Show(eval.threadSafeEvaluateNetwork(tempNet)[0].ToString()); }
public GenomeVisualizerForm(NeatGenome genome) { InitializeComponent(); updatePicture = true; _currentGenome = genome; _currentSelectedConnectionIndex = -1; ShowGenomeNetwork(genome); ShowGenomeConnections(genome); List <PointF> inputN = new List <PointF>(); List <PointF> outputN = new List <PointF>(); outputN = substrate.getNeuronGroupByType(1); inputN = substrate.getNeuronGroupByType(0); EvolvableSubstrate se = new EvolvableSubstrate(); hiddenNeurons = new List <PointF>(); connections = new ConnectionGeneList(); se.generateSubstrate(inputN, outputN, (INetwork)genome.Decode(null), HyperNEATParameters.initialDepth, (float)HyperNEATParameters.varianceThreshold, (float)HyperNEATParameters.bandingThreshold, (int)HyperNEATParameters.ESIterations, (float)HyperNEATParameters.divisionThreshold, HyperNEATParameters.maximumDepth, (uint)inputN.Count, (uint)outputN.Count, ref connections, ref hiddenNeurons); ShowHyperCubeSlide(genome); }
/// <summary> /// Constructor that manually generates a NN controller (used mostly for debugging). /// </summary> /// <param name="x">X coordinate of initial position.</param> /// <param name="y">Y coordinate of intial position.</param> /// <param name="numSensors">Number of sensor components. Each agent has one sensor composed of at least 3 components.</param> public NNControlledCreature(Texture2D bodyTexture, float x, float y, float headingInRadians, Simulator sim, bool drawSensorField_in, bool trackPlanting_in, int numSensors, bool freezeAfterPlanting_in) : base(bodyTexture, x, y, headingInRadians, sim, drawSensorField_in, trackPlanting_in, numSensors) { PlanterSubstrate substrate = new PlanterSubstrate(308, 4, 108, new BipolarSigmoid()); NeatGenome genome = substrate.generateGenome(); Controller = genome.Decode(ActivationFunctionFactory.GetActivationFunction("BipolarSigmoid")); freezeAfterPlanting = freezeAfterPlanting_in; frozen = false; }
private void ShowHyperCubeSlide(NeatGenome genome) { float x = (float)numericUpDownX.Value; float y = (float)numericUpDownY.Value; float starty = -1.0f; float startx; INetwork net = genome.Decode(null); float[] coordinates = new float[4]; coordinates[0] = x; coordinates[1] = y; double output; if (pictureBox1 != null) { return; } Graphics g = pictureBox1.CreateGraphics(); while (starty < 1.0f) { startx = -1.0f; coordinates[3] = starty; while (startx < 1.0f) { coordinates[2] = startx; net.ClearSignals(); net.SetInputSignals(coordinates); net.MultipleSteps(3); output = net.GetOutputSignal(0); //HyberCubeSlidePanel. if (output < 0.0f) { brush.Color = Color.FromArgb((int)(output * -255.0f), 0, 0); } else { brush.Color = Color.FromArgb(0, 0, (int)(output * 255.0f)); } g.FillRectangle(brush, new Rectangle((int)(startx * 100.0f) + 100, 100 - (int)(starty * 100.0f), 1, 1)); //Show origin startx += 0.01f; } starty += 0.01f; } brush.Color = Color.Green; g.FillEllipse(brush, new Rectangle((int)(x * 100.0f) + 100, 100 - (int)(y * 100.0f), 5, 5)); }
/// <summary> /// If using NEAT, this function simply sets the AgentBrain genome variable as the brain. Otherwise, the genome is actually used as a genome and is decoded into the appropriate brain structure. /// </summary> private void createBrains() { if (Genome != null) { if (NeatBrain) { Brain = Genome; } else if (Homogeneous) { ANN = SubstrateDescription.generateHomogeneousGenome(Genome, NormalizeANNWeights, this.AdaptableANN, this.ModulatoryANN, EvolveSubstrate); Brains = new List <INetwork>(); for (int i = 0; i < NumRobots; i++) { INetwork b = ANN.Decode(null); Brains.Add(b); } } else { if (MultipleBrains) { List <NeatGenome> genes = SubstrateDescription.generateGenomeStackSituationalPolicy(Genome, Convert.ToUInt32(NumRobots), NormalizeANNWeights, AdaptableANN, ModulatoryANN, 2, out ZCoordinates); for (int j = 0; j < genes.Count; j++) { MultiBrains.Add(genes[j].Decode(null)); } Brain = MultiBrains[0]; } else if (Hive) { ANN = SubstrateDescription.generateHiveBrainGenomeStack(Genome, Convert.ToUInt32(NumRobots), NormalizeANNWeights, AdaptableANN, ModulatoryANN, out ZCoordinates, EvolveSubstrate, UseCTRNNs); Brain = UseCTRNNs ? ANN.DecodeToCTRNN() : ANN.Decode(null); } else { ANN = SubstrateDescription.generateMultiGenomeStack(Genome, Convert.ToUInt32(NumRobots), NormalizeANNWeights, AdaptableANN, ModulatoryANN, out ZCoordinates, EvolveSubstrate); Brain = ANN.Decode(null); } } } }
public double EvaluateNetwork(INetwork cppn) { lock (locker) { NeatGenome tempGenome = m_substrate.GenerateGenome(cppn); INetwork tempSubsNet = tempGenome.Decode(null); double fitness = 0.0; Program.TheWorldSimulator.NetworksToEvaluate[m_agentId] = tempSubsNet; Program.TheWorldSimulator.EventsNetworkReady[m_agentId].Set(); Program.TheWorldSimulator.EventsFitnessReady[m_agentId].WaitOne(); fitness = Program.TheWorldSimulator.Fitness; //if (!SkirmishExperiment.multiple) // fitness += doEvaluation(tempNet); //else // fitness += doEvaluationMulti(tempNet); return(fitness); } }
private void createBrains() { if (genome != null) { if (homogenous) { ANN = substrateDescription.generateHomogeneousGenome(genome, normalizeANNWeights, this.adaptableANN, this.modulatoryANN, evolveSubstrate); brains = new List <INetwork>(); for (int i = 0; i < numRobots; i++) { INetwork b = ANN.Decode(null); brains.Add(b); } } else { if (multipleBrains) //Multiple brains with situational policies { List <NeatGenome> genes = substrateDescription.generateGenomeStackSituationalPolicy(genome, Convert.ToUInt32(numRobots), normalizeANNWeights, adaptableANN, modulatoryANN, 2, out zcoordinates); for (int j = 0; j < genes.Count; j++) { multiBrains.Add(genes[j].Decode(null)); } brain = multiBrains[0]; } else { ANN = substrateDescription.generateMultiGenomeStack(genome, Convert.ToUInt32(numRobots), normalizeANNWeights, adaptableANN, modulatoryANN, out zcoordinates, evolveSubstrate); brain = ANN.Decode(null); } } } }
private void createBrains() { if (genome != null) { //Schrum: debugging //Console.WriteLine("genome != null"); if (homogenous) { //Schrum: debugging //Console.WriteLine("homogenous"); ANN = substrateDescription.generateHomogeneousGenome(genome, normalizeANNWeights, this.adaptableANN, this.modulatoryANN, evolveSubstrate); brains = new List <INetwork>(); for (int i = 0; i < numRobots; i++) { INetwork b = ANN.Decode(null); brains.Add(b); } } else { //Schrum: debugging //Console.WriteLine("!homogenous"); if (multipleBrains) //Multiple brains with situational policies { //Schrum: debugging //Console.WriteLine("multipleBrains"); // Schrum: The original code hard codes "2" as the nubmer of brains for any multi brain scenario TODO //List<NeatGenome> genes = substrateDescription.generateGenomeStackSituationalPolicy(genome, Convert.ToUInt32(numRobots), normalizeANNWeights, adaptableANN, modulatoryANN, 2, out zcoordinates); List <NeatGenome> genes = substrateDescription.generateGenomeStackSituationalPolicy(genome, Convert.ToUInt32(numRobots), normalizeANNWeights, adaptableANN, modulatoryANN, numBrains, out zcoordinates, forcedSituationalPolicyGeometry); // Schrum: Debugging module deletion /** * if(genes.Count == 0) * { * Console.WriteLine("InputNeuronCount :" + genome.InputNeuronCount); * Console.WriteLine("NumLinks :" + genome.NumLinks); * Console.WriteLine("NumOutputModules :" + genome.NumOutputModules); * Console.WriteLine("OutputNeuronCount:" + genome.OutputNeuronCount); * Console.WriteLine("OutputsPerPolicy :" + genome.OutputsPerPolicy); * Console.WriteLine("TotalNeuronCount :" + genome.TotalNeuronCount); * * throw new Exception("How is genes.Count 0!"); * } **/ for (int j = 0; j < genes.Count; j++) { multiBrains.Add(genes[j].Decode(null)); } // Schrum: for debugging /* * for (int j = 0; j < multiBrains.Count; j++) * { * if (multiBrains[j] == null) * { * Console.WriteLine(j +": Null brain!"); * } * else * { * Console.WriteLine(j + ":" + multiBrains[j]); * Console.WriteLine(j + ":CurrentOutputModule:" + multiBrains[j].CurrentOutputModule); * Console.WriteLine(j + ":InputNeuronCount:" + multiBrains[j].InputNeuronCount); * Console.WriteLine(j + ":OutputNeuronCount:" + multiBrains[j].OutputNeuronCount); * Console.WriteLine(j + ":OutputsPerPolicy:" + multiBrains[j].OutputsPerPolicy); * Console.WriteLine(j + ":TotalNeuronCount:" + multiBrains[j].TotalNeuronCount); * Console.WriteLine(j + ":NumOutputModules:" + multiBrains[j].NumOutputModules); * } * } */ brain = multiBrains[0]; } else { //Schrum: debugging //Console.WriteLine("!multipleBrains"); ANN = substrateDescription.generateMultiGenomeStack(genome, Convert.ToUInt32(numRobots), normalizeANNWeights, adaptableANN, modulatoryANN, out zcoordinates, evolveSubstrate); brain = ANN.Decode(null); } } } }
public void showMovie(string genomeFile, int type) { if (true) // set to false to use hardcoded output values from a file { XmlDocument doc = new XmlDocument(); doc.Load(genomeFile); NeatGenome genome = XmlNeatGenomeReaderStatic.Read(doc); INetwork tempNet = null; INetwork cppn = null; NeatGenome tempGenome = null; Substrate substrate; if (type == 0) { substrate = new CTRNNSubstrate(4, 12, 8, HyperNEATParameters.substrateActivationFunction); } else if (type == 1) { substrate = new SUPGSubstrate(4, 12, 12, HyperNEATParameters.substrateActivationFunction); } else { doClune = true; substrate = new CluneSubstrate(20, 20, 20, HyperNEATParameters.substrateActivationFunction); } cppn = genome.Decode(null); tempGenome = substrate.generateGenome(cppn); tempNet = tempGenome.Decode(null); Controller controller; if (type == 0) { controller = new Controller(tempNet); } else if (type == 1) { controller = new Controller(tempNet, true, tempGenome, cppn, ((SUPGSubstrate)substrate).getSUPGMap()); } else { controller = new Controller(tempNet); } using (var domain = new Domain()) { domain.Initialize(controller); domain.RunDraw(); } } else { using (var domain = new Domain()) { domain.Initialize(); domain.RunDraw(); } } }
private void ShowHyperCubeSlide(NeatGenome genome) { float posx = (float)numericUpDownX.Value; float posy = (float)numericUpDownY.Value; float x = (float)numericUpDownX.Value; float y = (float)numericUpDownY.Value; float starty = -1.0f; float startx; INetwork net = genome.Decode(null); float[] coordinates = new float[4]; coordinates[0] = x; coordinates[1] = y; double output; // if (pictureBox1 != null) return; Graphics g = pictureBox1.CreateGraphics(); while (starty < 1.0f) { startx = -1.0f; coordinates[3] = starty; while (startx < 1.0f) { coordinates[2] = startx; net.ClearSignals(); net.SetInputSignals(coordinates); ((ModularNetwork)net).RecursiveActivation(); output = net.GetOutputSignal(0); //HyberCubeSlidePanel. if (output < 0.0f) { brush.Color = Color.FromArgb((int)(output * -255.0f), 0, 0); } else { brush.Color = Color.FromArgb(0, 0, (int)(output * 255.0f)); } g.FillRectangle(brush, new Rectangle((int)(startx * 100.0f) + 100, 100 - (int)(starty * 100.0f), 1, 1)); //Show origin startx += 0.01f; } starty += 0.01f; } brush.Color = Color.Green; //g.FillEllipse(brush, new Rectangle((int)(x * 100.0f) +100, 100-(int)(y * 100.0f), 5, 5)); brush.Color = Color.White; float tolerance = (float)numericUpDownTolerance.Value; if (connections != null) { foreach (ConnectionGene cg in connections) { if (Math.Abs(cg.coordinates[0] - posx) < tolerance && (Math.Abs(cg.coordinates[1] - posy) < tolerance)) { g.FillEllipse(brush, new Rectangle((int)(cg.coordinates[2] * 100.0f) + 100, 100 - (int)(cg.coordinates[3] * 100.0f), 2, 2)); } } } // redrawSlide = false; g.DrawEllipse(blackPen, new Rectangle((int)((float)numericUpDownX.Value * 100.0f) + 100 - 4, 100 - (int)((float)numericUpDownY.Value * 100.0f) - 4, 8, 8));//new Rectangle((int)(mx-4), (int)(my-4), 8, 8)); brush.Color = Color.Green; g.FillEllipse(brush, new Rectangle((int)(x * 100.0f) + 100, 100 - (int)(y * 100.0f), 5, 5)); }
public FieldSubs3LQTable(RLClientBase client, int numTeammates, int myUnum) : base(client, numTeammates, myUnum, false) { if (Program.LoadingGenome) { try { var doc = new XmlDocument(); doc.Load(Program.LoadedGenomePath); NeatGenome readCPPN = XmlNeatGenomeReaderStatic.Read(doc); var substrate = new MultiLayerSandwichSubstrate(Rows, Cols + 2, NeatExpParams.SubstrateLayers, NeatExpParams.AddBiasToSubstrate, HyperNEATParameters.substrateActivationFunction); SharpNeatLib.NeatGenome.NeatGenome tempGenome = substrate.GenerateGenome(readCPPN.Decode(HyperNEATParameters.substrateActivationFunction)); m_loadedNetwork = tempGenome.Decode(HyperNEATParameters.substrateActivationFunction); m_loadingBehaviour = true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); m_loadingBehaviour = false; } } }