From f6c4360090c1235ce54f84ddc8ab6a2629f8d8e4 Mon Sep 17 00:00:00 2001 From: Gertjan van den Burg Date: Tue, 3 Apr 2018 23:21:12 +0100 Subject: Add support for raw weight vector in gensvm() --- R/gensvm.R | 11 ++++++++++- R/validate.R | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'R') diff --git a/R/gensvm.R b/R/gensvm.R index 8994d3a..5652a4c 100644 --- a/R/gensvm.R +++ b/R/gensvm.R @@ -139,13 +139,21 @@ gensvm <- function(x, y, p=1.0, lambda=1e-8, kappa=0.0, epsilon=1e-6, if (gamma == 'auto') gamma <- 1.0/n.features + raw.weights <- if (is.character(weights)) NULL else weights + weights <- if (is.character(weights)) weights else "raw" + + if (weights == "raw" && length(raw.weights) != n.objects) { + cat("Error: length of weights vector unequal to number of objects\n") + return(invisible(NULL)) + } + if (!gensvm.validate.params(p=p, kappa=kappa, lambda=lambda, epsilon=epsilon, gamma=gamma, weights=weights, kernel=kernel)) return(invisible(NULL)) # Convert weights to index - weight.idx <- which(c("unit", "group") == weights) + weight.idx <- which(c("raw", "unit", "group") == weights) - 1 # Convert kernel to index (remember off-by-one for R vs. C) kernel.idx <- which(c("linear", "poly", "rbf", "sigmoid") == kernel) - 1 @@ -162,6 +170,7 @@ gensvm <- function(x, y, p=1.0, lambda=1e-8, kappa=0.0, epsilon=1e-6, kappa, epsilon, weight.idx, + raw.weights, as.integer(kernel.idx), gamma, coef, diff --git a/R/validate.R b/R/validate.R index b0f3f39..5960a38 100644 --- a/R/validate.R +++ b/R/validate.R @@ -64,7 +64,7 @@ gensvm.param.conditions <- function() lambda=function(x) {x > 0.0 }, epsilon=function(x) { x > 0.0 }, gamma=function(x) { x != 0.0 }, - weights=function(x) { x %in% c("unit", "group") }, + weights=function(x) { x %in% c("raw", "unit", "group") }, kernel=function(x) { x %in% c("linear", "poly", "rbf", "sigmoid") } ) } -- cgit v1.2.3