2016-06-11 2 views
1

私はこのRコードのスニペットを試しました。並列時に変数が見つかりません

Error in get(name, envir = envir) : object 'data.original' not found 
Error in checkForRemoteErrors(val) : 
    one node produced an error: could not find function "elbow.k" 

誰も私はそれを修正するのに役立ちます。私は、私は、エラー通知を持って並列

# include library 
require(stats) 
library(GMD) 
library(parallel) 
# include function 
source('~/Workspaces/Projects/RProject/MovielensCluster/readData.R'); # contain readtext.convert() function 
### 
elbow.k <- function(mydata){ 
    ## determine a "good" k using elbow 
    dist.obj <- dist(mydata); 
    hclust.obj <- hclust(dist.obj); 
    css.obj <- css.hclust(dist.obj,hclust.obj); 
    elbow.obj <- elbow.batch(css.obj); 
    # print(elbow.obj) 
    k <- elbow.obj$k 
    return(k) 
} 

# include file 
filePath <- "dataset/u.user"; 
data.convert <- readtext.convert(filePath); 
data.clustering <- data.convert[,c(-1,-4)]; 
# find k value 
no_cores <- detectCores(); 
cl<-makeCluster(no_cores); 
clusterExport(cl, list("data.clustering", "data.original", "elbow.k", "clustering.kmeans")); 
start.time <- Sys.time(); 
k.clusters <- parSapply(cl, 1, function(x) elbow.k(data.clustering)); 
end.time <- Sys.time(); 
cat('Time to find k using Elbow method is',(end.time - start.time),'seconds with k value:', k.clusters); 

に問題がありますか?どうもありがとう。

答えて

3

あなたの問題は「可変スコープ」に関係すると思います。 Mac/Linuxでは、すべての環境変数を自動的に含むmakeCluster(no_core、type = "FORK")を使用するオプションがあります。 Windowsでは、ロードされた基本パッケージだけで始まるParallel Socket Cluster(PSOCK)を使用する必要があります。したがって、並列関数が動作するために含めるライブラリだけでなく、どの変数も常に正確に指定します。 clusterExport()およびclusterEvalQ()は、それぞれ必要な変数とパッケージを表示する関数に必要です。 clusterExportの後の変数への変更はすべて無視されることに注意してください。あなたの問題に戻ってください。あなたは、次のように使用する必要があります。

clusterEvalQ(cl, library(GMD)); 

し、あなたの完全なコード:

# include library 
require(stats) 
library(GMD) 
library(parallel) 
# include function 
source('~/Workspaces/Projects/RProject/MovielensCluster/readData.R'); # contain readtext.convert() function 
### 
elbow.k <- function(mydata){ 
    ## determine a "good" k using elbow 
    dist.obj <- dist(mydata); 
    hclust.obj <- hclust(dist.obj); 
    css.obj <- css.hclust(dist.obj,hclust.obj); 
    elbow.obj <- elbow.batch(css.obj); 
    # print(elbow.obj) 
    k <- elbow.obj$k 
    return(k) 
} 

# include file 
filePath <- "dataset/u.user"; 
data.convert <- readtext.convert(filePath); 
data.clustering <- data.convert[,c(-1,-4)]; 
# find k value 
no_cores <- detectCores(); 
cl<-makeCluster(no_cores); 
clusterEvalQ(cl, library(GMD)); 
clusterExport(cl, list("data.clustering", "data.original", "elbow.k", "clustering.kmeans")); 
start.time <- Sys.time(); 
k.clusters <- parSapply(cl, 1, function(x) elbow.k(data.clustering)); 
end.time <- Sys.time(); 
cat('Time to find k using Elbow method is',(end.time - start.time),'seconds with k value:', k.clusters); 
+0

はそんなにありがとう。それはうまくいく – Khongbich

関連する問題