lace.Engine.inconsistency

Engine.inconsistency(values, given=None)

Compute inconsistency.

Parameters:
  • values (polars or pandas DataFrame or Series) – The values over which to compute the inconsistency. Each row of the DataFrame, or each entry of the Series, is an observation. Column names (or the Series name) should correspond to names of features in the table.

  • given (Dict[index, value], optional) – A dictionary mapping column indices/name to values, which specifies conditions on the observations.

Notes

  • If no given is provided, values must contain two or more columns. Since inconsistency requires context, the inconsistency of a single unconditioned value is always 1.

Examples

Compute the inconsistency of all animals over all variables

>>> import polars as pl
>>> from lace import examples
>>> animals = examples.Animals()
>>> index = animals.df["id"]
>>> inconsistency = animals.inconsistency(animals.df.drop("id"))
>>> pl.DataFrame({"index": index, "inconsistency": inconsistency}).sort(
...     "inconsistency", descending=True
... )  
shape: (50, 2)
┌────────────────┬───────────────┐
│ index          ┆ inconsistency │
│ ---            ┆ ---           │
│ str            ┆ f64           │
╞════════════════╪═══════════════╡
│ collie         ┆ 0.816517      │
│ beaver         ┆ 0.809991      │
│ rabbit         ┆ 0.785911      │
│ polar+bear     ┆ 0.783775      │
│ …              ┆ …             │
│ killer+whale   ┆ 0.513013      │
│ blue+whale     ┆ 0.503965      │
│ dolphin        ┆ 0.480259      │
│ humpback+whale ┆ 0.434979      │
└────────────────┴───────────────┘

Find satellites with inconsistent orbital periods

>>> engine = examples.Satellites()
>>> data = []
>>> # examples give us special access to the underlying data
>>> for ix, row in engine.df.to_pandas().iterrows():
...     given = row.dropna().to_dict()
...     period = given.pop("Period_minutes", None)
...
...     if period is None:
...         continue
...
...     ix = given.pop("ID")
...     ic = engine.inconsistency(
...         pl.Series("Period_minutes", [period]),
...         given,
...     )
...
...     data.append(
...         {
...             "index": ix,
...             "inconsistency": ic,
...             "Period_minutes": period,
...         }
...     )
...
>>> pl.DataFrame(data).sort(
...     "inconsistency", descending=True
... )  
shape: (1_162, 3)
┌───────────────────────────────────┬───────────────┬────────────────┐
│ index                             ┆ inconsistency ┆ Period_minutes │
│ ---                               ┆ ---           ┆ ---            │
│ str                               ┆ f64           ┆ f64            │
╞═══════════════════════════════════╪═══════════════╪════════════════╡
│ Intelsat 903                      ┆ 1.973348      ┆ 1436.16        │
│ TianLian 2 (TL-1-02, CTDRS)       ┆ 1.3645        ┆ 1436.1         │
│ QZS-1 (Quazi-Zenith Satellite Sy… ┆ 1.364247      ┆ 1436.0         │
│ Compass G-8 (Beidou IGSO-3)       ┆ 1.364093      ┆ 1435.93        │
│ …                                 ┆ …             ┆ …              │
│ Navstar GPS II-24 (Navstar SVN 3… ┆ 0.646141      ┆ 716.69         │
│ Navstar GPS IIR-10 (Navstar SVN … ┆ 0.646027      ┆ 716.47         │
│ Navstar GPS IIR-M-6 (Navstar SVN… ┆ 0.645991      ┆ 716.4          │
│ BSAT-3B                           ┆ 0.625282      ┆ 1365.61        │
└───────────────────────────────────┴───────────────┴────────────────┘

It looks like Intelsat 903 is the most inconsistent by a good amount. Let’s take a look at it’s data and see why its orbital period (very standard for a geosynchronos satellites) isn’t consistent with the model.

>>> cols = [
...     "Period_minutes",
...     "Class_of_Orbit",
...     "Perigee_km",
...     "Apogee_km",
...     "Eccentricity",
... ]
>>> engine.df.filter(pl.col("ID") == "Intelsat 903")[cols].melt()
shape: (5, 2)
┌────────────────┬────────────────────┐
│ variable       ┆ value              │
│ ---            ┆ ---                │
│ str            ┆ str                │
╞════════════════╪════════════════════╡
│ Period_minutes ┆ 1436.16            │
│ Class_of_Orbit ┆ GEO                │
│ Perigee_km     ┆ 35773.0            │
│ Apogee_km      ┆ 358802.0           │
│ Eccentricity   ┆ 0.7930699999999999 │
└────────────────┴────────────────────┘