/// Get the analytical minimum of a cubic fit to two input bounds.
/// Becomes numerically unstable as the third-order coefficient approaches 0.
// FIXME: In my tests I'm not actually seeing that this becomes particularly unstable;
//        it tends to produce either NaN, or something with about the same magnitude
//        as the quadratic minimum x value. (I was expecting to see extreme-but-normal values appear)
Get the analytical minimum of a cubic fit to two input bounds.
Becomes numerically unstable as the third-order coefficient approaches 0.
FIXME: In my tests I'm not actually seeing that this becomes particularly unstable;
it tends to produce either NaN, or something with about the same magnitude
as the quadratic minimum x value. (I was expecting to see extreme-but-normal values appear)
Get the analytical minimum of a cubic fit to two input bounds . Becomes numerically unstable as the third - order coefficient approaches 0 . FIXME : In my tests I ' m not actually seeing that this becomes particularly unstable ; it tends to produce either NaN or something with about the same magnitude as the quadratic minimum x value . ( I was expecting to see extreme - but - normal values appear )
fn cubic_min(low: Bound, high: Bound) -> f64
{
    let d_value = high.value - low.value;
    let d_alpha = high.alpha - low.alpha;
    let d_alpha2 = d_alpha * d_alpha;
    let d_alpha3 = d_alpha * d_alpha2;
    // get cubic coefficients
    // f(x) = ax^3 + bx^2 + cx + d
    let a = ((high.slope + low.slope) * d_alpha - 2.0 * d_value) / d_alpha3;
    let b = (3.0 * d_value - (high.slope + 2.0 * low.slope) * d_alpha) / d_alpha2;
    let c = low.slope;
    // The derivative of f has two roots.
    // For real a, b, c, the + root is always the minimum
    low.alpha + ((b * b - 3.0 * a * c).sqrt() - b) / (3.0 * a)
}
fn cubic_min ( low : Bound , high : Bound ) -> f64 { let d_value = high . value - low . value ; let d_alpha = high . alpha - low . alpha ; let d_alpha2 = d_alpha * d_alpha ; let d_alpha3 = d_alpha * d_alpha2 ; // get cubic coefficients // f(x) = ax^3 + bx^2 + cx + d let a = ( ( high . slope + low . slope ) * d_alpha - 2.0 * d_value ) / d_alpha3 ; let b = ( 3.0 * d_value - ( high . slope + 2.0 * low . slope ) * d_alpha ) / d_alpha2 ; let c = low . slope ; // The derivative of f has two roots. // For real a, b, c, the + root is always the minimum low . alpha + ( ( b * b - 3.0 * a * c ) . sqrt ( ) - b ) / ( 3.0 * a ) }
Get the analytical minimum of a cubic fit to two input bounds.
Get the analytical minimum of a cubic fit to two input bounds .
low
Bound
high
Bound