AForge.MachineLearning.EpsilonGreedyExploration.ChooseAction C# (CSharp) Method

ChooseAction() public method

Choose an action.
The method chooses an action depending on the provided estimates. The estimates can be any sort of estimate, which values usefulness of the action (expected summary reward, discounted reward, etc).
public ChooseAction ( double actionEstimates ) : int
actionEstimates double Action estimates.
return int
        public int ChooseAction( double[] actionEstimates )
        {
            // actions count
            int actionsCount = actionEstimates.Length;

            // find the best action (greedy)
            double maxReward = actionEstimates[0];
            int greedyAction = 0;

            for ( int i = 1; i < actionsCount; i++ )
            {
                if ( actionEstimates[i] > maxReward )
                {
                    maxReward = actionEstimates[i];
                    greedyAction = i;
                }
            }

            // try to do exploration
            if ( rand.NextDouble( ) < epsilon )
            {
                int randomAction = rand.Next( actionsCount - 1 );

                if ( randomAction >= greedyAction )
                    randomAction++;

                return randomAction;
            }

            return greedyAction;
        }
    }