a19a2c997408f16ddcbbdf35f6d7d967fbbdc22b
[aggexp.git] / m_MLPoly.R
1 #' @include b_LinearAlgorithm.R
2
3 #' @title MLpoly Algorithm
4 #'
5 #' @description MLpoly Algorithm.
6 #' Inherits \code{\link{LinearAlgorithm}}
7 #'
8 #' @field alpha Importance of weights redistribution, in [0,1]. Default: 0
9 #' @field grad Whether to use or not the (sub)gradient trick. Default: FALSE
10 #'
11 MLpoly = setRefClass(
12 Class = "MLpoly",
13
14 fields = c(
15 alpha = "numeric",
16 grad = "logical"
17 ),
18
19 contains = "LinearAlgorithm",
20
21 methods = list(
22 initialize = function(...)
23 {
24 callSuper(...)
25 if (length(alpha) == 0 || alpha < 0. || alpha > 1.)
26 alpha <<- 0. #no redistribution
27 if (length(grad) == 0)
28 grad <<- FALSE
29 },
30 predict_noNA = function(XY, x)
31 {
32 K = ncol(XY) - 1
33 if (K == 1)
34 {
35 #shortcut: nothing to combine
36 finalWeight = 1.
37 }
38
39 else
40 {
41 X = XY[,names(XY) != "Measure"]
42 Y = XY[,"Measure"]
43 finalWeight = .C("ml_predict_noNA", X = as.double(t(X)), Y = as.double(Y), n = as.integer(nrow(XY)),
44 K = as.integer(K), alpha=as.double(alpha), grad = as.integer(grad), weight=double(K))$weight
45 }
46
47 appendWeight(finalWeight)
48 return (matricize(x) %*% finalWeight)
49 }
50 )
51 )