Skip to contents

This function ensures that the base fit remains within defined vertical bounds by applying penalties if the left or right edge of the base segment exceeds limits.

Usage

base_constraint(y, min_y, poi_y, threshold = 2.3)

Arguments

y

Numeric vector representing the fitted y-values along the base segment.

min_y

Numeric. The minimum y-value in the dataset (used as a lower bound).

poi_y

Numeric. The y-value at the Point of Interest (POI).

threshold

Numeric. The upper y-bound for the base fit. Default is 2.3.

Value

A numeric penalty value:

  • 0 if both edges are within the defined range.

  • A squared penalty if the left or right edges exceed their respective bounds.

Details

  • The function applies constraints separately for the left and right edges of the base segment.

  • The left constraint ensures that the starting y-value remains within [0, threshold].

  • The right constraint ensures that the POI y-value is between [min_y, threshold].

  • If either constraint is violated, a squared penalty is applied to encourage corrections during optimization.

See also

objective_function where this function is used in the optimization process.

Examples

y_values <- c(0.5, 1.2, 2.0)  # Example y-values for the base segment
min_y <- 0.1
poi_y <- 1.8
threshold <- 2.3
base_constraint(y_values, min_y, poi_y, threshold)
#> [1] 0