diff --git a/07_final_assignment/baboonSimulation.R b/07_final_assignment/baboonSimulation.R index a969e83..d1064d3 100644 --- a/07_final_assignment/baboonSimulation.R +++ b/07_final_assignment/baboonSimulation.R @@ -367,17 +367,17 @@ aseq <- seq(from=start.of.a.and.b, to=end.of.a.and.b, length.out=15) step <- aseq[2] - aseq[1] for(a in aseq) { - for(b in seq(from=0.001, to=a, by=step)) { + for(b in seq(from=start.of.a.and.b, to=a, by=step)) { a.and.b.combinations <- cbind(a.and.b.combinations, c(a, b)) } } get.a <- function(i, index) { - return(a.and.b.combinations[1, (i*monkeys.per.core)-(monkeys.per.core-1) : (i*monkeys.per.core)]) + return((a.and.b.combinations[1, ((i*monkeys.per.core)-(monkeys.per.core-1)) : (i*monkeys.per.core)])[index]) } get.b <- function(i, index) { - return(a.and.b.combinations[2, (i*monkeys.per.core)-(monkeys.per.core-1) : (i*monkeys.per.core)]) + return((a.and.b.combinations[2, ((i*monkeys.per.core)-(monkeys.per.core-1)) : (i*monkeys.per.core)])[index]) } do.experiment <- function(i) { @@ -403,12 +403,25 @@ print(paste("--running-- i: ", i, " a: ", a, " b: ", b, " r: ", r, sep="" )) } - s <- simulateAndAnalyse(data, trialCount, alpha=a, beta=b, randomRatio=r ) - s[1] <- as.character(trialCount) - resultdat <- rbind(resultdat, - c(a, b, s[2:length(s)])) + if(FALSE) { + + s <- simulateAndAnalyse(data, trialCount, alpha=a, beta=b, randomRatio=r ) + s[1] <- as.character(trialCount) + resultdat <- rbind(resultdat, + c(a, b, s[2:length(s)])) + + #write preliminary result to file -> in case of interruption nothing gets lost + } - #write preliminary result to file -> in case of interruption nothing gets lost + asdf = data.frame(alpha=a, beta=b, + NumTrials=numeric(1), + NumWordsLearned=numeric(1), + NumNonwordsPresented=numeric(1), + GeneralAccuracy=numeric(1), + WordAccuracy=numeric(1), + NonwordAccuracy=numeric(1)) + + resultdat <- rbind(resultdat, asdf) write.table(resultdat, file=filename, col.names=names(resultdat)) } @@ -420,10 +433,10 @@ #...RUN, MONKEY, RUN! -#cl <- makeCluster(num.cores) -#registerDoParallel(cl) +cl <- makeCluster(num.cores) +registerDoParallel(cl) -#foreach(i=1:num.cores) %dopar% do.experiment(i) +foreach(i=1:num.cores) %dopar% do.experiment(i) ##new version: #...RUN, MONKEY, RUN!