scagnostics.trace <- function(df, trace) { n <- length(trace$index) res <- numeric(n*9) res <- matrix(res, ncol=9) df <- as.matrix(df) colnames(res) <- colnames(scagnostics(as.data.frame(df %*% trace$projs[[1]]))) for (i in 1:n) { res[i,] <- scagnostics(as.data.frame(df %*% trace$projs[[i]])) } return(res) } scagnostics.anneal <- function(df, idx, cool=0.99, temp=1, start=NULL, show.index=TRUE, gg=FALSE, stop.it="MAXRUNS", ...) { checkstop <- function() { if (stop.it=="MAXRUNS") return (i >= maxRuns) if (stop.it=="NRUNS") { if (i==maxRuns) { print("continue? (y/n)") key <- readLines(,1) continue <- !(key[1] != "y") if (continue) maxRuns <- maxRuns + runs } return (i >= maxRuns) } if (stop.it=="CONV") return (abs(deltaI) <= absDelta) return (I0>1) } i <- 1 df <- as.matrix(df) if (is.null(start)) { A0 <- proj(df) } else { A0 <- ortho(start) } res <- scagnostics(as.data.frame(df %*% A0)) I0 <- res[idx] method <- colnames(res)[idx] index <- I0 projs <- list() projs[[1]] <- A0 print(c("start index: ",I0)) if (gg) ggobi_display_set_tour_projection(d,A0) if (stop.it == "MAXRUNS") { pull.break=FALSE maxRuns=500 } if (stop.it == "NRUNS") { pull.break=TRUE maxRuns=30 runs=30 } if (stop.it == "CONV") { deltaI <- 1 absDelta=0.001 } while (!checkstop()) { B <- proj(df) Ai <- ortho(A0+cool^i*B) Ii <- scagnostics(as.data.frame(df %*% Ai))[idx] Ti <- temp/log(i+1) deltaI <- Ii-I0 rho <- min(exp(deltaI/(Ii*Ti)),1) if (is.na(rho)) rho <- 0 # print(c(i, I0,Ii,deltaI/(Ii*Ti), rho)) if (rbinom(1,1,rho)>0) { A0 <- Ai I0 <- Ii if (gg) ggobi_display_set_tour_projection(d,Ai) i <- i+1 projs[[i]] <- A0 index <- c(index,I0) if (show.index) plot(index, pch=20, ylab=method) } } res <- list(index=index, projs = projs) print(c("end index: ", I0)) return(res) }