Skip to content

Certainty degree

CertaintyDegree · experimental

Experimental

CertaintyDegree is an estimator under development, without a published reference. It is documented for completeness; do not use it as your only or main estimator yet.

The certainty degree reserves mass for unseen elements according to how plausible it is that the sample has already covered the support.

Definition

With \(N\) observations of \(V\) distinct elements and a support of \(B\) elements (bins, \(V\) by default), the mass reserved for unseen elements is

\[ p_0 = \max\!\Big(\big(\tfrac{V}{B + 1}\big)^{N},\ \texttt{unobs\_prob}\Big), \]

the probability that \(N\) draws from \(B + 1\) equally likely elements all fall among the \(V\) observed ones. The observed elements share the rest in proportion to their counts, \(P(w) = (1 - p_0)\,c(w)/N\), and each unseen element scores \(p_0\).

Example

With the example counts:

>>> import freqprob
>>> counts = dict(the=10, cat=5, sat=4, on=3, mat=2, a=2, dog=1, ran=1, far=1, away=1)
>>> cd = freqprob.CertaintyDegree(counts, logprob=False)
>>> [round(cd(w), 4) for w in ("the", "dog", "zebra")]
[0.3142, 0.0314, 0.0573]
>>> round(freqprob.CertaintyDegree(counts, bins=100, logprob=False)("zebra"), 6)
0.0

With the default support, \(p_0 = (10/11)^{30} \approx 0.057\). Declaring a support of 100 elements makes \(p_0\) vanish: if the 30 observations had been spread over 101 equally likely elements, finding only ten of them would be very unlikely.

Properties

  • Shrinks quickly with \(N\): the reserved mass falls exponentially with the number of observations.
  • A larger bins reserves less mass, unlike the additive methods, because it makes the observed concentration on few elements more telling.
  • The unseen score is per element, as for unobs_prob in MLE (see Pitfalls).

API

freqprob.CertaintyDegree

CertaintyDegree(freqdist: FrequencyDistribution, bins: int | None = None, unobs_prob: Probability = 0.0, logprob: bool = True)

Bases: ScoringMethod

Certainty-degree smoothing.

Reserves probability mass for unseen elements based on the degree of certainty that no unobserved samples remain, derived from the number of observations relative to the support size. As more of the possible bins are observed, the reserved mass shrinks; the remaining mass rescales the Maximum-Likelihood estimate of each observed element.

Parameters:

Name Type Description Default
freqdist FrequencyDistribution

Mapping of elements to observed counts.

required
bins int | None

Optional total number of possible sample bins for the experiment. If None (the default), it defaults to the number of observed types.

None
unobs_prob Probability

Reserved probability mass for unobserved states (0.0 <= unobs_prob <= 1.0). Defaults to 0.0.

0.0
logprob bool

Return log-probabilities if True (the default), otherwise plain probabilities. Counts are corrected to avoid domain errors when taking logarithms.

True

Examples:

Observed elements are rescaled by the computed certainty mass, and the remainder is reserved for unseen elements:

>>> from freqprob import CertaintyDegree
>>> freqdist = {"apple": 8, "banana": 4, "cherry": 2, "date": 1}
>>> cd = CertaintyDegree(freqdist, logprob=False)
>>> round(cd("apple"), 3)
0.515
>>> round(cd("date"), 3)
0.064
>>> round(cd("kiwi"), 3)  # unobserved
0.035
Note

This is an experimental distribution under development by Tiago Tresoldi; it should not be used as the sole or main distribution yet.

Initialize Certainty Degree estimation.

References

No published reference; see References.