Learn R Programming

bmrm (version 3.3)

ontologyLoss: Ontology Loss Function

Description

Ontology loss function may be used when the class labels are organized has an ontology structure

Usage

ontologyLoss(x, y, l = 1 - table(seq_along(y), y), dag = diag(nlevels(y)))

Arguments

x

instance matrix, where x(t,) defines the features of instance t

y

target vector where y(t) is an integer encoding target of x(t,)

l

loss matrix. l(t,p(t)) must be the loss for predicting target p(t) instead of y(t) for instance t. By default, the parameter is set to a 0/1 loss matrix.

dag

a numeric matrix defining the path in the Direct Acyclic Graph (DAG) to each class label

Value

a function taking one argument w and computing the loss value and the gradient at point w

References

Teo et al. A Scalable Modular Convex Solver for Regularized Risk Minimization. KDD 2007

Examples

Run this code
# NOT RUN {
  # -- Load the data
  x <- cbind(intercept=100,data.matrix(iris[1:4]))
  y <- iris$Species
  dag <- matrix(c(1,0,0,0,
                  0,1,1,0,
                  0,1,0,1),3,4,byrow=TRUE)
  w <- nrbm(ontologyLoss(x,y,dag=dag))
  w <- matrix(w,ncol(x))
  f <- x %*% tcrossprod(w,dag)
  table(y,max.col(f))
# }

Run the code above in your browser using DataLab