I try to look for instances that are missed in parallel processing. The code checks whether the csv file is missing and IF that's the case it will go and create a transformed (2D) version of the instance based on other .csv files (untransformed version of data). I tried to do this with standard for loop + if statement. But my program keeps crashing. I am getting the following image. enter image description here
(1) Here is my code which uses foreach to get to this solution:
ConfirmAllFilesExist <- function(i){
setwd("C:/Users/x/Desktop/Coswara/Extracted_data/")
library(nonlinearTseries)
library(crqa)
library(Rcpp)
library(parallelly)
library(tseriesChaos)
library(foreach)
library(doParallel)
library(future)
library(doFuture)
library(snow)
library(doSNOW)
if (file.exists(paste0('2D-cough-heavy-',as.character(i),'.csv')) == FALSE) {
print(as.character(i))
data <- read.csv(paste0('cough-heavy-',as.character(i),'.csv'))
data <- as.numeric(unlist(data))
tau.ami <- timeLag(data, technique = "ami", lag.max = 100, do.plot = F)
emb.dim = estimateEmbeddingDim(data, time.lag = tau.ami, max.embedding.dim = 15, do.plot = F)
Takens <- buildTakens(data, emb.dim, tau.ami)
paste0('Completed embedding unit: ',as.character(i))
x <- Takens[,1]
y <- Takens[,2]
z <- Takens[,3]
#u <- (1/3) * (x + y + z)
v <- (1/sqrt(6)) * (x + y - 2*z)
w <- (1/sqrt(2)) * (x - y)
file <- data.frame(v, w)
# save file
write.csv(file, paste0('2D-cough-heavy-',as.character(i),'.csv'), row.names = FALSE)
print(paste0('File ',as.character(i),'has been added.'))
}
}
foreach(i = 0:2016) %dopar% ConfirmAllFilesExist(i)
stopCluster(cl)
(2) standard for + if function which gives me the same result. The aim is to get this one to work but R keeps crashing. Anyone who knows what is happening here?
setwd("C:/Users/x/Desktop/Coswara/Extracted_data/")
library(parallelly)
library(foreach)
library(doParallel)
library(future)
library(doFuture)
library(snow)
library(doSNOW)
library(nonlinearTseries)
library(tseriesChaos)
# Confirm whether all files specified have been created in parallel processing.
ConfirmAllFilesExist <- function(start,stop){
setwd("C:/Users/x/Desktop/Coswara/Extracted_data/")
library(nonlinearTseries)
library(crqa)
library(Rcpp)
library(parallelly)
library(tseriesChaos)
library(foreach)
library(doParallel)
library(future)
library(doFuture)
library(snow)
library(doSNOW)
for (i in start:stop) {
if (file.exists(paste0('C:/Users/x/Desktop/Coswara/Extracted_data/2D-cough-heavy-',as.character(i),'.csv')) == FALSE) {
print(as.character(i))
data <- read.csv(paste0('cough-heavy-',as.character(i),'.csv'))
print('two')
data <- as.numeric(unlist(data))
print('two')
tau.ami <- timeLag(data, technique = "ami", lag.max = 100, do.plot = FALSE)
print('two')
emb.dim <- estimateEmbeddingDim(data, time.lag = tau.ami, max.embedding.dim = 15, do.plot = FALSE)
print('two')
Takens <- buildTakens(data, emb.dim, tau.ami)
print(paste0('Completed embedding unit: ',as.character(i)))
x <- Takens[,1]
y <- Takens[,2]
z <- Takens[,3]
#u <- (1/3) * (x + y + z)
v <- (1/sqrt(6)) * (x + y - 2*z)
w <- (1/sqrt(2)) * (x - y)
file <- data.frame(v, w)
# save file
write.csv(file, paste0('2D-cough-heavy-',as.character(i),'.csv'), row.names = FALSE)
print(paste0('File ',as.character(i),'has been added.'))
}
}
}
ConfirmAllFilesExist(0,2016)