Discard action if best option has low score

  • April 5, 2018 at 20:44 #23060
    Álvaro
    Participant

    Hi!

    I’ve found several times the same scenario and I don’t know how to properly deal with it.

    I have an action that evaluates a bunch of options with a variety of scorers. Then the best option is selected (ActionWithOptions.GetBest<T>(…)) and some code is executed using this option.

    I would like to completely avoid executing those code lines if the best option’s score is below some limit (say 0).

    I can get all scores with ActionWithOptions.GetAllScores(…), manually find the best and then execute the code if its score is above 0.

    I wonder if:
    1) Is this a memory efficient way? ActionWithOptions.GetAllScores(…) needs a buffer that will be re-populated each time this AI’s action is executed. Plus I’d need to loop over all the ScoredOption<T> options just to get the score of the best one (maybe a HashMap<T,float> would have been more handy here for the buffer).

    2) How could I “quick discard” an option if a scorer evaluates below 0? Some scorers act more as “filters” than properly said “scorers”. I usually implement this by giving these filter scorers a very negative weight. However this works only if there is always at least an option which I know it will get a final combined score above 0.
    It’s like the “All or nothing” feature of context scores applied to custom option scorers. In fact, when I’m not sure if the selected option is valid, I codify context scorers almost equivalent to the option scorers which are acting as filters and evaluate them on the saved option so I make sure that the option is valid. But this means that the scorer logic is evaluated twice and usually leads to more entangled solutions.

    Any ideas?

    Thanks!

    April 6, 2018 at 09:56 #23063
    Rami
    Keymaster

    Hi Alvaro,

    Thanks for posting.

    The included ActionWithOptions does not have any more possibilities than the ones you have already found, i.e. GetBest and GetAllScores.

    If you use GetAllScores and want to avoid unnecessary memory allocations and subsequent GC, you can use our provided ListBufferPool – a pool for lists. Just remember to Return the list to the pool after use.

    Internally, GetBest also loops through all options, evaluating all scorers and returns the highest scoring one – so if you find the highest scoring one in your code, the difference is negligible.

    You can however also implement your own specialized action types, so you could implement an ‘ActionWithOptions’ with the ‘All or Nothing’ logic. Internally, the ActionWithOptions is just a generic ActionBase which exposes a list of IOptionScorer and provides the two aforementioned methods.

You must be logged in to reply to this topic.