Skip to content

Commit

Permalink
Starting to update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Baxter Eaves committed Jan 13, 2024
1 parent ce69065 commit c6a9bae
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated all packages to have the correct SPDX for the Business Source License
- Removed internal implimentation of `logsumexp` in favor of `rv::misc::logsumexp`
- Update to rv 0.16.2
- Impute and prediction uncertainty are the mean total variation distance between each state's distribution and the average distribution divided by the potential max: `(n-1) / n`, where `n` is the number of states. This normalization is meant to ensure that the interpretation is the same regardless of the number of states -- zero is lowest, one is highest.

### Fixed

Expand Down
34 changes: 17 additions & 17 deletions pylace/lace/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,15 @@ def held_out_uncertainty(
│ --- ┆ --- ┆ --- │
│ list[str] ┆ f64 ┆ i64 │
╞══════════════════════════════════╪═════════════════════════╪═══════════╡
│ null ┆ 0.543803 ┆ 0 │
│ ["Perigee_km"] ┆ 0.543803 ┆ 1 │
│ ["Source_Used_for_Orbital_Data"] ┆ 0.543799 ┆ 2 │
│ ["Class_of_Orbit"] ┆ 0.5428 ┆ 3 │
│ null ┆ 0.43212 ┆ 0 │
│ ["Perigee_km"] ┆ 0.43212 ┆ 1 │
│ ["Class_of_Orbit"] ┆ 0.43212 ┆ 2 │
│ ["Source_Used_for_Orbital_Data"] ┆ 0.431921 ┆ 3 │
│ … ┆ … ┆ … │
│ ["Purpose"] ┆ 0.440191 ┆ 15 │
│ ["Eccentricity"] ┆ 0.438648 ┆ 16 │
│ ["Inclination_radians"] ┆ 0.44004 ┆ 17 │
│ ["Apogee_km"] ┆ 1.443993 ┆ 18 │
│ ["Country_of_Operator"] ┆ 0.054156 ┆ 15 │
│ ["Country_of_Contractor"] ┆ 0.06069 ┆ 16 │
│ ["Dry_Mass_kg"] ┆ 0.139502 ┆ 17 │
│ ["Inclination_radians"] ┆ 0.089026 ┆ 18 │
└──────────────────────────────────┴─────────────────────────┴───────────┘
If we don't want to use the greedy search, we can enumerate, but we need to
Expand All @@ -521,15 +521,15 @@ def held_out_uncertainty(
│ --- ┆ --- ┆ --- │
│ list[str] ┆ f64 ┆ i64 │
╞═══════════════════════════════════╪═════════════════════════╪═══════════╡
│ null ┆ 0.579697 ┆ 0 │
│ ["Expected_Lifetime"] ┆ 0.553909 ┆ 1 │
│ ["Class_of_Orbit", "Expected_Lif… ┆ 0.395509 ┆ 2 │
│ ["Class_of_Orbit", "Date_of_Laun… ┆ 0.38756 ┆ 3 │
│ null ┆ 0.445501 ┆ 0 │
│ ["Expected_Lifetime"] ┆ 0.437647 ┆ 1 │
│ ["Apogee_km", "Eccentricity"] ┆ 0.05561 ┆ 2 │
│ ["Apogee_km", "Country_of_Operat… ┆ 0.055283 ┆ 3 │
│ … ┆ … ┆ … │
│ ["Class_of_Orbit", "Country_of_O… ┆ 0.399052 ┆ 5 │
│ ["Class_of_Orbit", "Country_of_O… ┆ 0.41235 ┆ 6 │
│ ["Class_of_Orbit", "Country_of_C… ┆ 0.44004 ┆ 7 │
│ ["Apogee_km", "Class_of_Orbit", … ┆ 1.443993 ┆ 8 │
│ ["Apogee_km", "Country_of_Operat… ┆ 0.057624 ┆ 5 │
│ ["Apogee_km", "Country_of_Contra… ┆ 0.0595 ┆ 6 │
│ ["Apogee_km", "Country_of_Contra… ┆ 0.077359 ┆ 7 │
│ ["Apogee_km", "Class_of_Orbit", … ┆ 0.089026 ┆ 8 │
└───────────────────────────────────┴─────────────────────────┴───────────┘
"""
search = (
Expand Down Expand Up @@ -797,7 +797,7 @@ def attributable_uncertainty(
... quiet=True,
... ) # doctest: +NORMALIZE_WHITESPACE
>>> frac
0.09788266843531362
0.1814171785207335
"""

return _attributable_holdout(
Expand Down
36 changes: 22 additions & 14 deletions pylace/lace/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def edit_cell(self, row: Union[str, int], col: Union[str, int], value):
│ --- ┆ --- ┆ --- │
│ str ┆ u8 ┆ f64 │
╞═══════╪════════╪═════════════╡
│ pig ┆ 0 ┆ 0.02385
│ pig ┆ 0 ┆ 0.07593
└───────┴────────┴─────────────┘
"""
self.engine.edit_cell(row, col, value)
Expand Down Expand Up @@ -1694,6 +1694,10 @@ def predict(
"""
Predict a single target from a conditional distribution.
Uncertainty is the normalized mean total variation distance between
each state's predictive distribution and the average predictive
distribution.
Parameters
----------
target: column index
Expand Down Expand Up @@ -1721,18 +1725,18 @@ def predict(
>>> from lace.examples import Animals
>>> animals = Animals()
>>> animals.predict("swims")
(0, 0.008287057807910558)
(0, 0.04384630488890182)
Predict whether an animal swims given that it has flippers
>>> animals.predict("swims", given={"flippers": 1})
(1, 0.05008037071634858)
(1, 0.09588592928237495)
Let's confuse lace and see what happens to its uncertainty. Let's
predict whether an non-water animal with flippers swims
>>> animals.predict("swims", given={"flippers": 1, "water": 0})
(0, 0.32863593091906085)
(0, 0.36077426258767503)
If you want to save time and you do not care about quantifying your
epistemic uncertainty, you don't have to compute uncertainty.
Expand Down Expand Up @@ -1762,6 +1766,10 @@ def impute(
be returned, even if the value is most likely to be missing. Imputation
forces the value of a cell to be present.
Uncertainty is the normalized mean total variation distance between
each state's imputation distribution and the average imputation
distribution.
Parameters
----------
col: column index
Expand Down Expand Up @@ -1802,15 +1810,15 @@ def impute(
│ --- ┆ --- ┆ --- │
│ str ┆ str ┆ f64 │
╞═══════════════════════════════════╪═════════════════╪═════════════╡
│ AAUSat-3 ┆ Sun-Synchronous ┆ 0.102337
│ ABS-1 (LMI-1, Lockheed Martin-In… ┆ Sun-Synchronous ┆ 0.445436
│ ABS-1A (Koreasat 2, Mugunghwa 2,… ┆ Sun-Synchronous ┆ 0.544273
│ ABS-2i (MBSat, Mobile Broadcasti… ┆ Sun-Synchronous ┆ 0.445436
│ AAUSat-3 ┆ Sun-Synchronous ┆ 0.186415
│ ABS-1 (LMI-1, Lockheed Martin-In… ┆ Sun-Synchronous ┆ 0.360331
│ ABS-1A (Koreasat 2, Mugunghwa 2,… ┆ Sun-Synchronous ┆ 0.425853
│ ABS-2i (MBSat, Mobile Broadcasti… ┆ Sun-Synchronous ┆ 0.360331
│ … ┆ … ┆ … │
│ Zhongxing 20A ┆ Sun-Synchronous ┆ 0.445436
│ Zhongxing 22A (Chinastar 22A) ┆ Sun-Synchronous ┆ 0.522895
│ Zhongxing 2A (Chinasat 2A) ┆ Sun-Synchronous ┆ 0.445436
│ Zhongxing 9 (Chinasat 9, Chinast… ┆ Sun-Synchronous ┆ 0.445436
│ Zhongxing 20A ┆ Sun-Synchronous ┆ 0.360331
│ Zhongxing 22A (Chinastar 22A) ┆ Sun-Synchronous ┆ 0.404823
│ Zhongxing 2A (Chinasat 2A) ┆ Sun-Synchronous ┆ 0.360331
│ Zhongxing 9 (Chinasat 9, Chinast… ┆ Sun-Synchronous ┆ 0.360331
└───────────────────────────────────┴─────────────────┴─────────────┘
Impute a defined set of rows
Expand All @@ -1822,8 +1830,8 @@ def impute(
│ --- ┆ --- ┆ --- │
│ str ┆ str ┆ f64 │
╞═══════════════╪════════════════════════╪═════════════╡
│ AAUSat-3 ┆ Technology Development ┆ 0.1918
│ Zhongxing 20A ┆ Communications ┆ 0.191064
│ AAUSat-3 ┆ Technology Development ┆ 0.238355
│ Zhongxing 20A ┆ Communications ┆ 0.129248
└───────────────┴────────────────────────┴─────────────┘
Uncertainty is optional
Expand Down
2 changes: 1 addition & 1 deletion pylace/tests/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def test_animals():
assert engine.shape == (50, 85)
swim_cat, swim_unc = engine.predict("swims")
assert swim_cat == 0
assert_almost_equal(swim_unc, 0.008287, 6)
assert_almost_equal(swim_unc, 0.04384630, 6)

0 comments on commit c6a9bae

Please sign in to comment.