Documentation

Linglib.Phonology.HarmonicGrammar.MaxEnt

MaxEnt grammars #

A MaxEnt grammar makes harmonies into probabilities: a candidate whose violation vector is T c has probability proportional to the exponential of its harmony -(w ⬝ᵥ T c). As a measure, the MaxEnt distribution is the counting measure on the candidates tilted by harmony, the exponential family with statistic T and parameter -w. Violations are counts for a constraint set (OptimalityTheory.ConstraintSet.violations) and may be any reals, as when a lexicon scales them.

The name records a duality. Among the distributions of the candidates with the same expected violations as a MaxEnt distribution, the MaxEnt one has the greatest entropy, and no other has as much. The log-likelihood of an empirical distribution is concave in the weights, with gradient the expected less the observed violations, so the weights that maximize it are exactly those whose distribution has the observed expected violations, and the most likely MaxEnt grammar is the maximum-entropy one. A conditional grammar, a Markov kernel from inputs to the MaxEnt distributions of their candidates, satisfies the same duality with conditional entropy, the expected violations averaged over the observed inputs.

Main definitions #

Main results #

Implementation notes #

References #

noncomputable def HarmonicGrammar.logPartition {C : Type u_1} {ι : Type u_2} [Fintype ι] [Fintype C] (T : C → ι → ℝ) (w : ι → ℝ) :
ℝ

The log-partition function, the log of the normalizing constant of the MaxEnt distribution.

