示例#1
0
    // Todo: reinstate
    public static void ScoreBasedWeightedAverage(List <NeuralCreature> nets, FCNetwork genotype)
    {
        // float scoreSum = 0f;

        // for (int i = 0; i < nets.Count; i++) {
        //     scoreSum += Mathf.Pow(nets[i].Score, 3f);
        // }

        // NNClassic.NetUtils.Zero(genotype);

        // for (int i = 0; i < nets.Count; i++) {
        //     float scale = Mathf.Pow(nets[i].Score, 3f) / scoreSum;
        //     Network candidate = nets[i].Mind;

        //     for (int l = 0; l < candidate.Layers.Count; l++) {
        //         for (int p = 0; p < candidate.Layers[l].ParamCount; p++) {
        //             genotype.Layers[l][p] += candidate.Layers[l][p] * scale;
        //         }
        //     }
        // }
    }
示例#2
0
    private void Awake()
    {
        Application.runInBackground = true;

        var protoCreature = QuadrotorFactory.CreateCreature(
            Vector3.zero,
            Quaternion.identity);

        var config = new FCNetworkConfig();

        config.Layers.Add(new FCLayerConfig {
            NumNeurons = protoCreature.NumInputs
        });
        config.Layers.Add(new FCLayerConfig {
            NumNeurons = 30
        });
        config.Layers.Add(new FCLayerConfig {
            NumNeurons = protoCreature.NumOutputs
        });

        Destroy(protoCreature.gameObject);

        // Create creature bodies
        _creatures = new List <NeuralCreature>(_populationSize);
        for (int i = 0; i < _populationSize; i++)
        {
            NeuralCreature nc = new NeuralCreature();

            Vector3 spawnPos = GetSpawnPosition(i, _populationSize);
            nc.Body = QuadrotorFactory.CreateCreature(
                spawnPos,
                GetSpawnRotation());

            nc.Mind = new FCNetwork(config);
            NeuralUtils.Initialize(nc.Mind, ref _rng);

            _creatures.Add(nc);
        }

        // Create a random genotype to seed the population
        _genotype = new FCNetwork(config);
        NeuralUtils.Initialize(_genotype, ref _rng);

        PrepareNewEpisode();
        MutatePopulation();

        // Store initial pose so we can reuse creature gameplay objects across tests
        _creatureInitPose = new List <ITransform>();
        CreatureFactory.SerializePose(_creatures[0].Body, _creatureInitPose);

        Physics.autoSimulation     = false;
        Physics.autoSyncTransforms = false;

        var colliders = FindObjectsOfType <CapsuleCollider>();

        for (int i = 0; i < colliders.Length; i++)
        {
            // Bug this doesn't work, why?
            colliders[i].material = _physicsMaterial;
        }

        StartEpisode();
    }