Skip to content

Commit

Permalink
handling of possible scaling error
Browse files Browse the repository at this point in the history
  • Loading branch information
HannaMeyer committed Jul 31, 2020
1 parent ad37266 commit d0c73d0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions R/aoa.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ aoa <- function (newdata,
##############################################################################
#### Scale data and weight data if applicable:
train <- scale(train)
if (any(apply(train, 2, FUN=function(x){all(is.na(x))}))){
stop("some variables in train seem to have no variance")
}
scaleparam <- attributes(train)
if(!inherits(weight, "error")){
train <- sapply(1:ncol(train),function(x){train[,x]*unlist(weight[x])})
Expand All @@ -208,14 +211,12 @@ aoa <- function (newdata,
return(min(tmp))
}
}
if (!is.null(cl)){ #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if (!is.null(cl)){
mindist <- parApply(cl=cl,X=newdata,MARGIN=1,FUN=distfun)
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}else{
mindist <- apply(newdata,1,FUN=distfun)
}


trainDist <- as.matrix(dist(train))
# trainDist <- apply(train,1,FUN=function(x){
# FNN::knnx.dist(t(matrix(x)),train,k=1)})
Expand Down

0 comments on commit d0c73d0

Please # to comment.