Skip to content

Add scaling factor#5

Open
lmanan wants to merge 1 commit intomainfrom
scale-features-and-costs
Open

Add scaling factor#5
lmanan wants to merge 1 commit intomainfrom
scale-features-and-costs

Conversation

@lmanan
Copy link
Copy Markdown

@lmanan lmanan commented Mar 30, 2026

Normalize features and costs by a common scaling factor before solving

The soft margin loss optimizer can suffer from numerical instability when features and cost coefficients operate at very different scales. This PR introduces a scaling factor to normalize them before the MIP solver runs.

Changes:

  • LinearCosts: add set_scaling_factor / get_scaling_factor methods
  • HammingCosts: set scaling factor to the number of active variables (i.e. sum(mask) if a mask is provided, else n)
  • SoftMarginLoss: divide _b, _g, and _features by the scaling factor before optimization, and use the scaled features when computing the gradient
  • SoftMarginLoss.value_and_gradient: explicitly add the constant term a + b back to the solver's return value, since get_value() excludes it

@lmanan lmanan requested a review from funkey March 30, 2026 20:17
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.

1 participant