Learn R Programming

gputools (version 0.26)

gpuSvmPredict: A support vector machine style binary classifier

Description

This function classifies points in a data set with a support vector machine using a GPU. The negative category is represented by -1.f and the positive one by 1.f. The underlying code is adapted from Austin Carpenter's cuSVM which can be found at http://patternsonascreen.net/cuSVM.html

Usage

gpuSvmPredict(data, supportVectors, svCoefficients, svOffset,
	kernelWidth = 0.125, isRegression = FALSE)

Arguments

data
a matrix of floating point numbers. Each row will be placed into one of two categories -1.f or 1.f. Note that ncol(data) should equal ncol(supportVectors).
supportVectors
a matrix of floating point numbers. Each row of the matrix is a support vector. This matrix can be obtained from gpuSvmTrain, for example. Note that ncol(supportVector) should equal ncol(data).
svCoefficients
a vector of floating point numbers representing coefficients corresponding to the support vectors. This vector can be obtained from gpuSvmTrain, for example. Each support vector supportVectors[i,] has coefficient svCoefficients[i].
svOffset
a single floating point number. It is the offset for the prediction function. The offset can be obtained from gpuSvmTrain, for example.
kernelWidth
a single floating point number. This is the scalar Gaussian kernel parameter.
isRegression
a single logical value indicating if the supportVectors result from regression.

Value

  • a vector of nrow(data) entries, each either -1.f or 1.f. Each entry i corresponds to the support vector machine's prediction for the category of data[i,].

References

Carpenter, Austin, cuSVM: a cuda implementation of support vector classification and regression, http://http://patternsonascreen.net/cuSVM.html

Examples

Run this code
# y is discrete: -1 or 1 and we set isRegression to FALSE
y <- round(runif(100, min = 0, max = 1))
for(i in 1:5) { if(y[i] == 0) {y[i] <- -1}}

x <- matrix(runif(500), 100, 5)

# a <- gpuSvmTrain(y, x, isRegression = FALSE)
# print(a)
# 
# b <- gpuSvmPredict(x, a$supportVectors, a$svCoefficients, a$svOffset, isRegression = FALSE)
# print(b)

# this time around, y : -1 or 1 and we set isRegression to FALSE
y <- runif(100, min = -1, max = 1)

x <- matrix(runif(500), 100, 5)

# a <- gpuSvmTrain(y, x, isRegression = TRUE)
# print(a)
# 
# b <- gpuSvmPredict(x, a$supportVectors, a$svCoefficients, a$svOffset, isRegression = TRUE)
# print(b)

Run the code above in your browser using DataLab