SeitaBV / timely-beliefs

Model data as beliefs (at a certain time) about events (at a certain time).
MIT License
34 stars 6 forks source link

Compute the time integral of a BeliefsDataFrame #73

Open Flix6x opened 3 years ago

Flix6x commented 3 years ago

I often need to take the time integral of a BeliefsDataFrame, for example, when converting from a power flow to accumulated demand. It would be nice to be able to do this out of the box. Some sub-issues:

Flix6x commented 2 years ago

Proposed behaviour:

df = BeliefsDataFrame(some_timed_beliefs)

# The integrate method stands for taking the definite time integral with respect to the events
idf = df.integrate()

# The original sensor is retained
idf.sensor == df.sensor

# It follows that
idf.sensor.unit == df.sensor.unit
idf.sensor.event_resolution == df.sensor.event_resolution

# However, the unit and event resolution of the data have changed
idf.unit != df.sensor.unit
idf.event_resolution == timedelta(0)

Two notes:

  1. df.unit is a new BeliefsDataFrame property, next to df.sensor and df.event_resolution. We might want to use pint for unit conversion.
  2. I believe setting the event resolution to zero only makes sense for definite integrals, and not for indefinite integrals. For the latter case, we should retain the original event resolution, and make an assumption about what the event values describe. For example, if the event values describe mean values over sequential time intervals, we could take the assumption that the values within each interval are constant. Then it is possible to determine the indefinite integral, and we can report it's mean value in the original event resolution.

Finally, an example illustrating the belief timing sub-issue for (sequential) events A, B and C:

df (free-form representation)

belief_time    A     B     C
12:00          10          10
13:00          11    12      
14:00                      11
15:00          12
16:00                11

idf (free-form representation)

belief_time    A     B     C
12:00          10    10    20
13:00          11    23    33
14:00                      34
15:00          12    24    35
16:00                23    34