Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions smr_alignment/src/smr_alignment/metric_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ def optimize_weights(
loss = cp.sum(cp.pos(margins)) # piecewise-linear convex

if entropy_lambda > 0:
# cp.entr(x) = x*log(x); we add small offset to keep it defined near zero
loss += entropy_lambda * cp.sum(cp.entr(w + 1e-16))
# we add small offset to keep it defined near zero
n = len(metrics)
u = np.full(n, 1.0 / n)
loss += entropy_lambda * cp.sum_squares(w - u)

constraints = [cp.sum(w) == 1.0] # cp.sum(w) == 1.0 in CVXPY doesn’t return a plain bool at runtime,
# it returns a Constraint object, confusing type checkers. Therefore, the "type: ignore" below.
Expand Down