diff --git a/README.md b/README.md index 4bc0c94..c947e4b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # KPMS-IT4I-EX Companion to KPMS-IT4I with exercises. It is separate, to avoid lecture pdf replication on IT4I systems. +# ASwR diff --git a/code/UKOL5.sh b/code/UKOL5.sh new file mode 100644 index 0000000..cc43b8a --- /dev/null +++ b/code/UKOL5.sh @@ -0,0 +1,15 @@ +#!/bin/bash +#PBS -N rf +#PBS -l select=1:ncpus=128,walltime=00:05:00 +#PBS -q qexp +#PBS -e UKOL5.e +#PBS -o UKOL5.o + +cd ~/KPMS-IT4I-EX-1/code +pwd + +module load R +echo "loaded R" + + +time Rscript UKOL5_simulace.r 128 \ No newline at end of file diff --git a/code/rf_cv_karolina_pbs.sh b/code/rf_cv_karolina_pbs.sh index cc069a6..32791a9 100644 --- a/code/rf_cv_karolina_pbs.sh +++ b/code/rf_cv_karolina_pbs.sh @@ -5,15 +5,15 @@ #PBS -e rf_cv.e #PBS -o rf_cv.o -cd ~/KPMS-IT4I-EX/code +cd ~/KPMS-IT4I-EX-1/code pwd module load R echo "loaded R" -time Rscript rf_cv_serial.r -time Rscript rf_cv_mc.r 8 -time Rscript rf_cv_mc.r 16 +#time Rscript rf_cv_serial.r +#time Rscript rf_cv_mc.r 8 +#time Rscript rf_cv_mc.r 16 time Rscript rf_cv_mc.r 32 time Rscript rf_cv_mc.r 64 time Rscript rf_cv_mc.r 128 diff --git a/code/rf_cv_mc.r b/code/rf_cv_mc.r index 4e6ca52..9037582 100644 --- a/code/rf_cv_mc.r +++ b/code/rf_cv_mc.r @@ -26,15 +26,16 @@ fold_err = function(i, cv_pars, folds, train) { nc = as.numeric(commandArgs(TRUE)[1]) cat("Running with", nc, "cores\n") system.time({ -cv_err = parallel::mclapply(1:nrow(cv_pars), fold_err, cv_pars, folds = folds, + cv_err = parallel::mclapply(1:nrow(cv_pars), fold_err, cv_pars, folds = folds, train = train, mc.cores = nc) -err = tapply(unlist(cv_err), cv_pars[, "mtry"], sum) + err = tapply(unlist(cv_err), cv_pars[, "mtry"], sum) }) pdf(paste0("rf_cv_mc", nc, ".pdf")); plot(mtry_val, err/(n - n_test)); dev.off() -rf.all = randomForest(lettr ~ ., train, ntree = ntree) -pred = predict(rf.all, test) -correct = sum(pred == test$lettr) +ntree_new = lapply(splitIndices(200, nc), length) +rf = function(x) randomForest(lettr ~ ., train, ntree=x, norm.votes = FALSE) +rf.out = mclapply(ntree_new, rf, mc.cores = nc) +rf.all = do.call(combine, rf.out) mtry = mtry_val[which.min(err)] rf.all = randomForest(lettr ~ ., train, ntree = ntree, mtry = mtry) @@ -42,4 +43,3 @@ pred_cv = predict(rf.all, test) correct_cv = sum(pred_cv == test$lettr) cat("Proportion Correct: ", correct/n_test, "(mtry = ", floor((ncol(test) - 1)/3), ") with cv:", correct_cv/n_test, "(mtry = ", mtry, ")\n", sep = "") -