Exemple #1
0
    /// <summary>
    /// Take an action
    /// </summary>
    /// <param name="vectorAction">The action to take</param>
    /// <param name="textAction">The name of the action</param>
    public override void AgentAction(float[] vectorAction, string textAction)
    {
        base.AgentAction(vectorAction, textAction);
        lastActions = vectorAction;

        lastLoss = MLActionFactory.GetLoss(vectorAction);

        if (!isFighting)
        {
            return;
        }

        // Only perform confident moves
        var confidence = MLActionFactory.GetProbabilityFromVector(MLActionFactory.GetAction(vectorAction), vectorAction);

        if (!Mathf.Approximately(confidence, 0) && confidence < minConfidence)
        {
            return;
        }

        // Try to perform action
        TryToTakeAction(MLActionFactory.GetAction(vectorAction));

        // Interrupt dodges early
        if (endDodgeEarly && MLActionFactory.IsDodge(currentAction))
        {
            if (MLActionFactory.IsPunch(lastEnemyState) && !MLActionFactory.IsPunch(opponent.GetCurrentAction()))
            {
                // Opponent finished punching, so stop dodging
                dodgeAction.Interrupt();
            }
        }

        lastEnemyState = opponent.GetCurrentAction();
    }
Exemple #2
0
    private void Update()
    {
        var match = trainee.currentAction == coach.currentAction;//MLActionFactory.GetAction(trainee.lastActions) == MLActionFactory.GetAction(coach.lastActions);

        if (match)
        {
            matchingEvent.Invoke();
        }
        var desiredAction = MLActionFactory.GetAction(coach.lastActions);
        var probability   = MLActionFactory.GetProbabilityFromVector(desiredAction, trainee.lastActions);

        crossEntropy += MathUtils.CrossEntropy(probability);
        //correctness += probability;
        var alpha = 0.995f;

        runningAverageCorrectness = alpha * runningAverageCorrectness + (1 - alpha) * probability;
        AddSample(match);
    }