X-Git-Url: https://git.auder.net/doc/screen_players.png?a=blobdiff_plain;f=pkg%2FR%2Fm_MLPoly.R;fp=pkg%2FR%2Fm_MLPoly.R;h=a19a2c997408f16ddcbbdf35f6d7d967fbbdc22b;hb=ae507b4e6ed3ae1f50a24a7c43d77be9501d791c;hp=0000000000000000000000000000000000000000;hpb=57dbbab63a48b42f85e0a711640e1dd10b58f18a;p=aggexp.git diff --git a/pkg/R/m_MLPoly.R b/pkg/R/m_MLPoly.R new file mode 100644 index 0000000..a19a2c9 --- /dev/null +++ b/pkg/R/m_MLPoly.R @@ -0,0 +1,51 @@ +#' @include b_LinearAlgorithm.R + +#' @title MLpoly Algorithm +#' +#' @description MLpoly Algorithm. +#' Inherits \code{\link{LinearAlgorithm}} +#' +#' @field alpha Importance of weights redistribution, in [0,1]. Default: 0 +#' @field grad Whether to use or not the (sub)gradient trick. Default: FALSE +#' +MLpoly = setRefClass( + Class = "MLpoly", + + fields = c( + alpha = "numeric", + grad = "logical" + ), + + contains = "LinearAlgorithm", + + methods = list( + initialize = function(...) + { + callSuper(...) + if (length(alpha) == 0 || alpha < 0. || alpha > 1.) + alpha <<- 0. #no redistribution + if (length(grad) == 0) + grad <<- FALSE + }, + predict_noNA = function(XY, x) + { + K = ncol(XY) - 1 + if (K == 1) + { + #shortcut: nothing to combine + finalWeight = 1. + } + + else + { + X = XY[,names(XY) != "Measure"] + Y = XY[,"Measure"] + finalWeight = .C("ml_predict_noNA", X = as.double(t(X)), Y = as.double(Y), n = as.integer(nrow(XY)), + K = as.integer(K), alpha=as.double(alpha), grad = as.integer(grad), weight=double(K))$weight + } + + appendWeight(finalWeight) + return (matricize(x) %*% finalWeight) + } + ) +)