0

我是 R 编程的新手。我面临与 Stream 相关的问题。我正在从文本文件中读取数据流文件。当流到达流的末尾时。我无法处理这个问题。

 Micro_cluster<-function(data_stream)
   {
     list_counter<-1;
  micro_clusters<-list();
  while(TRUE)
  {
     points<-DSD_Wrapper(get_points(data_stream,n=1000));
     if(!points)
     {
        print("End of Stream");    
     }
     else
     {
       mcluster<-DSC_DenStream();
       cluster(mcluster,points,n=1000);
       micro_clusters[list_counter]<-list(mcluster);
       list_counter<-list_counter+1;
       rm(mcluster);    
     }

  }
  rm(list_counter);

} 
4

2 回答 2

0

在没有看到您要输入的内容的情况下,不一定能回答具体问题,但是 - 您知道您实际上并没有结束那个 WHILE 循环,对吧?它只会永远迭代。大概你想要类似的东西......

#Set an object that handles the boolean for the while loop, so that you can actually kill said loop
while_check <- TRUE

while(while_check)
{
 points<-DSD_Wrapper(get_points(data_stream,n=1000));
 if(!points)
 {
    print("End of Stream");
    #If there aren't any entries left, change that value so that the loop stops.
    while_check <- FALSE

 }
 else
 {
   mcluster<-DSC_DenStream();
   cluster(mcluster,points,n=1000);
   micro_clusters[list_counter]<-list(mcluster);
   list_counter<-list_counter+1;
   rm(mcluster);    
 }

}

我想这可以解释为什么流解析器实际上从未终止;)。

于 2014-04-06T07:12:55.147 回答
-1

我的问题陈述我有一组与纽约数据集相关的健康数据。文件结构如

经纬度日例 '

 40.00    -73.25     1    1

所以创建了一个文件,其中有大约 17699997 的记录。所以我必须使用流包创建一个流,从文件中提取 1000 个数据。然后我将应用 Denstram() 算法进行在线集群和相同的 1000 点获取并应用离线算法,例如K-均值,DBSACN。

我想从文件中取1000分申请在线和离线集群。老化需要 1000 直到流即将结束。

所以我创建了以下代码。但我无法找到流的结尾。

但我想通知用户流结束。两个过程

线上流程 线下流程

 Denstream_Dbscan<-function(Wrapper_Data_Stream)
{
  i<-1;
  while(TRUE)
  {


    # online process(micro cluster)
    start_time<-Sys.time();

    print(paste("Start online Process ",i," iteration",Sys.time()));
    dstream_micro<-DSC_DenStream(epsilon=0.01,initPoints=200,minPoints=500);
    system.time({
    cluster(dstream_micro,Wrapper_Data_Stream,n=1000,verbose=TRUE);    
    })
   # print(paste("center of cluster=",get_center(dstream_micro)));
    print(paste("no of micro cluster=",nclusters(dstream_micro,type="auto")));

    jpeg(paste("Micro Cluster(Online)_",i,".jpeg"));
    plot(dstream_micro,dsd=Wrapper_Data_Stream,pch=c(1,2),col_points="red",col_clusters="green",xlab="latitude",ylab="longitude", main=paste("TimeTaken=",start_time-end_time),sub=paste("micro cluster:",Sys.time()),col.main="red",col.sub="black");
    print(paste("End online Process  for ",i," iteration",Sys.time()));
    dev.off();


    # offline process (macro cluster)

    print(paste("Start offline Process ",i," iteration",Sys.time()));
    start_time<-Sys.time();
    dbscan_macro<-DSC_DBSCAN(eps=0.1)
    system.time({
    recluster(dbscan_macro,dstream_micro);

    })

    print(paste("no of macro cluster=",nclusters(dbscan_macro)));
   # print(paste("center of cluster=",get_center(dstream_micro)));
    end_time<-Sys.time();
    jpeg(paste("Macro Cluster(offline)_",i,".jpeg"));
    plot(dbscan_macro,Wrapper_Data_Stream,pch=c(1,2),col_points="grey",col_clusters="blue",xlab="latitude",ylab="longitude",main=paste("TimeTaken=",start_time-end_time),sub=paste("macro cluster:",Sys.time()),col.main="red",col.sub="black");
    dev.off();
    print(paste("End Offline Process  for ",i," iteration",Sys.time()));
    i<-i+1;

    }
}
于 2014-04-07T04:38:46.820 回答