AForge.MachineLearning.RouletteWheelExploration.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;
            // actions sum
            double sum = 0, estimateSum = 0;

            for ( int i = 0; i < actionsCount; i++ )
            {
                estimateSum += actionEstimates[i];
            }

            // get random number, which determines which action to choose
            double actionRandomNumber = rand.NextDouble( );

            for ( int i = 0; i < actionsCount; i++ )
            {
                sum += actionEstimates[i] / estimateSum;
                if ( actionRandomNumber <= sum )
                    return i;
            }

            return actionsCount - 1;
        }
    }