minmax.R (6441B)
1 library(DBI) 2 3 source("R/common.R") 4 5 gnuplot <- function (file, str, ...) { 6 cat(sprintf(str, ...), file=file, append=TRUE) 7 } 8 gnuplot_all <- function (filename, prefix, rmse_column, row_min, row_max) { 9 f <- filename 10 cat("",file=f) 11 gnuplot(f, paste(prefix,"_rmse_min = %f\n",sep=""), row_min[rmse_column]) 12 gnuplot(f, paste(prefix,"_rmse_min_timestamp = %d\n",sep=""), as.integer(row_min["timestamp"])) 13 gnuplot(f, paste(prefix,"_rmse_min_speed = %f\n",sep=""), row_min["speed"]) 14 gnuplot(f, paste(prefix,"_rmse_min_direction = %f\n",sep=""), row_min["direction"]) 15 gnuplot(f, paste(prefix,"_rmse_max = %f\n",sep=""), row_max[rmse_column]) 16 gnuplot(f, paste(prefix,"_rmse_max_timestamp = %d\n",sep=""), as.integer(row_max["timestamp"])) 17 gnuplot(f, paste(prefix,"_rmse_max_speed = %f\n",sep=""), row_max["speed"]) 18 gnuplot(f, paste(prefix,"_rmse_max_direction = %f\n",sep=""), row_max["direction"]) 19 } 20 21 data <- read.table("build/daily-rmse", sep="", header=TRUE) 22 z_rmse_sorted <- sort(data$z_rmse, decreasing=TRUE) 23 print("Min. velocity RMSE") 24 print(data[data$x_rmse == min(data$x_rmse), ]) 25 print(data[data$y_rmse == min(data$y_rmse), ]) 26 print(data[data$z_rmse == min(data$z_rmse), ]) 27 print("Max. velocity RMSE") 28 print(data[data$x_rmse == max(data$x_rmse), ]) 29 print(data[data$y_rmse == max(data$y_rmse), ]) 30 print(data[data$z_rmse == z_rmse_sorted[[1]], ]) 31 print(data[data$z_rmse == z_rmse_sorted[[2]], ]) 32 print("Mean velocity RMSE") 33 print(summary(data)) 34 with(list(tmp = data[data$x_rmse == min(data$x_rmse), ]), 35 printf("Velocity X min. RMSE = %f (%s), mean speed = %f\n", tmp["x_rmse"], tmp["timestamp"], tmp["speed"])) 36 with(list(tmp = data[data$y_rmse == min(data$y_rmse), ]), 37 printf("Velocity Y min. RMSE = %f (%s), mean speed = %f\n", tmp["y_rmse"], tmp["timestamp"], tmp["speed"])) 38 with(list(tmp = data[data$z_rmse == min(data$z_rmse), ]), 39 printf("Velocity Z min. RMSE = %f (%s), mean speed = %f\n", tmp["z_rmse"], tmp["timestamp"], tmp["speed"])) 40 with(list(tmp = data[data$x_rmse == max(data$x_rmse), ]), 41 printf("Velocity X max. RMSE = %f (%s), mean speed = %f\n", tmp["x_rmse"], tmp["timestamp"], tmp["speed"])) 42 with(list(tmp = data[data$y_rmse == max(data$y_rmse), ]), 43 printf("Velocity Y max. RMSE = %f (%s), mean speed = %f\n", tmp["y_rmse"], tmp["timestamp"], tmp["speed"])) 44 with(list(tmp = data[data$z_rmse == max(data$z_rmse), ]), 45 printf("Velocity Z max. RMSE = %f (%s), mean speed = %f\n", tmp["z_rmse"], tmp["timestamp"], tmp["speed"])) 46 #print(data) 47 gnuplot_all("build/gnuplot/x_rmse.gnuplot", "x", "x_rmse", 48 data[data$x_rmse == min(data$x_rmse),], 49 data[data$x_rmse == max(data$x_rmse),]) 50 gnuplot_all("build/gnuplot/y_rmse.gnuplot", "y", "y_rmse", 51 data[data$y_rmse == min(data$y_rmse),], 52 data[data$y_rmse == max(data$y_rmse),]) 53 gnuplot_all("build/gnuplot/z_rmse.gnuplot", "z", "z_rmse", 54 data[data$z_rmse == min(data$z_rmse),], 55 data[data$z_rmse == max(data$z_rmse),]) 56 57 direction_rmse_min = data[data$direction_rmse == min(data$direction_rmse), ] 58 direction_rmse_max = data[data$direction_rmse == max(data$direction_rmse), ] 59 direction_rmse_mean = mean(data$direction_rmse) 60 printf("Min. direction RMSE = %f (%s), mean direction = %f, mean speed = %f\n", 61 direction_rmse_min["direction_rmse"], 62 direction_rmse_min["timestamp"], 63 direction_rmse_min["direction"], 64 direction_rmse_min["speed"]) 65 printf("Max. direction RMSE = %f (%s), mean direction = %f, mean speed = %f\n", 66 direction_rmse_max["direction_rmse"], 67 direction_rmse_max["timestamp"], 68 direction_rmse_max["direction"], 69 direction_rmse_max["speed"]) 70 printf("Mean direction RMSE = %f\n", direction_rmse_mean) 71 gnuplot_all("build/gnuplot/direction_rmse.gnuplot", 72 "direction", "direction_rmse", direction_rmse_min, direction_rmse_max) 73 74 filename <- "build/gnuplot/acf_rmse.gnuplot" 75 cat("",file=filename) 76 gnuplot <- function (str, ...) { 77 cat(sprintf(str, ...), file=filename, append=TRUE) 78 } 79 with(list(tmp = data[data$acf_x_rmse == min(data$acf_x_rmse), ]), 80 { 81 gnuplot("acf_x_rmse_min = %f\n", tmp["acf_x_rmse"]) 82 gnuplot("acf_x_rmse_min_timestamp = %d\n", as.integer(tmp["timestamp"])) 83 gnuplot("acf_x_rmse_min_speed = %f\n", tmp["speed"]) 84 printf("ACF X min. RMSE = %f (%s), mean speed = %f\n", 85 tmp["acf_x_rmse"], tmp["timestamp"], tmp["speed"]) 86 }) 87 with(list(tmp = data[data$acf_y_rmse == min(data$acf_y_rmse), ]), 88 { 89 gnuplot("acf_y_rmse_min = %f\n", tmp["acf_y_rmse"]) 90 gnuplot("acf_y_rmse_min_timestamp = %d\n", as.integer(tmp["timestamp"])) 91 gnuplot("acf_y_rmse_min_speed = %f\n", tmp["speed"]) 92 printf("ACF Y min. RMSE = %f (%s), mean speed = %f\n", 93 tmp["acf_y_rmse"], tmp["timestamp"], tmp["speed"]) 94 }) 95 with(list(tmp = data[data$acf_z_rmse == min(data$acf_z_rmse), ]), 96 { 97 gnuplot("acf_z_rmse_min = %f\n", tmp["acf_z_rmse"]) 98 gnuplot("acf_z_rmse_min_timestamp = %d\n", as.integer(tmp["timestamp"])) 99 gnuplot("acf_z_rmse_min_speed = %f\n", tmp["speed"]) 100 printf("ACF Z min. RMSE = %f (%s), mean speed = %f\n", tmp["acf_z_rmse"], tmp["timestamp"], tmp["speed"]) 101 }) 102 with(list(tmp = data[data$acf_x_rmse == max(data$acf_x_rmse), ]), 103 { 104 gnuplot("acf_x_rmse_max = %f\n", tmp["acf_x_rmse"]) 105 gnuplot("acf_x_rmse_max_timestamp = %d\n", as.integer(tmp["timestamp"])) 106 gnuplot("acf_x_rmse_max_speed = %f\n", tmp["speed"]) 107 printf("ACF X max. RMSE = %f (%s), mean speed = %f\n", tmp["acf_x_rmse"], tmp["timestamp"], tmp["speed"]) 108 }) 109 with(list(tmp = data[data$acf_y_rmse == max(data$acf_y_rmse), ]), 110 { 111 gnuplot("acf_y_rmse_max = %f\n", tmp["acf_y_rmse"]) 112 gnuplot("acf_y_rmse_max_timestamp = %d\n", as.integer(tmp["timestamp"])) 113 gnuplot("acf_y_rmse_max_speed = %f\n", tmp["speed"]) 114 printf("ACF Y max. RMSE = %f (%s), mean speed = %f\n", tmp["acf_y_rmse"], tmp["timestamp"], tmp["speed"]) 115 }) 116 with(list(tmp = data[data$acf_z_rmse == max(data$acf_z_rmse), ]), 117 { 118 gnuplot("acf_z_rmse_max = %f\n", tmp["acf_z_rmse"]) 119 gnuplot("acf_z_rmse_max_timestamp = %d\n", as.integer(tmp["timestamp"])) 120 gnuplot("acf_z_rmse_max_speed = %f\n", tmp["speed"]) 121 printf("ACF Z max. RMSE = %f (%s), mean speed = %f\n", tmp["acf_z_rmse"], tmp["timestamp"], tmp["speed"]) 122 }) 123 124 print(cor(data)["speed",])