Ejemplo n.º 1
0
    public Genome InitGenome()
    {
        Genome g1 = new Genome(gt);



        for (int i = 0; i < inputSize + outputSize; i++)
        {
            NodeGene node = GetDeafultGenome().GetNodeGenes()[i].Copy();
            if (node.GetNodeType() == NodeGene.NODETYPE.OUTPUT || node.GetNodeType() == NodeGene.NODETYPE.HIDDEN)
            {
                node.SetBias(Random.Range(-1.0f, 1.0f));
                //node.SetBias(1.0f);
            }
            g1.AddNodeGene(node);
            //g1.GetNodeGenes()[inputSize + i].SetBias(Random.Range(-1.0f, 1.0f));
        }
        for (int i = 0; i < startConnections; i++)//sample n connections
        {
            ConnectionGene con = connections[Random.Range(0, connections.Count)].Copy();
            //ConnectionGene con = connections[i].Copy();
            con.SetWeight(Random.Range(-weightRange, weightRange));
            //con.SetWeight(1.0f);
            int inId = con.GetInNode().GetId();
            con.SetInNode(g1.GetNodeGenes()[inId]);
            int outId = con.GetOutNode().GetId();
            //Debug.Log(con.GetOutNode());
            //Debug.Log(outId);
            con.SetOutNode(g1.GetNodeGenes()[outId]);
            g1.AddConnectionGene(con);
        }
        if (speciation)
        {
            InsertGenomeIntoSpecies(g1, species);
            impf.StatsSpecies(species.Count);
        }
        genomes.Add(g1);

        return(g1);
    }