Built matrix of interval costs for held-out linear models. One indexed.

lin_costs(x, y, w, min_seg, indices)

Arguments

x

NumericVector, x-coords of values to group.

y

NumericVector, values to group in order.

w

NumericVector, weights.

min_seg

positive integer, minimum segment size (>=1).

indices

IntegerVector, ordered list of indices to pair.

Value

xcosts NumericMatix, for j>=i xcosts(i,j) is the cost of partition element [i,...,j] (inclusive).

Examples

lin_costs(c(1, 2, 3, 4), c(1, 2, 2, 1), c(1, 1, 1, 1), 1, 1:4)
#> [,1] [,2] [,3] [,4] #> [1,] 1.797693e+308 5.000038e-01 2.250203e+00 6.576132e+00 #> [2,] 5.000038e-01 1.797693e+308 3.611067e-01 2.250398e+00 #> [3,] 2.250203e+00 3.611067e-01 1.797693e+308 3.043395e+00 #> [4,] 6.576132e+00 2.250398e+00 3.043395e+00 1.797693e+308