Equations
Instances For
    theorem HarmonicGrammar.convexOn_logPartition {C : Type u_1} {ι : Type u_2} [Fintype ι] [Fintype C] (T : C → ι → ℝ) [Nonempty C] :
    ConvexOn ℝ Set.univ (logPartition T)

    The log-partition function is convex in the weights, a log-sum-exp of harmonies linear in them.

    noncomputable def HarmonicGrammar.maxEnt {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] (T : C → ι → ℝ) (w : ι → ℝ) :
    MeasureTheory.Measure C

    The MaxEnt distribution of candidates with violation vectors T under weights w weighs each candidate by the exponential of its harmony.

    Equations
    Instances For
      theorem HarmonicGrammar.maxEnt_congr {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] {ι' : Type u_3} [Fintype ι'] {T : C → ι → ℝ} {w : ι → ℝ} {T' : C → ι' → ℝ} {w' : ι' → ℝ} (h : harmony T w = harmony T' w') :
      maxEnt T w = maxEnt T' w'

      A MaxEnt distribution depends on the violations and weights only through the harmonies.

      noncomputable def HarmonicGrammar.logLikelihood {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] (T : C → ι → ℝ) (p : MeasureTheory.Measure C) (w : ι → ℝ) :
      ℝ

      The log-likelihood of an empirical distribution p under a grammar is the expected log-probability of the candidates drawn from p.

      Equations
      Instances For
        @[simp]
        theorem HarmonicGrammar.logLikelihood_dirac {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (c : C) :
        logLikelihood T (MeasureTheory.Measure.dirac c) w = Real.log ((maxEnt T w).real {c})

        The log-likelihood of a single observation is its log-probability.

        instance HarmonicGrammar.instIsZeroOrProbabilityMeasureMaxEnt {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] (T : C → ι → ℝ) (w : ι → ℝ) :
        MeasureTheory.IsZeroOrProbabilityMeasure (maxEnt T w)
        instance HarmonicGrammar.instIsProbabilityMeasureMaxEntOfNonempty {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] :
        MeasureTheory.IsProbabilityMeasure (maxEnt T w)
        theorem HarmonicGrammar.integral_eq_sum {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (q : MeasureTheory.Measure C) [MeasureTheory.IsFiniteMeasure q] :
        ∫ (c : C), T c ∂q = ∑ c : C, q.real {c} • T c

        On finitely many candidates the expected violation vector is a weighted sum.

        Probabilities #

        theorem HarmonicGrammar.maxEnt_real_singleton {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (c : C) :
        (maxEnt T w).real {c} = Real.softmax (harmony T w) c
        theorem HarmonicGrammar.maxEnt_singleton {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (c : C) :
        (maxEnt T w) {c} = ENNReal.ofReal (Real.softmax (harmony T w) c)
        theorem HarmonicGrammar.maxEnt_real_singleton_pos {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (c : C) :
        0 < (maxEnt T w).real {c}
        theorem HarmonicGrammar.absolutelyContinuous_maxEnt {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (q : MeasureTheory.Measure C) :
        q.AbsolutelyContinuous (maxEnt T w)

        Every candidate has positive probability, so every distribution of the candidates is absolutely continuous with respect to the MaxEnt distribution.

        theorem HarmonicGrammar.log_maxEnt_real_singleton {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (c : C) :
        Real.log ((maxEnt T w).real {c}) = harmony T w c - logPartition T w

        Harmony is log-probability up to the log of the normalizing constant.

        theorem HarmonicGrammar.log_maxEnt_real_singleton_div {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (a b : C) :
        Real.log ((maxEnt T w).real {a} / (maxEnt T w).real {b}) = harmony T w a - harmony T w b

        The log-odds of two candidates are their harmony difference, -(w ⬝ᵥ (T a - T b)), linear in the weights.

        theorem HarmonicGrammar.maxEnt_real_singleton_lt_iff {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) {a b : C} :
        (maxEnt T w).real {a} < (maxEnt T w).real {b} ↔ harmony T w a < harmony T w b
        theorem HarmonicGrammar.maxEnt_real_singleton_le_iff {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) {a b : C} :
        (maxEnt T w).real {a} ≤ (maxEnt T w).real {b} ↔ harmony T w a ≤ harmony T w b
        theorem HarmonicGrammar.maxEnt_real_singleton_of_pair {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [DecidableEq C] {a b : C} (hab : a ≠ b) (h : Finset.univ = {a, b}) :
        (maxEnt T w).real {a} = (harmony T w a - harmony T w b).sigmoid

        Of exactly two candidates, one has the sigmoid of its harmony advantage over the other.

        theorem HarmonicGrammar.tendsto_maxEnt_smul_atTop {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) {c : C} (h : ∀ (c' : C), c' ≠ c → harmony T w c' < harmony T w c) :
        Filter.Tendsto (fun (α : ℝ) => (maxEnt T (α • w)).real {c}) Filter.atTop (nhds 1)

        Scaling the weights scales the harmonies, so the MaxEnt distribution concentrates on a candidate of strictly greatest harmony.

        Expected log-probability #

        theorem HarmonicGrammar.integral_log_maxEnt_real_singleton {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (q : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure q] :
        ∫ (c : C), Real.log ((maxEnt T w).real {c}) ∂q = -(w ⬝ᵥ ∫ (c : C), T c ∂q) - logPartition T w

        The expected log-probability of the candidates under a distribution q depends on q only through its expected violations.

        theorem HarmonicGrammar.logLikelihood_eq {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (p : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure p] :
        logLikelihood T p w = -(w ⬝ᵥ ∫ (c : C), T c ∂p) - logPartition T w

        The maximum entropy principle #

        theorem HarmonicGrammar.toReal_klDiv_maxEnt_add_measureEntropy {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] (q : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure q] :
        (InformationTheory.klDiv q (maxEnt T w)).toReal + InformationTheory.measureEntropy q = w ⬝ᵥ ∫ (c : C), T c ∂q + logPartition T w

        The divergence of q from the MaxEnt distribution and the entropy of q add up to the expected penalty w ⬝ᵥ ∫ c, T c ∂q plus the log of the normalizing constant.

        theorem HarmonicGrammar.measureEntropy_maxEnt {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] :
        InformationTheory.measureEntropy (maxEnt T w) = w ⬝ᵥ ∫ (c : C), T c ∂maxEnt T w + logPartition T w
        theorem HarmonicGrammar.measureEntropy_add_toReal_klDiv_maxEnt {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] {q : MeasureTheory.Measure C} [MeasureTheory.IsProbabilityMeasure q] (hq : ∫ (c : C), T c ∂q = ∫ (c : C), T c ∂maxEnt T w) :
        InformationTheory.measureEntropy q + (InformationTheory.klDiv q (maxEnt T w)).toReal = InformationTheory.measureEntropy (maxEnt T w)

        A distribution with the expected violations of a MaxEnt distribution falls short of its entropy by its divergence from it.

        theorem HarmonicGrammar.measureEntropy_le_maxEnt {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] {q : MeasureTheory.Measure C} [MeasureTheory.IsProbabilityMeasure q] (hq : ∫ (c : C), T c ∂q = ∫ (c : C), T c ∂maxEnt T w) :

        The maximum entropy principle. No distribution with the expected violations of a MaxEnt distribution has more entropy.

        theorem HarmonicGrammar.eq_maxEnt_of_measureEntropy_eq {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] {q : MeasureTheory.Measure C} [MeasureTheory.IsProbabilityMeasure q] (hq : ∫ (c : C), T c ∂q = ∫ (c : C), T c ∂maxEnt T w) (h : InformationTheory.measureEntropy q = InformationTheory.measureEntropy (maxEnt T w)) :
        q = maxEnt T w

        The MaxEnt distribution is the only distribution with its expected violations and its entropy.

        theorem HarmonicGrammar.isGreatest_measureEntropy_maxEnt {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] :
        IsGreatest (InformationTheory.measureEntropy '' {q : MeasureTheory.Measure C | MeasureTheory.IsProbabilityMeasure q ∧ ∫ (c : C), T c ∂q = ∫ (c : C), T c ∂maxEnt T w}) (InformationTheory.measureEntropy (maxEnt T w))

        The MaxEnt distribution has the greatest entropy among the distributions with its expected violations.

        Learning #

        theorem HarmonicGrammar.hasFDerivAt_logPartition {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) [Nonempty C] :
        HasFDerivAt (logPartition T) (-LinearMap.toContinuousLinearMap ((dotProductBilin ℝ ℝ) (∫ (c : C), T c ∂maxEnt T w))) w

        The gradient of the log-partition function is minus the expected violation vector.

        theorem HarmonicGrammar.concaveOn_logLikelihood {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (p : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure p] [Nonempty C] :
        ConcaveOn ℝ Set.univ (logLikelihood T p)

        The log-likelihood is concave in the weights: it is linear in them less the log-partition function.

        theorem HarmonicGrammar.hasFDerivAt_logLikelihood {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (p : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure p] [Nonempty C] :
        HasFDerivAt (logLikelihood T p) (LinearMap.toContinuousLinearMap ((dotProductBilin ℝ ℝ) (∫ (c : C), T c ∂maxEnt T w - ∫ (c : C), T c ∂p))) w

        The gradient of the log-likelihood is the expected less the observed violation vector.

        theorem HarmonicGrammar.hasDerivAt_logLikelihood_update {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (p : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure p] [Nonempty C] [DecidableEq ι] (j : ι) :
        HasDerivAt (fun (t : ℝ) => logLikelihood T p (Function.update w j t)) ((∫ (c : C), T c ∂maxEnt T w) j - (∫ (c : C), T c ∂p) j) (w j)

        The partial derivative of the log-likelihood in the weight of constraint j is that constraint's expected violations less its observed ones.

        theorem HarmonicGrammar.isMaxOn_logLikelihood_iff {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (p : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure p] [Nonempty C] :
        IsMaxOn (logLikelihood T p) Set.univ w ↔ ∫ (c : C), T c ∂maxEnt T w = ∫ (c : C), T c ∂p

        Weights maximize the log-likelihood exactly when their MaxEnt distribution has the observed expected violations.

        theorem HarmonicGrammar.isGreatest_measureEntropy_of_isMaxOn {C : Type u_1} {ι : Type u_2} [Fintype ι] [MeasurableSpace C] [Fintype C] [MeasurableSingletonClass C] (T : C → ι → ℝ) (w : ι → ℝ) (p : MeasureTheory.Measure C) [MeasureTheory.IsProbabilityMeasure p] [Nonempty C] (h : IsMaxOn (logLikelihood T p) Set.univ w) :
        IsGreatest (InformationTheory.measureEntropy '' {q : MeasureTheory.Measure C | MeasureTheory.IsProbabilityMeasure q ∧ ∫ (c : C), T c ∂q = ∫ (c : C), T c ∂p}) (InformationTheory.measureEntropy (maxEnt T w))

        The most likely MaxEnt grammar of an empirical distribution gives the maximum-entropy distribution among those with the observed expected violations.

        Joint evaluation #

        theorem HarmonicGrammar.maxEnt_sum {ι : Type u_2} [Fintype ι] (w : ι → ℝ) {κ : Type u_3} {O : Type u_4} [Fintype κ] [DecidableEq κ] [Fintype O] [MeasurableSpace O] [MeasurableSingletonClass O] [Nonempty O] (T : κ → O → ι → ℝ) :
        maxEnt (fun (f : κ → O) => ∑ k : κ, T k (f k)) w = MeasureTheory.Measure.pi fun (k : κ) => maxEnt (T k) w

        When the violations of an output tuple add up its coordinates' violations, the MaxEnt distribution of the tuples is the product of the coordinates' MaxEnt distributions, so the coordinates are independent.

        theorem HarmonicGrammar.map_eval_maxEnt_sum {ι : Type u_2} [Fintype ι] (w : ι → ℝ) {κ : Type u_3} {O : Type u_4} [Fintype κ] [DecidableEq κ] [Fintype O] [MeasurableSpace O] [MeasurableSingletonClass O] [Nonempty O] (T : κ → O → ι → ℝ) (k : κ) :
        MeasureTheory.Measure.map (Function.eval k) (maxEnt (fun (f : κ → O) => ∑ k : κ, T k (f k)) w) = maxEnt (T k) w

        The marginal of such a distribution at a coordinate is that coordinate's MaxEnt distribution.

        Conditional MaxEnt #

        noncomputable def HarmonicGrammar.condMaxEnt {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) :
        ProbabilityTheory.Kernel X Y

        The conditional MaxEnt grammar takes each input to the MaxEnt distribution of its candidates, whose violation vectors are T (x, ·).

        Equations
        Instances For
          @[simp]
          theorem HarmonicGrammar.condMaxEnt_apply {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) (x : X) :
          (condMaxEnt T w) x = maxEnt (fun (y : Y) => T (x, y)) w
          noncomputable def HarmonicGrammar.condLogLikelihood {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (p : MeasureTheory.Measure (X × Y)) (w : ι → ℝ) :
          ℝ

          The conditional log-likelihood of an empirical distribution p of input–output pairs is the expected log-probability of each output given its input.

          Equations
          Instances For
            theorem HarmonicGrammar.condLogLikelihood_eq {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] (p : MeasureTheory.Measure (X × Y)) [MeasureTheory.IsProbabilityMeasure p] :
            condLogLikelihood T p w = -(w ⬝ᵥ ∫ (z : X × Y), T z ∂p) - ∑ x : X, p.fst.real {x} * logPartition (fun (y : Y) => T (x, y)) w
            instance HarmonicGrammar.instIsMarkovKernelCondMaxEnt {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] [Nonempty Y] :
            ProbabilityTheory.IsMarkovKernel (condMaxEnt T w)
            theorem HarmonicGrammar.sum_toReal_klDiv_condMaxEnt_add_condEntropy {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] [Nonempty Y] (ν : MeasureTheory.Measure X) [MeasureTheory.IsProbabilityMeasure ν] (q : ProbabilityTheory.Kernel X Y) [ProbabilityTheory.IsMarkovKernel q] :
            ∑ x : X, ν.real {x} * (InformationTheory.klDiv (q x) ((condMaxEnt T w) x)).toReal + InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd q) = w ⬝ᵥ ∫ (z : X × Y), T z ∂ν.compProd q + ∑ x : X, ν.real {x} * logPartition (fun (y : Y) => T (x, y)) w

            Averaged over inputs drawn from ν, the divergence of a conditional model q from the conditional MaxEnt grammar and the conditional entropy of q add up to the expected penalty plus the average log-partition function.

            theorem HarmonicGrammar.condEntropy_condMaxEnt {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] [Nonempty Y] (ν : MeasureTheory.Measure X) [MeasureTheory.IsProbabilityMeasure ν] :
            InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd (condMaxEnt T w)) = w ⬝ᵥ ∫ (z : X × Y), T z ∂ν.compProd (condMaxEnt T w) + ∑ x : X, ν.real {x} * logPartition (fun (y : Y) => T (x, y)) w

            The conditional entropy of the conditional MaxEnt grammar.

            theorem HarmonicGrammar.condEntropy_add_sum_toReal_klDiv {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] [Nonempty Y] (ν : MeasureTheory.Measure X) [MeasureTheory.IsProbabilityMeasure ν] {q : ProbabilityTheory.Kernel X Y} [ProbabilityTheory.IsMarkovKernel q] (hq : ∫ (z : X × Y), T z ∂ν.compProd q = ∫ (z : X × Y), T z ∂ν.compProd (condMaxEnt T w)) :
            InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd q) + ∑ x : X, ν.real {x} * (InformationTheory.klDiv (q x) ((condMaxEnt T w) x)).toReal = InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd (condMaxEnt T w))

            A conditional model with the expected violations of a conditional MaxEnt grammar falls short of its conditional entropy by its average divergence from it.

            theorem HarmonicGrammar.condEntropy_le_condMaxEnt {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] [Nonempty Y] (ν : MeasureTheory.Measure X) [MeasureTheory.IsProbabilityMeasure ν] {q : ProbabilityTheory.Kernel X Y} [ProbabilityTheory.IsMarkovKernel q] (hq : ∫ (z : X × Y), T z ∂ν.compProd q = ∫ (z : X × Y), T z ∂ν.compProd (condMaxEnt T w)) :
            InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd q) ≤ InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd (condMaxEnt T w))

            The conditional maximum entropy principle. No conditional model whose expected violations, averaged over the inputs, are those of a conditional MaxEnt grammar has more conditional entropy.

            theorem HarmonicGrammar.eq_condMaxEnt_of_condEntropy_eq {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] [Nonempty Y] (ν : MeasureTheory.Measure X) [MeasureTheory.IsProbabilityMeasure ν] {q : ProbabilityTheory.Kernel X Y} [ProbabilityTheory.IsMarkovKernel q] (hq : ∫ (z : X × Y), T z ∂ν.compProd q = ∫ (z : X × Y), T z ∂ν.compProd (condMaxEnt T w)) (h : InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd q) = InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd (condMaxEnt T w))) {x : X} (hx : ν {x} ≠ 0) :
            q x = (condMaxEnt T w) x

            A conditional model with those expected violations and that conditional entropy is the conditional MaxEnt grammar at every input of positive mass.

            theorem HarmonicGrammar.isGreatest_condEntropy_condMaxEnt {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] [Nonempty Y] (ν : MeasureTheory.Measure X) [MeasureTheory.IsProbabilityMeasure ν] :
            IsGreatest ((fun (q : ProbabilityTheory.Kernel X Y) => InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd q)) '' {q : ProbabilityTheory.Kernel X Y | ProbabilityTheory.IsMarkovKernel q ∧ ∫ (z : X × Y), T z ∂ν.compProd q = ∫ (z : X × Y), T z ∂ν.compProd (condMaxEnt T w)}) (InformationTheory.condEntropy Prod.snd Prod.fst (ν.compProd (condMaxEnt T w)))

            The conditional MaxEnt grammar has the greatest conditional entropy among the conditional models with its average expected violations.

            theorem HarmonicGrammar.concaveOn_condLogLikelihood {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] (p : MeasureTheory.Measure (X × Y)) [MeasureTheory.IsProbabilityMeasure p] [Nonempty Y] :
            ConcaveOn ℝ Set.univ (condLogLikelihood T p)

            The conditional log-likelihood is concave in the weights.

            theorem HarmonicGrammar.hasFDerivAt_condLogLikelihood {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] (p : MeasureTheory.Measure (X × Y)) [MeasureTheory.IsProbabilityMeasure p] [Nonempty Y] :
            HasFDerivAt (condLogLikelihood T p) (LinearMap.toContinuousLinearMap ((dotProductBilin ℝ ℝ) (∫ (z : X × Y), T z ∂p.fst.compProd (condMaxEnt T w) - ∫ (z : X × Y), T z ∂p))) w

            The gradient of the conditional log-likelihood is the expected less the observed violation vector, the expectation taken over the observed inputs.

            theorem HarmonicGrammar.isMaxOn_condLogLikelihood_iff {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] (p : MeasureTheory.Measure (X × Y)) [MeasureTheory.IsProbabilityMeasure p] [Nonempty Y] :
            IsMaxOn (condLogLikelihood T p) Set.univ w ↔ ∫ (z : X × Y), T z ∂p.fst.compProd (condMaxEnt T w) = ∫ (z : X × Y), T z ∂p

            Weights maximize the conditional log-likelihood exactly when the expected violations of their grammar, over the observed inputs, are the observed ones.

            theorem HarmonicGrammar.condLogLikelihood_eq_neg_condEntropy {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] (p : MeasureTheory.Measure (X × Y)) [MeasureTheory.IsProbabilityMeasure p] [Nonempty Y] (h : ∫ (z : X × Y), T z ∂p.fst.compProd (condMaxEnt T w) = ∫ (z : X × Y), T z ∂p) :
            condLogLikelihood T p w = -InformationTheory.condEntropy Prod.snd Prod.fst (p.fst.compProd (condMaxEnt T w))

            At weights matching the observed violations the conditional log-likelihood is minus the conditional entropy of the grammar, the common value of the two dual problems.

            theorem HarmonicGrammar.isGreatest_condEntropy_of_isMaxOn {ι : Type u_2} [Fintype ι] {X : Type u_3} {Y : Type u_4} [Fintype X] [MeasurableSpace X] [MeasurableSingletonClass X] [MeasurableSpace Y] (T : X × Y → ι → ℝ) (w : ι → ℝ) [Fintype Y] [MeasurableSingletonClass Y] (p : MeasureTheory.Measure (X × Y)) [MeasureTheory.IsProbabilityMeasure p] [Nonempty Y] (h : IsMaxOn (condLogLikelihood T p) Set.univ w) :
            IsGreatest ((fun (q : ProbabilityTheory.Kernel X Y) => InformationTheory.condEntropy Prod.snd Prod.fst (p.fst.compProd q)) '' {q : ProbabilityTheory.Kernel X Y | ProbabilityTheory.IsMarkovKernel q ∧ ∫ (z : X × Y), T z ∂p.fst.compProd q = ∫ (z : X × Y), T z ∂p}) (InformationTheory.condEntropy Prod.snd Prod.fst (p.fst.compProd (condMaxEnt T w)))

            The most likely conditional MaxEnt grammar of an empirical distribution has the greatest conditional entropy among the conditional models with the observed expected violations.