-
Notifications
You must be signed in to change notification settings - Fork 0
/
LUM.R
28 lines (25 loc) · 959 Bytes
/
LUM.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Large-margin Unified Machine (LUM)
# For single regression
lum <- function(x, y, a = 1, c = 1, lambda = 1, max.iter=100, eps = 1.0e-8){
# x: predictor
# y: binary response with {-1, 1} coding
# a, c: constants in LUM loss
# lambda: regularization pamameter
V <- function(u, a = 1, c = 1){
ifelse(u<c/(1+c),(1-u),(1/(1+c))*(a/((1+c)*u-c+a))^a)
}
coef <- glm(y~x)$coefficient
alpha <- coef[1]; beta <- coef[2]
for(iter in 1:max.iter){
new.beta <- optimize(f= function(bet) 1/n*sum(V(y*(alpha+x*bet), a, c))+lambda/2*bet^2,
interval = c(-100, 100))$minimum
new.alpha <- optimize(f= function(alp) sum(V(y*(alp + x*new.beta), a, c)),
interval=c(-100, 100))$minimum
if(max(abs(c(new.alpha, new.beta)-c(alpha, beta))) < eps){
break}
beta <- new.beta
alpha <- new.alpha
}
est <- c(alpha=new.alpha, beta=new.beta) # linear LUM estimator
return(est)
}