How this calculation works
Find the maximum-Shannon-entropy probability distribution on a finite support subject to entered moment constraints. Each support row supplies feature values, and the target vector specifies their required expectations. The solver uses an exponential-family dual with moment-matching diagnostics. It supports resolved interior solutions and rejects redundant, infeasible or boundary cases rather than returning an undocumented regularized distribution.
Maximize −Σp_i log p_i subject to Σp_i=1 and Σp_i f_i=m.A worked example
For support values zero, one and two with required mean one, the uniform probabilities (1/3,1/3,1/3) meet the constraint and maximize entropy. Entropy is log(3) nats. A fitted exponential-family parameter describes this constraint solution, not an observed data likelihood.
Good to know
2–30 support rows and 1–3 nonconstant independent feature columns. Interior exponential-family Newton solve with line search. Boundary, infeasible, redundant or unresolved constraints rejected without a fabricated distribution. Discrete entropy in nats, not differential entropy.
The support must be specified first
Each row represents a distinct possible outcome, even when two rows have identical feature values. The resulting probabilities are assigned to those labeled outcomes.
Entropy is measured relative to counting measure on this finite support. Splitting one outcome into several rows changes that measure and can change the answer. Do not treat the row list as a harmless plotting grid for a continuous distribution without accounting for how discretization changes the optimization problem.
Solves for unknown probabilities from constraints; an entropy calculator only evaluates probabilities already supplied. The Entropy regularized optimal transport calculator from a cost matrix offers a complementary calculation under its own stated assumptions.
Moment constraints are linear in probabilities
For each feature column, the weighted sum of its values must equal the corresponding target. Probabilities must also sum to one, so do not add a constant normalization column.
A target must lie in the convex hull of the feature rows to be feasible. Constant or redundant feature columns can make the dual Hessian singular even when the primal constraints describe a sensible distribution. The supported solver expects an independently informative, numerically resolved interior problem.
Worked example and mathematical rule
For support values zero, one and two with required mean one, the uniform probabilities (1/3,1/3,1/3) meet the constraint and maximize entropy. Entropy is log(3) nats. A fitted exponential-family parameter describes this constraint solution, not an observed data likelihood.
Maximize −Σp_i log p_i subject to Σp_i=1 and Σp_i f_i=m.
Why an exponential family appears
Lagrange multipliers give probabilities proportional to the exponential of a linear combination of feature values. Normalization is handled through a log-sum-exp expression, which avoids direct overflow.
The dual gradient is the mismatch between model and target moments, and its Hessian is the feature covariance. Newton steps with line search seek zero mismatch. Multipliers are optimization parameters; their signs depend on the stated convention and are not probabilities or causal effects.
Interior and boundary solutions differ
A boundary target may force some probabilities to zero. Its maximum-entropy distribution can exist even though finite exponential-family multipliers do not.
This implementation reports that limitation instead of claiming no mathematical solution exists. Near-boundary targets can produce very large multipliers and weak numerical conditioning. A rejection should therefore be read as outside the supported resolved interior fit, not automatically as a proof that the moment constraints are inconsistent.
Interpreting entropy and residuals
Shannon entropy uses natural logarithms and is reported in nats. With no informative preference among otherwise unconstrained labeled outcomes, the uniform distribution maximizes it.
Moment restrictions generally lower the feasible maximum. The residual measures agreement with the entered expectations, not statistical fit to observed frequencies. Maximum entropy selects a distribution under stated constraints; it does not establish that nature follows that distribution or quantify uncertainty in estimated target moments.
Checking a constructed distribution
Confirm nonnegative probabilities, unit total and each displayed weighted moment. Change one target within the feasible region to see how the distribution reallocates mass.
Rescaling a feature and its target consistently should preserve probabilities while changing its multiplier units. If the intended reference distribution is nonuniform, minimizing relative entropy is a different formulation and should not be replaced silently by this uniform-reference Shannon problem. Keep support labels, features and target precision with the result.
A few questions, answered
Why omit a constant feature?
Normalization is already enforced, and a constant column makes the dual redundant.
Does a rejected boundary case have no solution?
Not necessarily. A valid distribution with zero probabilities can lie outside this interior solver.
What units are used for entropy?
Nats, because logarithms are natural.
Can duplicate feature rows matter?
Yes. They remain distinct labeled support outcomes and affect the counting measure.