atas76 / openengine

Football match engine
MIT License
67 stars 6 forks source link

Take into account the current state's duration, rather than the next one's in sequence #11

Closed atas76 closed 1 year ago

atas76 commented 1 year ago

In the very first implementation, we are using the time of the next state in sequence for calculating the match duration. While this is practical and it evens out in total, it would be more correct to use the current state's time, because the duration of an action to complete is dependent not only on the action itself, but also on its outcome. We need to treat the whole state - action - outcome - state sequence as a unified chain, which will encapsulate all parameters of the transition between states, rather than split the initial state from its outcome, taking into account only the duration of the latter.

Examples:

Let the initial state be a corner kick. How long the corner kick will take will depend on its action (how it will be taken; not covered in this initial version) and its outcome. Currently, this duration is already predetermined by the previous state in sequence, because it would be convenient along with the outcome to pick also its duration, which however now is split from how the actual initial outcome's state plays out:

Corner Kick -> Corner Kick: 48 sec

if the corner kick results in a corner kick again, the duration added up will be the next corner kick's, even if the transition from one corner kick to the other would sensibly take much shorter time (and its assumed time would again be picked randomly from the previous state's transition).

Let's say we have the transition as specified in the match data:

Possession -> Corner Kick: 12 sec -> Possession

The corner kick taking 12 seconds will lead to a new possession, and it will be added as the initial's transition duration. However, as we don't want to overfit the simulation we will pick another outcome, which, with the current implementation, it will 'borrow' the duration from the next state, while the actual durations will be hidden from the implementation (the 12 seconds will be added as if the corner kick's outcome would be a possession, according to the data, but the simulation changes the outcome, without taking into account the change in duration, as the latter was predetermined when the first transition was selected from the previous state).

While reshuffling the outcomes is the main idea of this simulation, it would be more correct to pair the durations with the initial states rather than their outcomes in duration calculations while determining the outcomes.