Skip to content

Commit

Permalink
some formatting in NNshapeReg
Browse files Browse the repository at this point in the history
  • Loading branch information
zarquon42b committed Feb 24, 2014
1 parent ceba099 commit c68de96
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions R/NNshapeReg.r
Original file line number Diff line number Diff line change
Expand Up @@ -33,42 +33,39 @@
#'
#'
#' @export
NNshapeReg <- function(x,y=NULL, n=3, mahalanobis=FALSE,mc.cores = parallel::detectCores())
{
if (is.null(y))
y <- x
outdim <- dim(y)
if (length(dim(x)) == 3)
x <- vecx(x)
if (length(dim(y)) == 3)
y <- vecx(y)
NNshapeReg <- function(x,y=NULL, n=3, mahalanobis=FALSE,mc.cores = parallel::detectCores()) {
if (is.null(y))
y <- x
outdim <- dim(y)
if (length(dim(x)) == 3)
x <- vecx(x)
if (length(dim(y)) == 3)
y <- vecx(y)
i <- NULL
win <- FALSE
if(.Platform$OS.type == "windows")
win <- TRUE
if(.Platform$OS.type == "windows")
win <- TRUE
else
registerDoParallel(cores=mc.cores)### register parallel backend
registerDoParallel(cores=mc.cores)### register parallel backend
out <- y
estfun <- function(i)
{
estfun <- function(i) {
weighcalc <- proc.weight(x,n,i,mahalanobis=mahalanobis,report=F)$data
ws <- diag(weighcalc$weight)
tmpres <- apply(t(t(y[weighcalc$nr,])%*%ws),2,sum)
return(tmpres)
}
}
if (win)
out <- foreach(i=1:dim(x)[1],.combine=rbind) %do% estfun(i)
out <- foreach(i=1:dim(x)[1],.combine=rbind) %do% estfun(i)
else
out <- foreach(i=1:dim(x)[1],.combine=rbind) %dopar% estfun(i)

if (length(outdim) == 3)
{
out1 <- array(NA, dim=outdim)
for (i in 1:outdim[3])
out1[,,i] <- matrix(out[i,],outdim[1],outdim[2])

out <- out1
}
out <- foreach(i=1:dim(x)[1],.combine=rbind) %dopar% estfun(i)

if (length(outdim) == 3) {
out1 <- array(NA, dim=outdim)
for (i in 1:outdim[3])
out1[,,i] <- matrix(out[i,],outdim[1],outdim[2])

out <- out1
}
return(out)
}
}

0 comments on commit c68de96

Please sign in to comment.