public TWEANNGenotype(TWEANN tweann) { numInputs = tweann.NumInputs(); numOutputs = tweann.NumOutputs(); archetypeIndex = tweann.ArchetypeIndex; ID = EvolutionaryHistory.NextGenotypeID(); Links = new List <LinkGene>(); Nodes = new List <NodeGene>(tweann.GetNodes().Count); List <TWEANNNode> tweannNodeList = tweann.GetNodes(); for (int i = 0; i < tweann.GetNodes().Count; i++) { NodeGene ng = new NodeGene(tweannNodeList[i].GetNType(), tweannNodeList[i].GetFType(), tweannNodeList[i].GetInnovation()); Nodes.Add(ng); List <LinkGene> tempLinks = new List <LinkGene>(); foreach (TWEANNLink l in tweannNodeList[i].GetOutputs()) { LinkGene lg = new LinkGene(tweannNodeList[i].GetInnovation(), l.GetTarget().GetInnovation(), l.GetWeight(), l.GetInnovation()); tempLinks.Add(lg); } for (int j = 0; j < tempLinks.Count; j++) { Links.Add(tempLinks[j]); } } }
private void LinkMutation(long sourceNodeInnovation, float weight) //HACK LinkMutation(long sourceNodeInnovation, float weight) - recurrent links are possible. We may disable this later. { string debugMsg = "LinkMutation on link with innovation " + sourceNodeInnovation + " using a weight of " + weight; if (ArtGallery.DEBUG_LEVEL > ArtGallery.DEBUG.NONE) { Debug.Log(debugMsg); } long targetNodeInnovation = GetRandomNodeInnovation(sourceNodeInnovation, false); NTYPE sourceNTYPE = GetNodeByInnovationID(sourceNodeInnovation).nTYPE; NTYPE targetNTYPE = GetNodeByInnovationID(targetNodeInnovation).nTYPE; if ( /* (sourceNTYPE == NTYPE.INPUT && targetNTYPE == NTYPE.INPUT) || // both inputs */ (sourceNTYPE == NTYPE.INPUT && targetNTYPE == NTYPE.HIDDEN) || // input -> hidden (sourceNTYPE == NTYPE.INPUT && targetNTYPE == NTYPE.OUTPUT) || // input -> output /* (sourceNTYPE == NTYPE.HIDDEN && targetNTYPE == NTYPE.HIDDEN) || // hidden -> hidden */ (sourceNTYPE == NTYPE.HIDDEN && targetNTYPE == NTYPE.OUTPUT)) // hidden -> output { long link = EvolutionaryHistory.NextInnovationID(); AddLink(sourceNodeInnovation, targetNodeInnovation, weight, link); } }
void Start() { EvolutionaryHistory.InitializeEvolutionaryHistory(); EvolutionaryHistory.archetypes[0] = new TWEANNGenotype(4, 3, 0).Nodes; textbox = GetComponent <OutputText>(); art = new Artwork(); ActivationFunctions.ActivateAllFunctions(); //ActivationFunctions.ActivateFunction(new List<FTYPE> { FTYPE.SAWTOOTH }); width = height = 256; renderer = GetComponent <Renderer>(); img = new Texture2D(width, height, TextureFormat.ARGB32, true); }
/// <summary> /// Constructor for the initial room. invoked once per game /// </summary> /// <param name="numArtworks"></param> public RoomConfiguration(int numArtworks) { ArtArchetypeIndex = EvolutionaryHistory.NextPopulationIndex(); EvolutionaryHistory.archetypes[ArtArchetypeIndex] = new TWEANNGenotype(4, 3, ArtArchetypeIndex).Nodes; parentRoom = null; rooms = new RoomConfiguration[numArtworks]; artworks = new Artwork[numArtworks]; sculptures = new Sculpture[4]; // HACK PROTOTYPE hardcoded var. fix later for (int i = 0; i < numArtworks; i++) { artworks[i] = new Artwork(ArtArchetypeIndex); } //SetSculptures HAS to be called right after this constructor is called and initialized to create the lobby! this will change later }
private void SpliceMutation(FTYPE fType) // TODO add a factor to change the weights impact (maybe a single factor or one for each weight) { LinkGene lg = GetLinkByInnovationID(GetRandomLinkInnovation()); long sourceInnovation = lg.GetSourceInnovation(); long targetInnovation = lg.GetTargetInnovation(); long newNode = EvolutionaryHistory.NextInnovationID(); float weight1 = RandomGenerator.NextGaussian(); float weight2 = RandomGenerator.NextGaussian(); long toLink = EvolutionaryHistory.NextInnovationID(); long fromLink = EvolutionaryHistory.NextInnovationID(); string debugMsg = "SpliceMutation between " + sourceInnovation + " and " + targetInnovation + ". Adding a node with an innovation of " + newNode + " and an activation function of " + fType; if (ArtGallery.DEBUG_LEVEL > ArtGallery.DEBUG.NONE) { Debug.Log(debugMsg); } SpliceNode(fType, newNode, sourceInnovation, targetInnovation, weight1, weight2, toLink, fromLink); }
void Start() { EvolutionaryHistory.InitializeEvolutionaryHistory(); EvolutionaryHistory.archetypes[0] = new TWEANNGenotype(4, 3, 0).Nodes; width = height = 64; //ActivationFunctions.ActivateAllFunctions(); collectedFunctions = new List <FTYPE> { FTYPE.ID, FTYPE.TANH, FTYPE.SQUAREWAVE, FTYPE.GAUSS, FTYPE.SINE }; activeFunctions = new List <FTYPE> { FTYPE.ID, FTYPE.GAUSS, FTYPE.SINE }; ActivationFunctions.ActivateFunction(activeFunctions); leftRenderer = leftQuad.GetComponent <Renderer>(); rightRenderer = rightQuad.GetComponent <Renderer>(); leftImg = new Texture2D(width, height, TextureFormat.ARGB32, true); rightImg = new Texture2D(width, height, TextureFormat.ARGB32, true); BuildArtworks(); }
public void SpliceNode(FTYPE fType, long newNodeInnovation, long sourceInnovation, long targetInnovation, float weight1, float weight2, long toLinkInnovation, long fromLinkInnovation) { NodeGene ng = new NodeGene(NTYPE.HIDDEN, fType, newNodeInnovation); LinkGene lg = GetLinkBetween(sourceInnovation, targetInnovation); //lg.SetActive(false); // TODO active bool is not in use // HACK Links should not be removed when splicing in a new node, but active is not in use yet //links.Remove(lg); // HACK if this fails then it will be because the index is either < 0 or > count - add fixes or write a container w/ helper methods Nodes.Insert(System.Math.Min(OutputStartIndex(), System.Math.Max(numInputs, IndexOfNodeInnovation(sourceInnovation) + 1)), ng); //int index = EvolutionaryHistory.IndexOfArchetypeInnovation(archetypeIndex, sourceInnovation); //int pos = System.Math.Min(EvolutionaryHistory.FirstArchetypeOutputIndex(archetypeIndex), System.Math.Max(numInputs, index + 1)); EvolutionaryHistory.AddArchetype(archetypeIndex, Nodes.IndexOf(ng), ng.Clone(), "origin"); LinkGene toNew = new LinkGene(sourceInnovation, newNodeInnovation, weight1, toLinkInnovation); LinkGene fromNew = new LinkGene(newNodeInnovation, targetInnovation, weight2, fromLinkInnovation); Links.Add(toNew); Links.Add(fromNew); }
public TWEANNGenotype(List <NodeGene> nodes, List <LinkGene> links, int archetypeIndex) { Nodes = nodes; Links = links; numInputs = 0; numOutputs = 0; foreach (NodeGene n in nodes) { if (n.nTYPE == NTYPE.INPUT) { numInputs++; } else if (n.nTYPE == NTYPE.OUTPUT) { numOutputs++; } } this.archetypeIndex = archetypeIndex; ID = EvolutionaryHistory.NextGenotypeID(); }
/// <summary> /// This executes before any Start() methods /// </summary> private void Awake() { //Init EvolutionaryHistory.InitializeEvolutionaryHistory(); testerID = DEFAULT_TESTERID; invertY = DEFAULT_INVERTY; functionSpawnRate = DEFAULT_FUNCTION_SPAWN_RATE; artworkMutationChances = DEFAULT_ARTWORK_MUTATION_CHANCES; sculptureMutationChances = DEFAULT_SCULPTURE_MUTATION_CHANCES; gameTimer = MAX_GAME_TIME; //set reference to the player player = FindObjectOfType <Player>(); //parse command line args and set variables if (args[0] != null) { for (int i = 0; i < args.Length; i++) { if (args[i] == "-testerID") { int result; if (int.TryParse(args[i + 1], out result)) { testerID = result; } } else if (args[i] == "-invertY") { invertY = true; } else if (args[i] == "-functionSpawnRate") { float result; if (float.TryParse(args[i + 1], out result)) { functionSpawnRate = result; } } else if (args[i] == "-artworkMutationChances") { int result; if (int.TryParse(args[i + 1], out result)) { artworkMutationChances = result; } } else if (args[i] == "-sculptureMutationChances") { int result; if (int.TryParse(args[i + 1], out result)) { sculptureMutationChances = result; } } else if (args[i] == "-gameTimer") { float result; if (float.TryParse(args[i + 1], out result) && result <= MAX_GAME_TIME) { gameTimer = result; } } } } }