Skip to content

Add missing nonnegativity constraint to variational SoftmaxAllocator (#70) - #153

Open
huuan26 wants to merge 1 commit into
jankrepl:masterfrom
huuan26:fix/variational-softmax-constraint-70
Open

huuan26 wants to merge 1 commit into
jankrepl:masterfrom
huuan26:fix/variational-softmax-constraint-70

Conversation

@huuan26

@huuan26 huuan26 commented Oct 18, 2026

Copy link
Copy Markdown

Summary

Adds the missing nonnegativity constraint $w \ge 0$ to the variational formulation of SoftmaxAllocator in deepdow/layers/allocate.py, resolving #70.

Mathematical Formulation & Changes

  • Variational Softmax Optimization Problem:
    The constrained variational softmax formulation solves the convex optimization problem over the clipped probability simplex:
$$\min_{w \in \mathbb{R}^{N}} \quad -x^{\top} w + \sum_{i=1}^{N} w_{i} \log(w_{i}) \quad \text{subject to} \quad \sum_{i=1}^{N} w_{i} = 1, \quad 0 \le w_{i} \le w_{\max}$$
  • Explicit Nonnegativity Constraint (deepdow/layers/allocate.py):
    • Updated the constraint list in SoftmaxAllocator.__init__ (when formulation="variational") from cons = [cp.sum(w) == 1.0, w <= max_weight] to cons = [cp.sum(w) == 1.0, w >= 0.0, w <= max_weight], matching the documented formulation in docs/source/layers.rst as well as SparsemaxAllocator, NumericalMarkowitz, and NumericalRiskBudgeting.
    • Ensures the underlying CvxpyLayer conic program includes all $2N$ linear inequality constraints ($w \ge 0$ and $w \le w_{\max}$).

Testing

  • Added TestSoftmax.test_variational_nonnegativity_constraint in tests/test_layers.py:
    • Verifies that the compiled CvxpyLayer linear inequality cone dimension equals $2N$ (layer.layer.cone_dims["l"] == 2 * n_assets).
    • Verifies that forward allocations satisfy $0 \le w_{i} \le w_{\max}$ and $\sum_{i=1}^{N} w_{i} = 1$ (within solver tolerance) and produce finite gradients on backward pass across multiple n_assets and max_weight configurations.

Fixes #70

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variational softmax is missing a constraint

1 participant