Enforce Slope Constraints at the Point of Interest (POI)
Source:R/seek_inflection.R
poi_constraints.RdThis function ensures that the slope at the Point of Interest (POI) falls within the specified bounds. It applies different calculations depending on whether the fit is linear or parabolic.
Arguments
- params
A numeric vector containing the model parameters:
For a linear fit:
params[1]is the slope.For a parabolic fit:
params[1](quadratic coefficient) andparams[2](linear coefficient).
- slope_bounds
A numeric vector of length 2 specifying the lower and upper slope limits.
- poi_x
Numeric. The x-coordinate of the Point of Interest.
- fit_type
Character. Specifies the type of fit used. Can be
"linear"or"parabolic".
Value
A numeric value:
0if the computed slope is within bounds.A squared penalty value if the computed slope is outside the allowable range.
Details
If the fit type is
"linear", the slope is taken directly fromparams[1].If the fit type is
"parabolic", the slope at the POI is computed as \(2a \cdot poi_x + b\).The function checks if the computed slope falls within the specified
slope_bounds.If the slope is out of bounds, it applies a squared penalty to encourage corrections during optimization.
See also
objective_function which utilizes this constraint during optimization.
Examples
params_linear <- c(0.5) # Example slope for a linear fit
slope_bounds <- c(0.2, 1.0)
poi_x <- 5
poi_constraints(params_linear, slope_bounds, poi_x, fit_type = "linear")
#> [1] 0
params_parabolic <- c(0.1, 0.5) # Example quadratic and linear coefficients
poi_constraints(params_parabolic, slope_bounds, poi_x, fit_type = "parabolic")
#> [1] 0.25