-
Notifications
You must be signed in to change notification settings - Fork 91
Basics of finite probability theory #1626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
malarbol
wants to merge
35
commits into
UniMath:master
Choose a base branch
from
malarbol:probability-theory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
992890f
finite probability spaces & random variables
malarbol d941a54
constant random variables
malarbol 9df4d7b
fix link
malarbol b3cad75
Merge branch 'master' into probability-theory
malarbol c826867
rename module finite-probability-theory
malarbol 6f03269
fix links
malarbol 68bfd70
format
malarbol e4e361a
typo
malarbol 380bb36
rename measure -> distribution
malarbol 424c0f8
add references
malarbol 58f9c47
fix link
malarbol 76ac71b
zero-is-not-one-R
malarbol 1c306a6
finite probability spaces are inhabited
malarbol d4082d6
atomic random variables
malarbol aeb66d1
fix name
malarbol 12c60fd
explicit references sections
malarbol 1538f5d
Update references.bib
malarbol 883489e
rephrase non-empty consequence/hypothesis for finite probability spaces
malarbol a6de932
re-rephrase
malarbol ea39ce4
Update src/finite-probability-theory/finite-probability-spaces.lagda.md
malarbol 384d6bc
Update src/finite-probability-theory/finite-probability-spaces.lagda.md
malarbol 745c376
Update src/finite-probability-theory/probability-distributions-on-fin…
malarbol e040b72
Update src/finite-probability-theory/positive-distributions-on-finite…
malarbol 50ee095
Use Pr instead of \mu
malarbol 782074f
format
malarbol 83646d0
Merge branch 'master' into probability-theory
malarbol 9c465a4
rename real-random-variable
malarbol 9fe7c83
use prop-double-negation-elim-is-inhabited-or-empty
malarbol ef5c7d0
fix link
malarbol 9143114
fix link
malarbol cd0fcae
Merge branch 'master' into probability-theory
malarbol e6366f8
Merge branch 'master' into probability-theory
malarbol 4a98f17
Merge branch 'master' into probability-theory
malarbol 9026548
Merge branch 'master' into probability-theory
malarbol da98060
Merge branch 'master' into probability-theory
malarbol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Finite probability theory | ||
|
|
||
| ```agda | ||
| module finite-probability-theory where | ||
|
|
||
| open import finite-probability-theory.expected-value-random-real-variables-finite-probability-spaces public | ||
| open import finite-probability-theory.finite-probability-spaces public | ||
| open import finite-probability-theory.measures-on-finite-types public | ||
| open import finite-probability-theory.probability-measures-on-finite-types public | ||
| open import finite-probability-theory.random-real-variables-finite-probability-spaces public | ||
| ``` |
72 changes: 72 additions & 0 deletions
72
...-theory/expected-value-random-real-variables-finite-probability-spaces.lagda.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Expected value of random real variables in finite probability spaces | ||
|
|
||
| ```agda | ||
| module finite-probability-theory.expected-value-random-real-variables-finite-probability-spaces where | ||
| ``` | ||
|
|
||
| <details><summary>Imports</summary> | ||
|
|
||
| ```agda | ||
| open import finite-probability-theory.finite-probability-spaces | ||
| open import finite-probability-theory.measures-on-finite-types | ||
| open import finite-probability-theory.probability-measures-on-finite-types | ||
| open import finite-probability-theory.random-real-variables-finite-probability-spaces | ||
|
|
||
| open import foundation.dependent-pair-types | ||
| open import foundation.empty-types | ||
| open import foundation.function-types | ||
| open import foundation.identity-types | ||
| open import foundation.inhabited-types | ||
| open import foundation.propositions | ||
| open import foundation.sets | ||
| open import foundation.subtypes | ||
| open import foundation.transport-along-identifications | ||
| open import foundation.universe-levels | ||
|
|
||
| open import group-theory.sums-of-finite-families-of-elements-abelian-groups | ||
|
|
||
| open import real-numbers.addition-real-numbers | ||
| open import real-numbers.dedekind-real-numbers | ||
| open import real-numbers.multiplication-real-numbers | ||
| open import real-numbers.positive-real-numbers | ||
| open import real-numbers.rational-real-numbers | ||
| open import real-numbers.strict-inequality-real-numbers | ||
|
|
||
| open import univalent-combinatorics.finite-types | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| ## Idea | ||
|
|
||
| The | ||
| {{#concept "expected value" Disambiguation="of a random real variable in a finite probability space" Agda=expected-value-random-real-variable-Finite-Probability-Space}} | ||
| of a | ||
| [random real variable](finite-probability-theory.random-real-variables-finite-probability-spaces.md) | ||
| `X` in a | ||
| [finite probability space](finite-probability-theory.finite-probability-spaces.md) | ||
| `(Ω , μ)` is the | ||
| [sum](group-theory.sums-of-finite-families-of-elements-abelian-groups.md) | ||
|
|
||
| \[ ∑\_{x ∈ Ω} X(x)μ(x). \] | ||
|
|
||
| ## Definitions | ||
|
|
||
| ### Expected value of a random real variable in a finite probability space | ||
|
|
||
| ```agda | ||
| module _ | ||
| {l : Level} (Ω : Finite-Probability-Space l) | ||
| (X : random-real-variable-Finite-Probability-Space Ω) | ||
| where | ||
|
|
||
| expected-value-random-real-variable-Finite-Probability-Space : ℝ lzero | ||
| expected-value-random-real-variable-Finite-Probability-Space = | ||
| sum-finite-Ab | ||
| ( abelian-group-add-ℝ-lzero) | ||
| ( finite-type-Finite-Probability-Space Ω) | ||
| ( λ x → | ||
| mul-ℝ | ||
| ( X x) | ||
| ( real-measure-Finite-Probability-Space Ω x)) | ||
| ``` | ||
123 changes: 123 additions & 0 deletions
123
src/finite-probability-theory/finite-probability-spaces.lagda.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Finite probability spaces | ||
|
|
||
| ```agda | ||
| module finite-probability-theory.finite-probability-spaces where | ||
| ``` | ||
|
|
||
| <details><summary>Imports</summary> | ||
|
|
||
| ```agda | ||
| open import finite-probability-theory.measures-on-finite-types | ||
| open import finite-probability-theory.probability-measures-on-finite-types | ||
|
|
||
| open import foundation.dependent-pair-types | ||
| open import foundation.empty-types | ||
| open import foundation.function-types | ||
| open import foundation.identity-types | ||
| open import foundation.inhabited-types | ||
| open import foundation.propositions | ||
| open import foundation.sets | ||
| open import foundation.subtypes | ||
| open import foundation.transport-along-identifications | ||
| open import foundation.universe-levels | ||
|
|
||
| open import group-theory.sums-of-finite-families-of-elements-abelian-groups | ||
|
|
||
| open import real-numbers.addition-real-numbers | ||
| open import real-numbers.dedekind-real-numbers | ||
| open import real-numbers.positive-real-numbers | ||
| open import real-numbers.rational-real-numbers | ||
| open import real-numbers.strict-inequality-real-numbers | ||
|
|
||
| open import univalent-combinatorics.finite-types | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| ## Idea | ||
|
|
||
| A {{#concept "finite probability space" Agda=Finite-Probability-Space}} is a | ||
| [finite type](univalent-combinatorics.finite-types.md) equipped with a | ||
| [probability measure](finite-probability-theory.probability-measures-on-finite-types.md). | ||
|
|
||
| ## Definitions | ||
|
|
||
| ### Finite probability spaces | ||
|
|
||
| ```agda | ||
| Finite-Probability-Space : (l : Level) → UU (lsuc l) | ||
| Finite-Probability-Space l = | ||
| Σ ( Finite-Type l) | ||
| ( probability-measure-Finite-Type) | ||
|
|
||
| module _ | ||
| {l : Level} (Ω : Finite-Probability-Space l) | ||
| where | ||
|
|
||
| finite-type-Finite-Probability-Space : Finite-Type l | ||
| finite-type-Finite-Probability-Space = pr1 Ω | ||
|
|
||
| type-Finite-Probability-Space : UU l | ||
| type-Finite-Probability-Space = | ||
| type-Finite-Type finite-type-Finite-Probability-Space | ||
|
|
||
| is-finite-type-Finite-Probability-Space : | ||
| is-finite type-Finite-Probability-Space | ||
| is-finite-type-Finite-Probability-Space = | ||
| is-finite-type-Finite-Type finite-type-Finite-Probability-Space | ||
|
|
||
| measure-Finite-Probability-Space : | ||
| measure-Finite-Type finite-type-Finite-Probability-Space | ||
| measure-Finite-Probability-Space = pr1 (pr2 Ω) | ||
|
|
||
| real-measure-Finite-Probability-Space : | ||
| type-Finite-Probability-Space → ℝ lzero | ||
| real-measure-Finite-Probability-Space = | ||
| real-measure-Finite-Type | ||
| ( finite-type-Finite-Probability-Space) | ||
| ( measure-Finite-Probability-Space) | ||
|
|
||
| eq-one-total-measure-Finite-Probability-Space : | ||
| ( total-measure-Finite-Type | ||
| ( finite-type-Finite-Probability-Space) | ||
| ( measure-Finite-Probability-Space)) = | ||
| one-ℝ | ||
| eq-one-total-measure-Finite-Probability-Space = | ||
| pr2 (pr2 (Ω)) | ||
malarbol marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| ### A finite probability space is nonempty | ||
|
|
||
| ```agda | ||
| module _ | ||
| {l : Level} (Ω : Finite-Probability-Space l) | ||
| where | ||
|
|
||
| is-nonempty-type-Finite-Probability-Space : | ||
| is-nonempty (type-Finite-Probability-Space Ω) | ||
| is-nonempty-type-Finite-Probability-Space = | ||
| not-0=1 ∘ absurd-is-empty-Finite-Probability-Space | ||
| where | ||
|
|
||
| absurd-is-empty-Finite-Probability-Space : | ||
| is-empty (type-Finite-Probability-Space Ω) → | ||
| zero-ℝ = one-ℝ | ||
| absurd-is-empty-Finite-Probability-Space H = | ||
| ( inv | ||
| ( is-zero-total-measure-is-empty-Finite-Type | ||
| ( finite-type-Finite-Probability-Space Ω) | ||
| ( measure-Finite-Probability-Space Ω) | ||
| ( H))) ∙ | ||
| ( eq-one-total-measure-Finite-Probability-Space Ω) | ||
|
|
||
| not-0=1 : is-empty (zero-ℝ = one-ℝ) | ||
fredrik-bakke marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| not-0=1 H = | ||
| irreflexive-le-ℝ | ||
| ( zero-ℝ) | ||
| ( inv-tr | ||
| ( le-ℝ zero-ℝ) | ||
| ( H) | ||
| ( is-positive-real-ℝ⁺ one-ℝ⁺)) | ||
| ``` | ||
malarbol marked this conversation as resolved.
Show resolved
Hide resolved
|
||
81 changes: 81 additions & 0 deletions
81
src/finite-probability-theory/measures-on-finite-types.lagda.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Measures on finite types | ||
|
|
||
| ```agda | ||
| module finite-probability-theory.measures-on-finite-types where | ||
| ``` | ||
|
|
||
| <details><summary>Imports</summary> | ||
|
|
||
| ```agda | ||
| open import foundation.empty-types | ||
| open import foundation.function-types | ||
| open import foundation.identity-types | ||
| open import foundation.universe-levels | ||
|
|
||
| open import group-theory.sums-of-finite-families-of-elements-abelian-groups | ||
|
|
||
| open import real-numbers.addition-real-numbers | ||
| open import real-numbers.dedekind-real-numbers | ||
| open import real-numbers.positive-real-numbers | ||
| open import real-numbers.rational-real-numbers | ||
|
|
||
| open import univalent-combinatorics.finite-types | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| ## Idea | ||
|
|
||
| A | ||
| {{#concept "measure" Disambiguation="on a finite type" Agda=measure-Finite-Type}} | ||
| on a [finite type](univalent-combinatorics.finite-types.md) is a function into | ||
| the [positive real numbers](real-numbers.positive-real-numbers.md). | ||
|
|
||
| The **total measure** of a measure `μ` on a finite type `Ω` is the | ||
| [sum](group-theory.sums-of-finite-families-of-elements-abelian-groups.md) | ||
|
|
||
| \[ ∑\_{x ∈ Ω} μ(x). \] | ||
|
|
||
| ## Definition | ||
|
|
||
| ### Measures on finite types | ||
|
|
||
| ```agda | ||
| module _ | ||
| {l : Level} (Ω : Finite-Type l) | ||
| where | ||
|
|
||
| measure-Finite-Type : UU (lsuc lzero ⊔ l) | ||
| measure-Finite-Type = type-Finite-Type Ω → ℝ⁺ lzero | ||
|
|
||
| real-measure-Finite-Type : | ||
| measure-Finite-Type → type-Finite-Type Ω → ℝ lzero | ||
| real-measure-Finite-Type μ = real-ℝ⁺ ∘ μ | ||
|
|
||
| total-measure-Finite-Type : measure-Finite-Type → ℝ lzero | ||
| total-measure-Finite-Type μ = | ||
| sum-finite-Ab | ||
| ( abelian-group-add-ℝ-lzero) | ||
| ( Ω) | ||
| ( real-ℝ⁺ ∘ μ) | ||
| ``` | ||
|
|
||
| ## Properties | ||
|
|
||
| ### The total measure of an empty type is zero | ||
|
|
||
| ```agda | ||
| module _ | ||
| {l : Level} (Ω : Finite-Type l) (μ : measure-Finite-Type Ω) | ||
| where | ||
|
|
||
| is-zero-total-measure-is-empty-Finite-Type : | ||
| is-empty (type-Finite-Type Ω) → | ||
| total-measure-Finite-Type Ω μ = zero-ℝ | ||
| is-zero-total-measure-is-empty-Finite-Type H = | ||
| eq-zero-sum-finite-is-empty-Ab | ||
| ( abelian-group-add-ℝ-lzero) | ||
| ( Ω) | ||
| ( H) | ||
| ( real-ℝ⁺ ∘ μ) | ||
| ``` |
77 changes: 77 additions & 0 deletions
77
src/finite-probability-theory/probability-measures-on-finite-types.lagda.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| # Probability measures on finite types | ||
|
|
||
| ```agda | ||
| module finite-probability-theory.probability-measures-on-finite-types where | ||
| ``` | ||
|
|
||
| <details><summary>Imports</summary> | ||
|
|
||
| ```agda | ||
| open import finite-probability-theory.measures-on-finite-types | ||
|
|
||
| open import foundation.empty-types | ||
| open import foundation.function-types | ||
| open import foundation.identity-types | ||
| open import foundation.inhabited-types | ||
| open import foundation.propositions | ||
| open import foundation.sets | ||
| open import foundation.subtypes | ||
| open import foundation.universe-levels | ||
|
|
||
| open import group-theory.sums-of-finite-families-of-elements-abelian-groups | ||
|
|
||
| open import real-numbers.addition-real-numbers | ||
| open import real-numbers.dedekind-real-numbers | ||
| open import real-numbers.positive-real-numbers | ||
| open import real-numbers.rational-real-numbers | ||
|
|
||
| open import univalent-combinatorics.finite-types | ||
| ``` | ||
|
|
||
| </details> | ||
|
|
||
| ## Idea | ||
|
|
||
| A | ||
| {{#concept "probability measure" Disambiguation="on a finite type" Agda=probability-measure-Finite-Type}} | ||
| on a [finite type](univalent-combinatorics.finite-types.md) is a | ||
| [measure](finite-probability-theory.measures-on-finite-types.md) with **total | ||
| measure** equal to 1. | ||
|
|
||
| ## Definition | ||
|
|
||
| ### The property of being a probability measure on a finite type | ||
|
|
||
| ```agda | ||
| module _ | ||
| {l : Level} (Ω : Finite-Type l) (μ : measure-Finite-Type Ω) | ||
| where | ||
|
|
||
| is-probability-measure-prop-measure-Finite-Type : Prop (lsuc lzero) | ||
| is-probability-measure-prop-measure-Finite-Type = | ||
| Id-Prop | ||
| ( ℝ-Set lzero) | ||
| ( total-measure-Finite-Type Ω μ) | ||
| ( one-ℝ) | ||
|
|
||
| is-probability-measure-Finite-Type : UU (lsuc lzero) | ||
| is-probability-measure-Finite-Type = | ||
| type-Prop is-probability-measure-prop-measure-Finite-Type | ||
|
|
||
| is-prop-is-probability-measure-Finite-Type : | ||
| is-prop is-probability-measure-Finite-Type | ||
| is-prop-is-probability-measure-Finite-Type = | ||
| is-prop-type-Prop is-probability-measure-prop-measure-Finite-Type | ||
| ``` | ||
|
|
||
| ### Probability measures on finite types | ||
|
|
||
| ```agda | ||
| module _ | ||
| {l : Level} (Ω : Finite-Type l) | ||
| where | ||
|
|
||
| probability-measure-Finite-Type : UU (lsuc lzero ⊔ l) | ||
| probability-measure-Finite-Type = | ||
| type-subtype (is-probability-measure-prop-measure-Finite-Type Ω) | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems probably true of any rational ring, FWIW? It might help variables more usefully expressed in terms of integers and rational numbers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it too but I think I'd need "rational-positive-distributions" for that (I'd need the coefficients
μ(x)to be rational); maybe it would be a good thing to have. I can give it a go or feel free to join in if you want to!On the other hand, we'll probably have the concept of "real ring" sometimes in the future so we'll be able to consider random variables in real rings then.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed you made quite some progress on real multiplication etc. Do we have the ring of real numbers already or are there still some missing laws?
I suspect distributivity must be quite painful🫤 EDIT: I see distributivity is already there 🎊There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're probably working on large rings and such. Let's wait then. I think we need som ring structure on ℝ to follow with more interesting results.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, see #1586. The ring at
lzerowas originally contributed, but in the end it was concluded to wait for the large ring.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect. I'll just wait then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, do you mean you will wait with finishing this PR until that one has been merged? If so, please mark this one as a draft.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. One of the endgoal is to prove that the space of real random variables is an ℝ-module and the expected value a linear map. For this I'll need more algebraic structure. And I'll need more time to figure out the level-polymorphic construction.
Thanks for your help anyways. Sorry for your time.