Skip to main content

soft_sort

pub fn soft_sort<F>(x: &[F], temperature: F) -> OptimizeResult<Vec<F>>
where F: Float + FromPrimitive + Debug + Clone,
Expand description

Compute the soft sort of a vector via regularised isotonic regression.

Returns a non-decreasing sequence of the same length as x. At temperature → 0 this recovers the exact sorted sequence; at high temperature the output approaches the element-wise mean.

Internally uses the Pool Adjacent Violators (PAV) algorithm to solve the isotonic regression:

min_{ŝ non-decreasing} Σ (ŝ_i - s_i)²  +  temperature · regularisation

§Arguments

  • x – input vector.
  • temperature – controls softness (≥ 0; typical values 0.01–1.0).

§Returns

Non-decreasing vector of the same length as x.