Skip to content

Commit

Permalink
fixing corner cases of reduced memory prediction for hpdRF_paralleltree
Browse files Browse the repository at this point in the history
  • Loading branch information
vishrutg committed Oct 14, 2015
1 parent b4d5c33 commit a673f7a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
7 changes: 1 addition & 6 deletions algorithms/HPdclassifier/R/hpdRF_parallelTree.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,13 @@ hpdrandomForest <- hpdRF_parallelTree <- function(formula, data,
oob_predictions = NULL
if(completeModel)
{
tryCatch({
if(do.trace)
.master_output("\tComputing oob statistics")
timing_info <- Sys.time()
oob_predictions = .predictOOB(forest, observations,
responses, oob_indices, cutoff, classes,
reduceModel = reduceModel,do.trace)
ntree = ntree, reduceModel = reduceModel, do.trace)
forest = oob_predictions$dforest
},error = function(e)
{
stop(paste("aborting oob computations. received error:", e))
})
if(do.trace)
.master_output("\tcurrent distributed forest size: ",
format(round(d.object.size(forest)/1024/1024,2),nsmall = 2),
Expand Down
13 changes: 10 additions & 3 deletions algorithms/HPdclassifier/R/hpdRFdistributed.R
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@


.predictOOB <- function(forest, observations, responses, oob_indices,
cutoff, classes, reduceModel = FALSE, trace = FALSE)
cutoff, classes, ntree, reduceModel = FALSE, trace = FALSE)
{

timing_info <- Sys.time()
Expand All @@ -571,8 +571,12 @@


dforest = forest
if(ntree < npartitions(forest))
dforest = .redistributeForest(forest,as.list(1:ntree))
rm(forest)
suppressWarnings({
votes = darray(npartitions =c(npartitions(dforest),npartitions(observations)))
votes = darray(npartitions =c(npartitions(dforest),
npartitions(observations)))
})
foreach(i,0:(npartitions(votes)-1),
function(predictions=splits(votes,i+1),
Expand All @@ -585,6 +589,7 @@
{
tree_ids = which(!sapply(forest,is.null))
tree_ids = tree_ids[-1]

forest = .Call("unserializeForest",forest,
PACKAGE = "HPdclassifier")
forestparam = .Call("getForestParameters", forest,
Expand Down Expand Up @@ -612,16 +617,18 @@
predictions = matrix(as.double(NA),
ncol = nrow(observations),
length(tree_ids))

tree_ids = tree_ids - 1
oob_indices = lapply(oob_indices, as.integer)

.Call("forestPredictOOB", forest, predictions, observations,
oob_indices, as.integer(tree_ids))

.Call("garbageCollectForest",forest)
update(predictions)
},progress = FALSE)


timing_info <- Sys.time() - timing_info
if(trace)
.master_output(format(round(timing_info, 2),nsmall = 2))
Expand Down
6 changes: 1 addition & 5 deletions algorithms/HPdclassifier/src/hpdRFpredict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,11 +499,7 @@ extern "C"
for(int tree_index = 0; tree_index < length(R_tree_ids); tree_index++)
{
int tree_id = INTEGER(R_tree_ids)[tree_index]-1;
SEXP indices;
if(length(R_indices) > 1)
indices = VECTOR_ELT(R_indices,tree_id);
else
indices = R_indices;
SEXP indices = VECTOR_ELT(R_indices,tree_id);
for(int i = 0; i < length(indices); i++)
{
int obs_index = INTEGER(indices)[i]-1;
Expand Down

0 comments on commit a673f7a

Please sign in to comment.