1 #' @include b_LinearAlgorithm.R
3 #' @title Exponential Weights Algorithm
5 #' @description Exponential Weights Algorithm.
6 #' Inherits \code{\link{LinearAlgorithm}}
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
11 ExponentialWeights = setRefClass(
12 Class = "ExponentialWeights",
19 contains = "LinearAlgorithm",
22 initialize = function(...)
25 if (length(alpha) == 0 || alpha < 0. || alpha > 1.)
26 alpha <<- 0. #no redistribution
27 if (length(grad) == 0)
30 predict_noNA = function(XY, x)
35 #shortcut: nothing to combine
41 X = XY[,names(XY) != "Measure"]
43 finalWeight = .C("ew_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
47 appendWeight(finalWeight)
48 return (matricize(x) %*% finalWeight)