Diferenças
Aqui você vê as diferenças entre duas revisões dessa página.
Ambos lados da revisão anteriorRevisão anterior | |||
disciplinas:ce718:atividades2011:pi [2011/06/20 22:08] – [section 3] fernandomayer | disciplinas:ce718:atividades2011:pi [2011/06/21 00:56] (atual) – [section 4] fernandomayer | ||
---|---|---|---|
Linha 164: | Linha 164: | ||
==== Comparação dos algorítmos ==== | ==== Comparação dos algorítmos ==== | ||
+ | |||
+ | === Executando e armazenando tempos e resultados === | ||
+ | |||
+ | <code R> | ||
+ | ## Define um n comum | ||
+ | n1 <- 1:1e+4 | ||
+ | n2 <- seq(0, 1e+6, 1000)[-1] | ||
+ | |||
+ | ## | ||
+ | ## Tempo Eder com n1 | ||
+ | res.eder.n1 <- matrix(NA, ncol=2, nrow=length(n1)) | ||
+ | con <- 1 | ||
+ | eder.n1 <- system.time( | ||
+ | for (i in n1){ | ||
+ | | ||
+ | con <- con+1 | ||
+ | } | ||
+ | ) | ||
+ | |||
+ | ## Tempo Walmes com n1 | ||
+ | walmes.n1 <- system.time( | ||
+ | bf <- buffon.walmes(max(n1)) | ||
+ | ) | ||
+ | res.walmes.n1 <- bf$rho/ | ||
+ | |||
+ | |||
+ | ## Tempo Fernando com n1 | ||
+ | fernando.n1 <- system.time( | ||
+ | | ||
+ | ) | ||
+ | |||
+ | ## Tempo Stuart com n1 | ||
+ | stuart.n1 <- system.time( | ||
+ | | ||
+ | ) | ||
+ | ## | ||
+ | |||
+ | ## Tempo Eder com n2 | ||
+ | res.eder.n2 <- matrix(NA, ncol=2, nrow=length(n2)) | ||
+ | con <- 1 | ||
+ | eder.n2 <- system.time( | ||
+ | for (i in n2){ | ||
+ | | ||
+ | con <- con+1 | ||
+ | } | ||
+ | ) | ||
+ | |||
+ | ## Tempo Walmes com n2 | ||
+ | walmes.n2 <- system.time( | ||
+ | bf <- buffon.walmes(max(n2)) | ||
+ | ) | ||
+ | res.walmes.n2 <- bf$rho/ | ||
+ | |||
+ | |||
+ | ## Tempo Fernando com n2 | ||
+ | fernando.n2 <- system.time( | ||
+ | | ||
+ | ) | ||
+ | |||
+ | ## Tempo Stuart com n2 | ||
+ | stuart.n2 <- system.time( | ||
+ | | ||
+ | ) | ||
+ | #### Parei em 3261 seg. ~ 55 min. | ||
+ | </ | ||
+ | |||
+ | === Comparando performances === | ||
+ | |||
+ | <code R> | ||
+ | ## Usando n1 = 1:1e4 | ||
+ | ## | ||
+ | |||
+ | ## Comparacao de tempos de execucao | ||
+ | tempo.n1 <- c(eder.n1[3], | ||
+ | names(tempo.n1) <- c(" | ||
+ | tempo.n1 <- sort(tempo.n1) | ||
+ | ## barchart | ||
+ | require(lattice) | ||
+ | barchart(tempo.n1, | ||
+ | panel = function(...){ | ||
+ | | ||
+ | | ||
+ | labels = do.call(as.character, | ||
+ | list(round(tempo.n1, | ||
+ | }) | ||
+ | |||
+ | ## Cria um data.frame com todos os resultados | ||
+ | res.n1 <- data.frame(n = n1, | ||
+ | eder = res.eder.n1[, | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | ## modifica o data.frame para o lattice | ||
+ | require(reshape) | ||
+ | res.n1 <- melt(res.n1, | ||
+ | |||
+ | ## Comparacao grafica | ||
+ | xyplot(value ~ n | variable, data = res.n1, type = " | ||
+ | xlab = " | ||
+ | ylab = expression(paste(" | ||
+ | panel = function(...){ | ||
+ | | ||
+ | | ||
+ | }, scales = list(relation = " | ||
+ | |||
+ | ## Usando n2 = seq(0, 1e+6, 1000)[-1] | ||
+ | ## | ||
+ | |||
+ | ## Comparacao de tempos de execucao | ||
+ | tempo.n2 <- c(eder.n2[3], | ||
+ | names(tempo.n2) <- c(" | ||
+ | tempo.n2 <- sort(tempo.n2) | ||
+ | ## barchart | ||
+ | barchart(tempo.n2, | ||
+ | panel = function(...){ | ||
+ | | ||
+ | | ||
+ | labels = do.call(as.character, | ||
+ | list(round(tempo.n2, | ||
+ | }) | ||
+ | |||
+ | ## Cria um data.frame com todos os resultados | ||
+ | ## Stuart nao entra pq nao terminou a execução | ||
+ | ## Walmes fica de fora pq vai ate 1e6 | ||
+ | res.n2 <- data.frame(n = n2, | ||
+ | eder = res.eder.n2[, | ||
+ | | ||
+ | |||
+ | ## modifica o data.frame para o lattice | ||
+ | res.n2 <- melt(res.n2, | ||
+ | |||
+ | ## Comparacao grafica | ||
+ | xyplot(value ~ n | variable, data = res.n2, type = " | ||
+ | xlab = " | ||
+ | ylab = expression(paste(" | ||
+ | panel = function(...){ | ||
+ | | ||
+ | | ||
+ | })#, scales = list(relation = " | ||
+ | |||
+ | ## Plot separado do Walmes | ||
+ | xyplot(res.walmes.n2 ~ 1:max(n2), type = " | ||
+ | xlab = " | ||
+ | ylab = expression(paste(" | ||
+ | panel = function(...){ | ||
+ | | ||
+ | | ||
+ | }) | ||
+ | </ | ||
+ | |||