Optimal cost-constrained stratified sampling allocation (source code)

= Optimal cost-constrained stratified sampling allocation
{title2=$x_i^*=\frac bA\sqrt{v_i/a_i},\quad A=\sum_i\sqrt{a_iv_i}$}

Suppose the <variance> is $\sum_i v_i/x_i$ and the sampling cost is $\sum_i a_ix_i\leq b$, with positive costs, variance coefficients and budget. The <Cauchy-Schwarz inequality> gives $A^2\leq(\sum_i v_i/x_i)(\sum_i a_ix_i)\leq b\sum_i v_i/x_i$. Equality forces $x_i$ proportional to $\sqrt{v_i/a_i}$ and a tight budget, proving the displayed unique optimum. The minimal variance is $A^2/b$. For the <optimization Lagrangian> $f-\lambda(\sum_i a_ix_i-b)$, the multiplier and budget derivative both equal $-A^2/b^2$. Therefore a small resource change $\delta b$ changes the optimum by $\lambda\delta b+O((\delta b)^2)$. This is a continuous allocation; integer sample-size restrictions define a separate optimization problem.