2019-06-06 22:53:25 +00:00
|
|
|
# These functions are not exported, so I won't provide their documentation either.
|
2019-05-31 22:13:24 +00:00
|
|
|
# I.e. it's not a mistake that the documentation below lacks the " ' " on each line.
|
|
|
|
|
|
|
|
# Covariates
|
|
|
|
#
|
|
|
|
# Creates a covariate for use in the Java code. These functions don't need to
|
|
|
|
# be directly run by a user, as loadData and train will detect, create and use
|
|
|
|
# such covariate objects.
|
|
|
|
#
|
|
|
|
# @name covariates
|
|
|
|
#
|
|
|
|
# @param name The name of the covariate, that later values will be placed
|
|
|
|
# under.
|
|
|
|
# @return An internal rJava object for later internal use.
|
|
|
|
# @keywords internal
|
|
|
|
# @examples
|
|
|
|
# # This is unnecessary for a user to do
|
|
|
|
#
|
|
|
|
# # Create a covariate
|
|
|
|
# booleanCovariate <- Java_BooleanCovariate("x1")
|
|
|
|
# factorCovariate <- Java_FactorCovariate("x2", c("cat", "dog", "mouse"))
|
|
|
|
# numericCovariate <- Java_NumericCovariate("x3")
|
|
|
|
#
|
|
|
|
# # Call the approriate Java method
|
|
|
|
# # The Java createValue method always takes in a String
|
|
|
|
# value1 <- .jcall(booleanCovariate, "Lca/joeltherrien/randomforest/covariates/Covariate$Value;", "createValue", "true")
|
|
|
|
# value2 <- .jcall(factorCovariate, "Lca/joeltherrien/randomforest/covariates/Covariate$Value;", "createValue", "dog")
|
|
|
|
# value3 <- .jcall(numericCovariate, "Lca/joeltherrien/randomforest/covariates/Covariate$Value;", "createValue", "3.14")
|
|
|
|
NULL
|
|
|
|
|
|
|
|
# @rdname covariates
|
2019-08-29 20:54:38 +00:00
|
|
|
Java_BooleanCovariate <- function(name, index, na.penalty){
|
|
|
|
covariate <- .jnew(.class_BooleanCovariate, name, as.integer(index), na.penalty)
|
2019-05-31 22:13:24 +00:00
|
|
|
covariate <- .jcast(covariate, .class_Object) # needed for later adding it into Java Lists
|
|
|
|
|
|
|
|
return(covariate)
|
|
|
|
}
|
|
|
|
|
|
|
|
# @rdname covariates
|
|
|
|
# @param levels The levels of the factor as a character vector
|
2019-08-29 20:54:38 +00:00
|
|
|
Java_FactorCovariate <- function(name, index, levels, na.penalty){
|
2019-05-31 22:13:24 +00:00
|
|
|
levelsArray <- .jarray(levels, makeResponse(.class_String))
|
|
|
|
levelsList <- .jcall("java/util/Arrays", "Ljava/util/List;", "asList", .jcast(levelsArray, "[Ljava/lang/Object;"))
|
|
|
|
|
2019-08-29 20:54:38 +00:00
|
|
|
covariate <- .jnew(.class_FactorCovariate, name, as.integer(index), levelsList, na.penalty)
|
2019-05-31 22:13:24 +00:00
|
|
|
covariate <- .jcast(covariate, .class_Object) # needed for later adding it into Java Lists
|
|
|
|
|
|
|
|
return(covariate)
|
|
|
|
}
|
|
|
|
|
|
|
|
# @rdname covariates
|
2019-08-29 20:54:38 +00:00
|
|
|
Java_NumericCovariate <- function(name, index, na.penalty){
|
|
|
|
covariate <- .jnew(.class_NumericCovariate, name, as.integer(index), na.penalty)
|
2019-05-31 22:13:24 +00:00
|
|
|
covariate <- .jcast(covariate, .class_Object) # needed for later adding it into Java Lists
|
|
|
|
|
|
|
|
return(covariate)
|
|
|
|
}
|