@@ -73,9 +73,6 @@ From mathcomp Require Import charge ftc gauss_integral hoelder.
7373(* beta_pdf == probability density function for beta *)
7474(* beta_prob == beta probability measure *)
7575(* div_beta_fun a b c d := beta_fun (a + c) (b + d) / beta_fun a b *)
76- (* poisson_pmf r == a pmf of Poisson distribution with parameter r : R *)
77- (* poisson_prob r == probability measure of Poisson distribution when *)
78- (* 0 <= r and \d_0%N otherwise *)
7976(* ``` *)
8077(* *)
8178(***************************************************************************** *)
@@ -2303,159 +2300,6 @@ Qed.
23032300
23042301End exp_coeff_properties.
23052302
2306- Section normal_density.
2307- Context {R : realType}.
2308- Local Open Scope ring_scope.
2309- Local Import Num.ExtraDef.
2310- Implicit Types m s x : R.
2311-
2312- Definition normal_pdf0 m s x : R := normal_peak s * normal_fun m s x.
2313-
2314- Lemma normal_pdf0_center m s : normal_pdf0 m s = normal_pdf0 0 s \o center m.
2315- Proof . by rewrite /normal_pdf0 normal_fun_center. Qed .
2316-
2317- Lemma normal_pdf0_ge0 m s x : 0 <= normal_pdf0 m s x.
2318- Proof . by rewrite mulr_ge0 ?normal_peak_ge0 ?expR_ge0. Qed .
2319-
2320- Lemma normal_pdf0_gt0 m s x : s != 0 -> 0 < normal_pdf0 m s x.
2321- Proof . by move=> s0; rewrite mulr_gt0 ?expR_gt0// normal_peak_gt0. Qed .
2322-
2323- Lemma measurable_normal_pdf0 m s : measurable_fun setT (normal_pdf0 m s).
2324- Proof . by apply: measurable_funM => //=; exact: measurable_normal_fun. Qed .
2325-
2326- Lemma continuous_normal_pdf0 m s : continuous (normal_pdf0 m s).
2327- Proof .
2328- move=> x; apply: cvgM; first exact: cvg_cst.
2329- apply: (@cvg_comp _ R^o _ _ _ _
2330- (nbhs (- (x - m) ^+ 2 / (s ^+ 2 *+ 2)))); last exact: continuous_expR.
2331- apply: cvgM; last exact: cvg_cst; apply: (@cvgN _ R^o).
2332- apply: (@cvg_comp _ _ _ _ (@GRing.exp R^~ 2) _ (nbhs (x - m))).
2333- apply: (@cvgB _ R^o) => //; exact: cvg_cst.
2334- exact: sqr_continuous.
2335- Qed .
2336-
2337- Lemma normal_pdf0_ub m s x : normal_pdf0 m s x <= normal_peak s.
2338- Proof .
2339- rewrite /normal_pdf0 ler_piMr ?normal_peak_ge0//.
2340- rewrite -[leRHS]expR0 ler_expR mulNr oppr_le0 mulr_ge0// ?sqr_ge0//.
2341- by rewrite invr_ge0 mulrn_wge0// sqr_ge0.
2342- Qed .
2343-
2344- End normal_density.
2345-
2346- Section normal_probability.
2347- Variables (R : realType) (m sigma : R).
2348- Local Open Scope ring_scope.
2349- Notation mu := lebesgue_measure.
2350-
2351- Local Notation normal_peak := (normal_peak sigma).
2352- Local Notation normal_fun := (normal_fun m sigma).
2353-
2354- Let measurable_normal_fun : measurable_fun setT normal_fun.
2355- Proof .
2356- apply: measurableT_comp => //=; apply: measurable_funM => //=.
2357- apply: measurableT_comp => //=; apply: measurable_funX => //=.
2358- exact: measurable_funD.
2359- Qed .
2360-
2361- Let F (x : R^o) := (x - m) / (Num.sqrt (sigma ^+ 2 *+ 2)).
2362- Lemma F'E : F^`()%classic = cst (Num.sqrt (sigma ^+ 2 *+ 2))^-1.
2363- Proof .
2364- apply/funext => x; rewrite /F derive1E deriveM// deriveD// derive_cst scaler0.
2365- by rewrite add0r derive_id derive_cst addr0 scaler1.
2366- Qed .
2367-
2368- Let int_gaussFE : sigma != 0 ->
2369- (\int[mu]_x ((((gauss_fun \o F) *
2370- (F^`())%classic) x)%:E * (Num.sqrt (sigma ^+ 2 *+ 2))%:E))%E =
2371- (Num.sqrt (sigma ^+ 2 * pi *+ 2))%:E.
2372- Proof .
2373- move=> s0.
2374- rewrite -mulrnAr -[in RHS]mulr_natr sqrtrM ?(sqrtrM 2) ?sqr_ge0 ?pi_ge0// !EFinM.
2375- rewrite muleCA ge0_integralZr//=; last first.
2376- by move=> x _; rewrite lee_fin mulr_ge0//= ?gauss_fun_ge0// F'E/= invr_ge0.
2377- rewrite F'E; apply/measurable_EFinP/measurable_funM => //.
2378- apply/measurableT_comp => //; first exact: measurable_gauss_fun.
2379- by apply: measurable_funM => //; exact: measurable_funD.
2380- congr *%E.
2381- rewrite -increasing_ge0_integration_by_substitutionT//; first last.
2382- - by move=> x; rewrite gauss_fun_ge0.
2383- - exact: continuous_gauss_fun.
2384- - apply/gt0_cvgMly; last exact: cvg_addrr.
2385- by rewrite invr_gt0// sqrtr_gt0 -mulr_natr mulr_gt0// exprn_even_gt0.
2386- - apply/gt0_cvgMlNy; last exact: cvg_addrr_Ny.
2387- by rewrite invr_gt0// sqrtr_gt0 -mulr_natr mulr_gt0// exprn_even_gt0.
2388- - by rewrite F'E; exact: is_cvg_cst.
2389- - by rewrite F'E; exact: is_cvg_cst.
2390- - by rewrite F'E => ?; exact: cvg_cst.
2391- - move=> x y xy; rewrite /F ltr_pM2r ?ltr_leB//.
2392- rewrite invr_gt0 ?sqrtr_gt0 ?pmulrn_lgt0 ?exprn_even_gt0//.
2393- apply: integralT_gauss.
2394- by rewrite -(mulr_natr (_ ^+ 2)) sqrtrM ?sqr_ge0.
2395- Qed .
2396-
2397- Let integral_normal_pdf_part : sigma != 0 ->
2398- (\int[mu]_x (normal_fun x)%:E =
2399- (Num.sqrt (sigma ^+ 2 * pi *+ 2))%:E)%E.
2400- Proof .
2401- move=> s0; rewrite -int_gaussFE//; apply: eq_integral => /= x _.
2402- rewrite F'E !fctE/= EFinM -muleA -EFinM mulVf ?mulr1; last first.
2403- by rewrite gt_eqF// sqrtr_gt0 pmulrn_lgt0// exprn_even_gt0.
2404- congr (expR _)%:E; rewrite mulNr exprMn exprVn; congr (- (_ * _^-1)%R).
2405- by rewrite sqr_sqrtr// pmulrn_lge0// sqr_ge0.
2406- Qed .
2407-
2408- Let integrable_normal_pdf_part : sigma != 0 ->
2409- mu.-integrable setT (EFin \o normal_fun).
2410- Proof .
2411- move=> s0; apply/integrableP; split.
2412- by apply/measurable_EFinP; apply: measurable_normal_fun.
2413- under eq_integral do rewrite /= ger0_norm ?expR_ge0//.
2414- by rewrite /= integral_normal_pdf_part// ltry.
2415- Qed .
2416-
2417- Local Notation normal_pdf := (normal_pdf m sigma).
2418- Local Notation normal_prob := (normal_prob m sigma).
2419-
2420- Let normal0 : normal_prob set0 = 0%E.
2421- Proof . by rewrite /normal_prob integral_set0. Qed .
2422-
2423- Let normal_ge0 A : (0 <= normal_prob A)%E.
2424- Proof .
2425- rewrite /normal_prob integral_ge0//= => x _.
2426- by rewrite lee_fin normal_pdf_ge0 ?ltW.
2427- Qed .
2428-
2429- Let normal_sigma_additive : semi_sigma_additive normal_prob.
2430- Proof .
2431- move=> /= A mA tA mUA.
2432- rewrite /normal_prob/= integral_bigcup//=; last first.
2433- apply: (integrableS _ _ (@subsetT _ _)) => //; exact: integrable_normal_pdf.
2434- apply: is_cvg_ereal_nneg_natsum_cond => n _ _.
2435- by apply: integral_ge0 => /= x ?; rewrite lee_fin normal_pdf_ge0 ?ltW.
2436- Qed .
2437-
2438- HB.instance Definition _ := isMeasure.Build _ _ _
2439- normal_prob normal0 normal_ge0 normal_sigma_additive.
2440-
2441- Let normal_setT : normal_prob [set: _] = 1%E.
2442- Proof . by rewrite /normal_prob integral_normal_pdf. Qed .
2443-
2444- HB.instance Definition _ :=
2445- @Measure_isProbability.Build _ _ R normal_prob normal_setT.
2446-
2447- Lemma integrable_indic_itv (a b : R) (b0 b1 : bool) : a < b ->
2448- mu.-integrable setT (EFin \o \1_[set` (Interval (BSide b0 a) (BSide b1 b))]).
2449- Proof .
2450- move=> ab.
2451- apply/integrableP; split; first by apply/measurable_EFinP/measurable_indic.
2452- apply/abse_integralP => //; first by apply/measurable_EFinP/measurable_indic.
2453- rewrite integral_indic// setIT/= lebesgue_measure_itv/=.
2454- by rewrite lte_fin ab -EFinD/= ltry.
2455- Qed .
2456-
2457- End normal_probability.
2458-
24592303(* TODO: move *)
24602304Section shift_properties.
24612305Variable R : realType.
@@ -3914,147 +3758,3 @@ by rewrite -!EFin_beta_fun -EFinM divff// gt_eqF// beta_fun_gt0.
39143758Qed .
39153759
39163760End beta_prob_bernoulliE.
3917-
3918- Section poisson_pmf.
3919- Local Open Scope ring_scope.
3920- Context {R : realType}.
3921- Implicit Types (rate : R) (k : nat).
3922-
3923- Definition poisson_pmf (rate : R) (k : nat) : R :=
3924- (rate ^+ k) * k`!%:R^-1 * expR (- rate).
3925-
3926- Lemma poisson_pmf_ge0 rate k (rate0 : 0 <= rate) : 0 <= poisson_pmf rate k.
3927- Proof .
3928- by rewrite /poisson_pmf 2?mulr_ge0// exprn_ge0.
3929- Qed .
3930-
3931- End poisson_pmf.
3932-
3933- Lemma measurable_poisson_pmf {R : realType} D (rate : R) k :
3934- measurable_fun D (@poisson_pmf R ^~ k).
3935- Proof .
3936- apply: measurable_funM; first exact: measurable_funM.
3937- by apply: measurable_funTS; exact: measurableT_comp.
3938- Qed .
3939-
3940- Definition poisson_prob {R : realType} (rate : R) (k : nat)
3941- : set nat -> \bar R :=
3942- fun U => if (0 <= rate)%R then
3943- \esum_(k in U) (poisson_pmf rate k)%:E else \d_0%N U.
3944-
3945- Section poisson.
3946- Context {R : realType} (rate : R) (k : nat).
3947- Local Open Scope ereal_scope.
3948-
3949- Local Notation poisson := (poisson_prob rate k).
3950-
3951- Let poisson0 : poisson set0 = 0.
3952- Proof . by rewrite /poisson measure0; case: ifPn => //; rewrite esum_set0. Qed .
3953-
3954- Let poisson_ge0 U : 0 <= poisson U.
3955- Proof .
3956- rewrite /poisson; case: ifPn => // rate0; apply: esum_ge0 => /= n Un.
3957- by rewrite lee_fin poisson_pmf_ge0.
3958- Qed .
3959-
3960- Let poisson_sigma_additive : semi_sigma_additive poisson.
3961- Proof .
3962- move=> F mF tF mUF; rewrite /poisson; case: ifPn => rate0; last first.
3963- exact: measure_semi_sigma_additive.
3964- apply: cvg_toP.
3965- apply: ereal_nondecreasing_is_cvgn => a b ab.
3966- apply: lee_sum_nneg_natr => // n _ _.
3967- by apply: esum_ge0 => /= ? _; exact: poisson_pmf_ge0.
3968- by rewrite nneseries_sum_bigcup// => i; rewrite lee_fin poisson_pmf_ge0.
3969- Qed .
3970-
3971- HB.instance Definition _ := isMeasure.Build _ _ _ poisson
3972- poisson0 poisson_ge0 poisson_sigma_additive.
3973-
3974- Let poisson_setT : poisson [set: _] = 1.
3975- Proof .
3976- rewrite /poisson; case: ifPn; last by move=> _; rewrite probability_setT.
3977- move=> rate0; rewrite /poisson_pmf.
3978- have pkn n : 0%R <= (rate ^+ n / n`!%:R * expR (- rate))%:E.
3979- by rewrite lee_fin poisson_pmf_ge0.
3980- apply/esym.
3981- rewrite [LHS](_ : _ = (expR rate)%:E * (expR (- rate))%:E); last first.
3982- by rewrite -EFinM expRN divff// gt_eqF ?expR_gt0.
3983- transitivity
3984- ((\esum_(k0 in setT) (rate ^+ k0 / k0`!%:R)%:E) * (expR (- rate))%:E).
3985- congr *%E.
3986- rewrite -EFin_lim; last exact: is_cvg_series_exp_coeff.
3987- transitivity (ereal_sup (range (EFin \o (fun n : nat => (\sum_(0 <= k0 < n) rate ^+ k0 / k0`!%:R)%R)))).
3988- apply: cvg_lim => //.
3989- rewrite /esum/series/exp_coeff/=.
3990- apply: ereal_nondecreasing_cvgn.
3991- apply: nondecreasing_series => n _ _.
3992- exact: exp_coeff_ge0.
3993- apply/eqP; rewrite eq_le; apply/andP; split.
3994- apply: le_ereal_sup => _ [n _ <-]/=.
3995- exists `I_n => //.
3996- rewrite -fsbig_ord/=.
3997- rewrite big_mkord.
3998- by rewrite sumEFin.
3999- apply: ub_ereal_sup.
4000- move=> /= e/= [S [fS _] <-].
4001- apply: ereal_sup_ge.
4002- have /finite_fsetP[X SX] := fS.
4003- set N : nat := \max_(x <- X) x.
4004- exists ((\sum_(0 <= k0 < N.+1) rate ^+ k0 / k0`!%:R)%:E) => //.
4005- rewrite fsbig_finite//=.
4006- rewrite -sumEFin.
4007- rewrite [leRHS](_ : _ =
4008- (\sum_(i <- fset_set `I_N.+1) (rate ^+ i / i`!%:R)%:E)%R); last first.
4009- rewrite -Iiota.
4010- rewrite -fsbig_finite//=.
4011- rewrite -fsbig_seq//.
4012- rewrite -/(iota 0 N.+1).
4013- apply: iota_uniq.
4014- apply: lee_sum_nneg_subfset => /=.
4015- apply/subsetP.
4016- move=> n; rewrite 2!inE.
4017- rewrite 2?in_fset_set// 2!inE => Sn/=.
4018- rewrite ltnS.
4019- apply: leq_bigmax_seq => //.
4020- by rewrite SX in Sn.
4021- move=> n _ _.
4022- by rewrite lee_fin mulr_ge0// exprn_ge0.
4023- (* TODO: lemma *)
4024- under [RHS]eq_esum do rewrite mulrC.
4025- rewrite muleC -ereal_sup_pZl; last exact: expR_gt0.
4026- apply/eqP; rewrite eq_le; apply/andP; split => /=.
4027- apply: le_ereal_sup => _ [_ [N fN <-] <-]; exists N => //.
4028- rewrite ge0_mule_fsumr//.
4029- by move=> ?; exact: exp_coeff_ge0.
4030- apply: le_ereal_sup => _ [N fN <-]/=.
4031- exists (\sum_(x1 \in N) (rate ^+ x1 / x1`!%:R)%:E)%R; first by exists N.
4032- rewrite ge0_mule_fsumr//.
4033- by move=> ?; exact: exp_coeff_ge0.
4034- Qed .
4035-
4036- HB.instance Definition _ :=
4037- @Measure_isProbability.Build _ _ R poisson poisson_setT.
4038-
4039- End poisson.
4040-
4041- Lemma measurable_poisson_prob (R : realType) (n : nat) :
4042- measurable_fun setT (poisson_prob ^~ n : R -> pprobability _ _).
4043- Proof .
4044- apply: (@measurability _ _ _ _ _ _
4045- (@pset _ _ _ : set (set (pprobability _ R)))) => //.
4046- move=> _ -[_ [r r01] [Ys mYs <-]] <-; apply: emeasurable_fun_infty_o => //=.
4047- rewrite /poisson_prob/=.
4048- set f := (X in measurable_fun _ X).
4049- apply: measurable_fun_if => //=.
4050- by exact: measurable_fun_ler.
4051- apply: (eq_measurable_fun (fun t =>
4052- \sum_(k <oo | k \in Ys) (poisson_pmf t k)%:E))%E.
4053- move=> x /set_mem[_/= x01].
4054- rewrite nneseries_esum// -1?[in RHS](set_mem_set Ys)// => k kYs.
4055- by rewrite lee_fin poisson_pmf_ge0.
4056- apply: ge0_emeasurable_sum.
4057- by move=> k x/= [_ x01] _; rewrite lee_fin poisson_pmf_ge0.
4058- move=> k Ysk; apply/measurableT_comp => //.
4059- exact: measurable_poisson_pmf.
4060- Qed .
0 commit comments