Skip to content

Instantly share code, notes, and snippets.

@tailriver
Created July 19, 2012 06:26
Show Gist options
  • Save tailriver/3141139 to your computer and use it in GitHub Desktop.
Save tailriver/3141139 to your computer and use it in GitHub Desktop.
D-optimality
input_file <- commandArgs()[6]
output_file <- commandArgs()[7]
search_max <- as.integer(commandArgs()[8])
M <- data.matrix(read.table(input_file))
nrows <- dim(M)[1]
if (search_max < 1) search_max <- nrows
selected_rows <- rep(0, nrows)
for (order in 1:search_max) {
Mselected <- M[which(selected_rows > 0),]
calc_det <- function(i) {
M_ <- rbind(Mselected, M[i,])
ifelse( is.na(i), NA, determinant( t(M_) %*% M_ )$modulus )
}
rows <- 1:nrows
rows[selected_rows > 0] <- NA
det_values <- mapply(calc_det, rows)
cat(sprintf("%d min:%.6e max:%.6e\n", order, min(na.omit(det_values)), max(na.omit(det_values))))
det_max_row <- which.max(det_values)
selected_rows[det_max_row] <- order
}
write.table(selected_rows, output_file, quote=F, col.names=F, row.names=F, append=F)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment