Beispiel #1
0
    /// <summary>
    /// Evaluate the provided phenome and return its fitness score.
    /// This takes a blackbox (pretty much the decoded neuralnetwork (the phenome)) that input can be passed to
    /// and output processed in the domain. Makes it very easy, we dont have to wory about the genome (genelist) or phenome (network) at all
    /// </summary>
    public FitnessInfo Evaluate(IBlackBox box)
    {
        // Set a maximum number of evaluations
        _evalCount++;
        double      fitness     = 0;
        FitnessInfo fitnessInfo = new FitnessInfo(fitness, fitness);

        if (_evalCount > _nextEvalStop)
        {
            _nextEvalStop += _evalBlockSize;
            Debug.Log("Eval Count = " + _evalCount);
            if (_evalCount >= 500000)
            {
                _stopConditionSatisfied = true;
            }
        }

        // Only use player model if it has been initialized. Otherwise, all fitness is 0.5
        if (_experiment.geomNodeList != null)
        {
            // Get highlevel features
            PCGSharpHighLevelFeatures featureCounts = new PCGSharpHighLevelFeatures();
            PCGSharpHighLevelFeatures.C_HL_ROOMTYPE lastRoomType = PCGSharpHighLevelFeatures.C_HL_ROOMTYPE.NoPreviousRoom;
            if (_experiment == null)
            {
                Debug.Log("Experiment null");
            }
            if (_experiment.geomNodeList == null)
            {
                Debug.Log("Geom node list null");
            }
            for (int i = 0; i < _experiment.geomNodeList.Count; i++)
            {
                // Get cppn output for each node
                box.InputSignalArray[0] = _experiment.geomNodeList[i].normDepth;
                box.InputSignalArray[1] = _experiment.geomNodeList[i].normSiblingIndex;

                box.ResetState();
                box.Activate();

                double[] outputs = new double[box.OutputCount];
                for (int j = 0; j < box.OutputCount; j++)
                {
                    outputs[j] = box.OutputSignalArray[j];
                }

                // Convert each nodes cppn output into a contentId
                int combinedContentID = featureCounts.CPPNOutputToSettingsId(outputs);
                lastRoomType = featureCounts.UpdateFeatures(combinedContentID, lastRoomType);
            }

            // Compare to the features of existing map
            double difference = featureCounts.CompareToOther(_originalFeatures);
            if (difference == 0)
            {
                _stopConditionSatisfied = true;
            }

            difference = 1000 + difference;

            // Fitness is the membership to the "Like" class (positive class)
            fitnessInfo = new FitnessInfo(difference, difference);
        }
        else
        {
            _stopConditionSatisfied = true;
        }

        return(fitnessInfo);
    }