library(ggplot2) #para graficar
library(dplyr) # verbos para manipulacion de datos
Un dataframe
puede verse como una matriz en donde cada columna puede tener un tipo de datos diferente.
bfs_data<-c(3370, 316, 1688, 4581, 6473, 4345, 1083, 4723, 2950, 4735, 5179, 5423, 4439, 741, 516, 5281, 1240, 4613, 6298, 1293, 2345, 6711, 6518, 855, 272, 1034)
dfs_data<-c(397, 314, 3422, 2717, 5150, 3360, 2001, 845, 3008, 690, 2981, 781, 4068, 207, 1795, 3933, 2979, 1428, 550, 2988)
uni_cost_data<-c(2585, 3261, 1, 3783, 2184, 6730, 114, 5701, 4542, 1125, 3011, 2452, 6369, 1479, 5735, 4632, 5488, 296, 2077, 3702, 6457, 193, 2882, 1787, 6363, 1944, 1961)
uninformed_search<-data.frame(bfs=bfs_data[1:20],dfs=dfs_data,uni_cost=uni_cost_data[1:20])
uninformed_search
ancho
a un formato largo
uninformed_search<-uninformed_search %>% reshape2::melt()
No id variables; using all as measure variables
uninformed_search
El simbolo %>%
es un pipe a la haskell
. Se toma como entrada un dataframe
y la salida es otro dataframe
.
Se agrupa por variable
y por cada variable
se calcula la media y la desviación estandard
uninformed_search_summary <- uninformed_search %>% group_by(variable) %>% summarise(mean=mean(value),sd=sd(value))
uninformed_search_summary
NA
Mostramos la media y deviación standard de cada algoritmo
library(ggplot2)
uninformed_search_summary %>%
ggplot()+
#geom_col(aes(x=variable,y=mean,fill=variable))+
geom_errorbar(aes(x=variable,y=mean,ymin=mean-sd,ymax=mean+sd),width=.2,color='darkgray')+
theme_bw()
uninformed_search %>%
ggplot()+
geom_boxplot(aes(x=variable,y=value,fill=variable),color='darkgray')+
theme_bw()
#ggdark::dark_theme_classic()
sa_df$algorithm<-"SA"
sa_df$run<-seq(1:30)
sa_df$nqueen<-"4"
# 8
time<-rnorm(30,10,5)
states<-rnorm(30,50,5)
h<-rnorm(30,4,1) %>% as.integer()
sa8_df<-data.frame(time=time,states=states,h=h)
sa8_df$algorithm<-"SA"
sa8_df$run<-seq(1:30)
sa8_df$nqueen<-"8"
# 10
time<-rnorm(30,12,1)
states<-rnorm(30,70,5)
h<-rnorm(30,7,4) %>% as.integer()
sa10_df<-data.frame(time=time,states=states,h=h)
sa10_df$algorithm<-"SA"
sa10_df$run<-seq(1:30)
sa10_df$nqueen<-"10"
rbind(sa_df,sa8_df,sa10_df)
/bin/sh: 1: t: not found
Lee y transforma a un dataframe
. Un dataframe
puede verse como una matriz en donde cada columna puede tener un tipo de datos diferente.
library(dplyr) # manupulacion de datos
library(ggplot2) # graficar
library(readr) #lectura de archivos
library(tidyr) #transformacion
local_search<-readr::read_csv("local-search-results.csv")
── Column specification ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
cols(
time = col_double(),
states = col_double(),
h = col_double(),
algorithm = col_character(),
run = col_double(),
nqueen = col_double()
)
local_search
local_search_wide <- local_search %>% tidyr::pivot_wider(names_from = run,
values_from = c("time", "states","h"))
local_search_wide
local_search_long<-local_search %>% tidyr::pivot_longer(!one_of(c("algorithm","nqueen")),
names_to = "metrics",
values_to = "value")
local_search_long
local_search %>% group_by(algorithm,nqueen) %>% summarise(mean_time=mean(time),sd_time=sd(time))
`summarise()` has grouped output by 'algorithm'. You can override using the `.groups` argument.
local_search %>% group_by(algorithm,nqueen) %>% summarise(mean_states=mean(states),
sd_states=sd(states),
mean_time=mean(time),
sd_time=sd(time)
)
`summarise()` has grouped output by 'algorithm'. You can override using the `.groups` argument.
local_search %>% group_by(algorithm,nqueen) %>% summarise(total=n(),
success=sum((h==0)),
perc=success/total
)
`summarise()` has grouped output by 'algorithm'. You can override using the `.groups` argument.
local_search %>% filter(algorithm=="GA")