User-Specified Loss Function
Specification of a differentiable convex loss function.
fSolver(z, a, extra)
z
: Vector containing observed responsea
: Matrix with active constraintsextra
: List with element fobj
containing the target function and gobj
with the first derivativeThis function is called internally in activeSet
by setting mySolver = fSolver
. It uses optim()
with "BFGS"
for optimization.
x: Vector containing the fitted values
lbd: Vector with Lagrange multipliers
f: Value of the target function
gx: Gradient at point x
activeSet
##Fitting isotone regression using active set (L2-norm user-specified) set.seed(12345) y <- rnorm(9) ##response values w <- rep(1,9) ##unit weights btota <- cbind(1:8, 2:9) ##Matrix defining isotonicity (total order) fit.convex <- activeSet(btota, fSolver, fobj = function(x) sum(w*(x-y)^2), gobj = function(x) 2*drop(w*(x-y)), y = y, weights = w)