Aggregation and Offsets#
aggregate.sum() and aggregate.mean() build an aggregation
\(W\): an Operator from a Space (its columns) to the
groups of its labels (its rows), sparse. On the observations,
Problem.aggregate() gives the problem of \(W z\), \(W H\),
\(W S_z W^T\) and \(W c\) (hourly observations to daily means); on the
state, Posterior.cov() and Posterior.averaging_kernel() take it for
the posterior of totals or means. The groups are given by by: level names,
a pandas.Grouper with a freq (time bins at a frequency), an
pandas.IntervalIndex named after a level (time bins given), or a
pandas.Series that maps a level’s values to groups (sites to networks,
cells to regions).
offset_block() uses the same groups for a block of unknown offsets in the
state: one per group of observations (a site’s background in a month), with
the forward block that adds each to its observations. Its prior covariance is
any model on the offsets’ labels, so Exponential("obs_time", "30D",
within="site") correlates the months of a site.
In [1]: import numpy as np
In [2]: import pandas as pd
In [3]: import fips
In [4]: hours = pd.date_range("2024-01-01", periods=6, freq="8h")
In [5]: labels = pd.MultiIndex.from_product([["A", "B"], hours], names=["site", "obs_time"])
In [6]: obs = fips.Vector.from_series(pd.Series(np.arange(12.0), index=labels), block="ch4")
In [7]: W = fips.aggregate.mean(obs.space, by=["site", pd.Grouper(level="obs_time", freq="1D")])
In [8]: (W @ obs).to_series()
Out[8]:
block site obs_time
ch4 A 2024-01-01 1.0
2024-01-02 4.0
B 2024-01-01 7.0
2024-01-02 10.0
dtype: float64
In [9]: offsets, forward = fips.offset_block(obs.space, by=pd.Grouper(level="obs_time", freq="1D"))
In [10]: offsets.space
Out[10]: Space(offset: 2 x ['obs_time'])
Aggregation#
|
Return the operator that sums the labels of space by group. |
|
Return the operator that averages the labels of space by group. |
Offsets#
|
Return a block of offsets for the state: one per group of observations, and the map to them. |