コード例 #1
0
    // Create a ne random genome from the given parameters.
    public Genome RandomGenome(
        int inputs              = 2,
        int outputs             = 2,
        int hiddenNodes         = 5,
        int connectionMutations = 5,
        float weight            = 10)
    {
        Genome result = new Genome(inputs, outputs, weight);

        for (int i = 0; i < hiddenNodes; i++)
        {
            var neuron = Mutator.MutateAddNode(result);
            if (neuron == null)
            {
                break;
            }
            neuron.InGenes[0].Weight  = Random.Range(-weight, weight);
            neuron.OutGenes[0].Weight = Random.Range(-weight, weight);
        }

        var poplProxy = FindObjectOfType <PopulationProxy>();
        var config    = poplProxy == null ? poplProxy.Config : new NEATConfig();

        for (int i = 0; i < connectionMutations; i++)
        {
            var gene = Mutator.MutateAddGene(config, result);
            if (gene == null)
            {
                break;
            }
            gene.Weight = Random.Range(-weight, weight);
        }

        return(result);
    }