# ordinalRegressionLoss: The loss function for ordinal regression In bmrm: Bundle Methods for Regularized Risk Minimization Package

## Description

The loss function for ordinal regression

## Usage

 `1` ```ordinalRegressionLoss(x, y, C = "0/1", impl = c("loglin", "quadratic")) ```

## Arguments

 `x` matrix of training instances (one instance by row) `y` integer vector of positive values (>=1) representing the training labels for each instance in x `C` the cost matrix to use, C[i,j] being the cost for predicting label i instead of label j. `impl` either the string "loglin" or "quadratic", that define the implementation to use for the computation of the loss.

## Value

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

## References

Teo et al. Bundle Methods for Regularized Risk Minimization JMLR 2010

nrbm

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20``` ```# -- Load the data x <- data.matrix(iris[1:4]) y <- as.integer(iris\$Species) # -- Train the model w <- nrbm(ordinalRegressionLoss(x,y),LAMBDA=0.001,EPSILON_TOL=0.0001) w2 <- nrbm(ordinalRegressionLoss(x,y,impl="quadratic"),LAMBDA=0.001,EPSILON_TOL=0.0001) # -- plot predictions f <- x %*% w f2 <- x %*% w2 layout(1:2) plot(y,f) plot(f,f2,main="compare predictions of quadratic and loglin implementations") # -- Compute accuracy ij <- expand.grid(i=seq(nrow(x)),j=seq(nrow(x))) n <- tapply(f[ij\$i] - f[ij\$j]>0,list(y[ij\$i],y[ij\$j]),sum) N <- table(y[ij\$i],y[ij\$j]) print(n/N) ```

### Example output

```LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   1.0173005e-19
Dual Feasibility      =   0.0000000e+00
Complementarity Value =   2.0590219e-12
Duality Gap           =   2.0590219e-12
Termination Condition =   2.0590218e-12
1:gap=0.99995 obj=1 reg=0 risk=1 w=[0,0]
LowRankQP CONVERGED IN 11 ITERATIONS

Primal Feasibility    =   5.5857624e-17
Dual Feasibility      =   1.1102230e-16
Complementarity Value =   2.0651032e-12
Duality Gap           =   2.0650753e-12
Termination Condition =   2.0651029e-12
2:gap=0.195788 obj=0.195931 reg=4.97691e-05 risk=0.195881 w=[-0.0301262,0.271402]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   8.1835214e-18
Dual Feasibility      =   2.2204460e-16
Complementarity Value =   3.2324636e-12
Duality Gap           =   3.2324595e-12
Termination Condition =   3.2324622e-12
3:gap=0.0948223 obj=0.0952394 reg=0.000143117 risk=0.0950963 w=[-0.0466482,0.459552]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   2.4607827e-17
Dual Feasibility      =   2.2204460e-16
Complementarity Value =   3.7484345e-11
Duality Gap           =   3.7484334e-11
Termination Condition =   3.7484305e-11
4:gap=0.0420257 obj=0.043074 reg=0.000417082 risk=0.0426569 w=[0.0155968,0.745712]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   8.6309063e-19
Dual Feasibility      =   1.1102230e-16
Complementarity Value =   2.0598678e-12
Duality Gap           =   2.0598677e-12
Termination Condition =   2.0598628e-12
5:gap=0.0142363 obj=0.0166568 reg=0.00104829 risk=0.0156085 w=[-0.256003,1.0919]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   1.0293895e-18
Dual Feasibility      =   1.1102230e-16
Complementarity Value =   6.8236500e-13
Duality Gap           =   6.8236499e-13
Termination Condition =   6.8236136e-13
6:gap=0.00408375 obj=0.00941908 reg=0.00242048 risk=0.0069986 w=[-0.449722,1.50098]
LowRankQP CONVERGED IN 11 ITERATIONS

Primal Feasibility    =   6.5203168e-17
Dual Feasibility      =   4.2188475e-15
Complementarity Value =   3.4600872e-11
Duality Gap           =   3.4600863e-11
Termination Condition =   3.4600650e-11
7:gap=0.00301501 obj=0.00941908 reg=0.00242048 risk=0.0069986 w=[-0.449722,1.50098]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   8.0916782e-19
Dual Feasibility      =   0.0000000e+00
Complementarity Value =   2.6610099e-12
Duality Gap           =   2.6610098e-12
Termination Condition =   2.6609901e-12
8:gap=0.00195678 obj=0.00941908 reg=0.00242048 risk=0.0069986 w=[-0.449722,1.50098]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   1.0273815e-17
Dual Feasibility      =   2.9976022e-15
Complementarity Value =   8.9925242e-12
Duality Gap           =   8.9925232e-12
Termination Condition =   8.9924544e-12
9:gap=0.00123223 obj=0.00899572 reg=0.00403188 risk=0.00496383 w=[-0.414716,2.2088]
LowRankQP CONVERGED IN 13 ITERATIONS

Primal Feasibility    =   2.4914498e-17
Dual Feasibility      =   4.4408921e-16
Complementarity Value =   4.4243340e-12
Duality Gap           =   4.4243301e-12
Termination Condition =   4.4242987e-12
10:gap=0.00101094 obj=0.00899572 reg=0.00403188 risk=0.00496383 w=[-0.414716,2.2088]
LowRankQP CONVERGED IN 13 ITERATIONS

Primal Feasibility    =   1.0857923e-16
Dual Feasibility      =   1.8096635e-14
Complementarity Value =   6.6332936e-12
Duality Gap           =   6.6332622e-12
Termination Condition =   6.6332392e-12
11:gap=0.00037729 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 15 ITERATIONS

Primal Feasibility    =   1.1254578e-16
Dual Feasibility      =   0.0000000e+00
Complementarity Value =   6.8655161e-12
Duality Gap           =   6.8654921e-12
Termination Condition =   6.8654588e-12
12:gap=0.000240586 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 14 ITERATIONS

Primal Feasibility    =   2.5835074e-15
Dual Feasibility      =   6.4392935e-15
Complementarity Value =   1.0903487e-11
Duality Gap           =   1.0902893e-11
Termination Condition =   1.0903395e-11
13:gap=0.000215402 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 14 ITERATIONS

Primal Feasibility    =   2.8539943e-18
Dual Feasibility      =   8.4376950e-15
Complementarity Value =   1.0178374e-12
Duality Gap           =   1.0178372e-12
Termination Condition =   1.0178288e-12
14:gap=0.00012538 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 13 ITERATIONS

Primal Feasibility    =   7.0081487e-17
Dual Feasibility      =   7.0610184e-14
Complementarity Value =   5.9873523e-12
Duality Gap           =   5.9873411e-12
Termination Condition =   5.9873015e-12
15:gap=7.83959e-05 obj=0.00856749 reg=0.00359877 risk=0.00496872 w=[-0.613904,1.94123]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   1.0003599e-19
Dual Feasibility      =   0.0000000e+00
Complementarity Value =   2.0590219e-12
Duality Gap           =   2.0590219e-12
Termination Condition =   2.0590218e-12
1:gap=0.99995 obj=1 reg=0 risk=1 w=[0,0]
LowRankQP CONVERGED IN 11 ITERATIONS

Primal Feasibility    =   5.5803453e-17
Dual Feasibility      =   1.1102230e-16
Complementarity Value =   2.0651032e-12
Duality Gap           =   2.0650753e-12
Termination Condition =   2.0651029e-12
2:gap=0.195788 obj=0.195931 reg=4.97691e-05 risk=0.195881 w=[-0.0301262,0.271402]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   8.2013176e-18
Dual Feasibility      =   2.2204460e-16
Complementarity Value =   3.2324636e-12
Duality Gap           =   3.2324595e-12
Termination Condition =   3.2324622e-12
3:gap=0.0948223 obj=0.0952394 reg=0.000143117 risk=0.0950963 w=[-0.0466482,0.459552]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   2.4573827e-17
Dual Feasibility      =   3.3306691e-16
Complementarity Value =   3.7484345e-11
Duality Gap           =   3.7484334e-11
Termination Condition =   3.7484305e-11
4:gap=0.0420257 obj=0.043074 reg=0.000417082 risk=0.0426569 w=[0.0155968,0.745712]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   7.4789301e-19
Dual Feasibility      =   1.1102230e-16
Complementarity Value =   2.0598678e-12
Duality Gap           =   2.0598677e-12
Termination Condition =   2.0598628e-12
5:gap=0.0142363 obj=0.0166568 reg=0.00104829 risk=0.0156085 w=[-0.256003,1.0919]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   9.9720218e-19
Dual Feasibility      =   2.2204460e-16
Complementarity Value =   6.8236500e-13
Duality Gap           =   6.8236499e-13
Termination Condition =   6.8236136e-13
6:gap=0.00408375 obj=0.00941908 reg=0.00242048 risk=0.0069986 w=[-0.449722,1.50098]
LowRankQP CONVERGED IN 11 ITERATIONS

Primal Feasibility    =   6.5611727e-17
Dual Feasibility      =   3.9968029e-15
Complementarity Value =   3.4600872e-11
Duality Gap           =   3.4600863e-11
Termination Condition =   3.4600650e-11
7:gap=0.00301501 obj=0.00941908 reg=0.00242048 risk=0.0069986 w=[-0.449722,1.50098]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   1.0170599e-18
Dual Feasibility      =   1.1102230e-16
Complementarity Value =   2.6610099e-12
Duality Gap           =   2.6610098e-12
Termination Condition =   2.6609901e-12
8:gap=0.00195678 obj=0.00941908 reg=0.00242048 risk=0.0069986 w=[-0.449722,1.50098]
LowRankQP CONVERGED IN 12 ITERATIONS

Primal Feasibility    =   1.0475479e-17
Dual Feasibility      =   3.1086245e-15
Complementarity Value =   8.9925242e-12
Duality Gap           =   8.9925232e-12
Termination Condition =   8.9924544e-12
9:gap=0.00123223 obj=0.00899572 reg=0.00403188 risk=0.00496383 w=[-0.414716,2.2088]
LowRankQP CONVERGED IN 13 ITERATIONS

Primal Feasibility    =   2.4955261e-17
Dual Feasibility      =   4.4408921e-16
Complementarity Value =   4.4243340e-12
Duality Gap           =   4.4243300e-12
Termination Condition =   4.4242987e-12
10:gap=0.00101094 obj=0.00899572 reg=0.00403188 risk=0.00496383 w=[-0.414716,2.2088]
LowRankQP CONVERGED IN 13 ITERATIONS

Primal Feasibility    =   1.0852316e-16
Dual Feasibility      =   1.8096635e-14
Complementarity Value =   6.6332936e-12
Duality Gap           =   6.6332622e-12
Termination Condition =   6.6332392e-12
11:gap=0.00037729 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 15 ITERATIONS

Primal Feasibility    =   1.1132028e-16
Dual Feasibility      =   1.1102230e-16
Complementarity Value =   6.8655161e-12
Duality Gap           =   6.8654921e-12
Termination Condition =   6.8654588e-12
12:gap=0.000240586 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 14 ITERATIONS

Primal Feasibility    =   2.5833831e-15
Dual Feasibility      =   6.4392935e-15
Complementarity Value =   1.0903487e-11
Duality Gap           =   1.0902893e-11
Termination Condition =   1.0903395e-11
13:gap=0.000215402 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 14 ITERATIONS

Primal Feasibility    =   2.8690552e-18
Dual Feasibility      =   8.4376950e-15
Complementarity Value =   1.0178374e-12
Duality Gap           =   1.0178372e-12
Termination Condition =   1.0178288e-12
14:gap=0.00012538 obj=0.00858201 reg=0.00333369 risk=0.00524832 w=[-0.611245,1.8206]
LowRankQP CONVERGED IN 13 ITERATIONS

Primal Feasibility    =   6.9961993e-17
Dual Feasibility      =   7.0721207e-14
Complementarity Value =   5.9873523e-12
Duality Gap           =   5.9873411e-12
Termination Condition =   5.9873015e-12
15:gap=7.83959e-05 obj=0.00856749 reg=0.00359877 risk=0.00496872 w=[-0.613904,1.94123]
1      2      3
1 0.4900 0.0000 0.0000
2 1.0000 0.4900 0.0028
3 1.0000 0.9972 0.4896
```

bmrm documentation built on May 2, 2019, 2:49 p.m.