Learn R Programming

ddalpha (version 1.3.16)

is.in.convex: Check Outsiderness

Description

Checks the belonging to at least one of class convex hulls of the training sample.

Usage

is.in.convex(x, data, cardinalities, seed = 0)

Value

Matrix of number of objects rows and number of classes columns, containing 1 if an object belongs to the convex hull of the corresponding class, and 0 otherwise.

Arguments

x

Matrix of objects (numerical vector as one object) whose belonging to convex hulls is to be checked; each row contains a \(d\)-variate point. Should have the same dimension as data.

data

Matrix containing training sample where each row is a \(d\)-dimensional object, and objects of each class are kept together so that the matrix can be thought of as containing blocks of objects, representing classes.

cardinalities

Numerical vector of cardinalities of each class in data, each entry corresponds to one class.

seed

the random seed. The default value seed=0 makes no changes.

Author

Implementation of the simplex algorithm is taken from the algorithm for computation of zonoid depth (Dyckerhoff, Koshevoy and Mosler, 1996) that has been implemented in C++ by Rainer Dyckerhoff.

Details

Checks are conducted w.r.t. each separate class in data using the simplex algorithm, taken from the C++ implementation of the zonoid depth calculation by Rainer Dyckerhoff.

References

Dyckerhoff, R., Koshevoy, G., and Mosler, K. (1996). Zonoid data depth: theory and computation. In: Prat A. (ed), COMPSTAT 1996. Proceedings in computational statistics, Physica-Verlag (Heidelberg), 235--240.

See Also

ddalpha.train and ddalpha.classify for application.

Examples

Run this code
# Generate a bivariate normal location-shift classification task
# containing 400 training objects and 1000 to test with
class1 <- mvrnorm(700, c(0,0), 
                  matrix(c(1,1,1,4), nrow = 2, ncol = 2, byrow = TRUE))
class2 <- mvrnorm(700, c(2,2), 
                  matrix(c(1,1,1,4), nrow = 2, ncol = 2, byrow = TRUE))
trainIndices <- c(1:200)
testIndices <- c(201:700)
propertyVars <- c(1:2)
classVar <- 3
trainData <- rbind(cbind(class1[trainIndices,], rep(1, 200)), 
                   cbind(class2[trainIndices,], rep(2, 200)))
testData <- rbind(cbind(class1[testIndices,], rep(1, 500)), 
                  cbind(class2[testIndices,], rep(2, 500)))
data <- list(train = trainData, test = testData)

# Count outsiders
numOutsiders = sum(rowSums(is.in.convex(data$test[,propertyVars], 
                                data$train[,propertyVars], c(200, 200))) == 0)
cat(numOutsiders, "outsiders found in the testing sample.\n")

Run the code above in your browser using DataLab