CAN_Reverse_Engineering/R/city/.Rhistory

168 lines
11 KiB
R

demo()
demo(graphics)
library(rEDM)
devtools::install_github("ha0ye/rEDM")
library(devtools)
libary(rEDM)
package(rEDM)
library(rEDM)
setwd("C:/Users/brent/Google Drive/AFIT/PhD Research/Validation/R/city")
speed_brake_rpm <- read.csv("speed_brake_rpm_city.csv")
load(smap_output_brake.RDA)
load(smap_output_brake.Rda)
load(file = "smap_output_brake.Rda")
View(smap_output_brake)
View(speed_brake_rpm)
lib <- c(1, 0.5*length(speed_brake_rpm))
pred <- c(0.5*length(speed_brake_rpm)+1, length(speed_brake_rpm))
len(speed_brake_rpm)
data(speed_brake_rpm)
length(speed_brake_rpm)
lib <- c(1, 0.5*22792)
pred <- c(0.5*22792+1, 22792)
cols <- c("speed", "rpm", "brake")
target <- "brake"
block_smap_output <- block_lnlp(speed_brake_rpm, lib = lib, pred = pred, columns = cols, target_column = target, method = "s-map", theta = 3, stats_only = FALSE, first_column_time = TRUE, save_smap_coefficients = TRUE, silent = TRUE)
save(block_smap_output, file = "brake_block_smap_output.Rda")
smap_coeffs <- block_smap_output$smap_coefficients[[1]]
str(smap_coeffs)
predictions <- block_smap_output$model_output[[1]] t <- predictions$time
plot(t, predictions$obs, type = "l", col = "black", ylab = "x", xlab = "")
lines(t, predictions$pred, lty = 2)
legend("topright", legend = c("observed", "predicted"), lty = c(1, 2), bty = "n")
plot(t, smap_coeffs[, 1], type = "l", col = "red", ylab = "effect of speed", xlab = "")
plot(t, smap_coeffs[, 2], type = "l", col = "blue", ylab = "effect of rpm", xlab = "")
plot(t, smap_coeffs[, 3], type = "l", col = "magenta", ylab = "effect of lags", xlab = "")
predictions <- block_smap_output$model_output[[1]]
t <- predictions$time
plot(t, predictions$obs, type = "l", col = "black", ylab = "x", xlab = "")
lines(t, predictions$pred, lty = 2)
legend("topright", legend = c("observed", "predicted"), lty = c(1, 2), bty = "n")
plot(t, smap_coeffs[, 1], type = "l", col = "red", ylab = "effect of speed", xlab = "")
plot(t, smap_coeffs[, 2], type = "l", col = "blue", ylab = "effect of rpm", xlab = "")
plot(t, smap_coeffs[, 3], type = "l", col = "magenta", ylab = "effect of lags", xlab = "")
cols = c("brake", "speed", "rpm")
block_smap_output <- block_lnlp(speed_brake_rpm, lib = lib, pred = pred, columns = cols, target_column = target, method = "s-map", theta = 3, stats_only = FALSE, first_column_time = TRUE, save_smap_coefficients = TRUE, silent = TRUE)
save(block_smap_output, file = "brake_block_smap_output.Rda")
smap_coeffs <- block_smap_output$smap_coefficients[[1]]
str(smap_coeffs)
predictions <- block_smap_output$model_output[[1]]
t <- predictions$time
plot(t, predictions$obs, type = "l", col = "black", ylab = "x", xlab = "")
lines(t, predictions$pred, lty = 2)
legend("topright", legend = c("observed", "predicted"), lty = c(1, 2), bty = "n")
plot(t, smap_coeffs[, 1], type = "l", col = "red", ylab = "effect of lags", xlab = "")
plot(t, smap_coeffs[, 2], type = "l", col = "blue", ylab = "effect of speed", xlab = "")
plot(t, smap_coeffs[, 3], type = "l", col = "magenta", ylab = "effect of rpm", xlab = "")
cols = c("speed", "rpm")
block_smap_output <- block_lnlp(speed_brake_rpm, lib = lib, pred = pred, columns = cols, target_column = target, method = "s-map", theta = 3, stats_only = FALSE, first_column_time = TRUE, save_smap_coefficients = TRUE, silent = TRUE)
smap_coeffs <- block_smap_output$smap_coefficients[[1]]
str(smap_coeffs)
predictions <- block_smap_output$model_output[[1]]
t <- predictions$time
plot(t, predictions$obs, type = "l", col = "black", ylab = "x", xlab = "")
lines(t, predictions$pred, lty = 2)
legend("topright", legend = c("observed", "predicted"), lty = c(1, 2), bty = "n")
plot(t, smap_coeffs[, 1], type = "l", col = "red", ylab = "effect of speed", xlab = "")
plot(t, smap_coeffs[, 2], type = "l", col = "blue", ylab = "effect of rpm", xlab = "")
list_of_model_predictions <- block_smap_output$model_output
first_data_frame_of_predictions <- list_of_model_predictions[[1]]
observed <- first_data_frame_of_predictions$obs
predicted <- first_data_frame_of_predictions$pred
plot_range <- range(c(observed, predicted), na.rm = TRUE)
plot(observed, predicted, xlim = plot_range, ylim = plot_range, xlab = "Observed", ylab = "Predicted", asp = 1)
abline(a = 0, b = 1, lty = 2, col = "blue")
View(block_smap_output)
View(block_smap_output)
View(first_data_frame_of_predictions)
View(first_data_frame_of_predictions)
View(block_smap_output)
str(block_smap_output.rmse)
str(block_smap_output$rmse)
data(block_3sp)
View(block_3sp)
block_smap_output <- block_lnlp(speed_brake_rpm, lib = lib, pred = pred, columns = cols, target_column = target, method = "s-map", tp = 300, theta = 3, stats_only = FALSE, first_column_time = TRUE, save_smap_coefficients = TRUE, silent = TRUE)
smap_coeffs <- block_smap_output$smap_coefficients[[1]]
str(smap_coeffs)
predictions <- block_smap_output$model_output[[1]]
t <- predictions$time
plot(t, predictions$obs, type = "l", col = "black", ylab = "x", xlab = "")
lines(t, predictions$pred, lty = 2)
legend("topright", legend = c("observed", "predicted"), lty = c(1, 2), bty = "n")
plot(t, smap_coeffs[, 1], type = "l", col = "red", ylab = "effect of speed", xlab = "")
plot(t, smap_coeffs[, 2], type = "l", col = "blue", ylab = "effect of rpm", xlab = "")
View(block_smap_output)
list_of_model_predictions <- block_smap_output$model_output
first_data_frame_of_predictions <- list_of_model_predictions[[1]]
observed <- first_data_frame_of_predictions$obs
predicted <- first_data_frame_of_predictions$pred
plot_range <- range(c(observed, predicted), na.rm = TRUE)
plot(observed, predicted, xlim = plot_range, ylim = plot_range, xlab = "Observed", ylab = "Predicted", asp = 1)
abline(a = 0, b = 1, lty = 2, col = "blue")
load(file = "ccm_optimal_tp.Rda")
View(output_df)
View(output_df)
ccm_speed_xmap_brake_neg400 = ccm(speed_brake_rpm, E = 9, lib_sizes = NROW(speed_brake_rpm), lib_column = "speed", target_column = "brake", tp = -400, random_libs = FALSE, num_neighbors = "E+1", silent = TRUE, stats_only=FALSE, first_column_time = TRUE)
ccm_speed_xmap_brake_neg400 = ccm(speed_brake_rpm, E = 9, lib_sizes = NROW(speed_brake_rpm), lib_column = "speed", target_column = "brake", tp = -400, random_libs = FALSE, num_neighbors = "E+1", silent = TRUE, first_column_time = TRUE)
View(ccm_speed_xmap_brake_neg400)
View(smap_output_brake)
output_df_means <- ccm_means(output_df)
warnings()
View(output_df_means)
output_brake <- output_df[11]
View(output_brake)
output_brake <- output_df[[11]]
View(output_df)
output_brake <- ccm_means(output_df[11])
output_brake <- ccm_means(output_df[[11]])
output_df[[11]]
output_df[11]
output_df[11,]
output_brake <- ccm_means(output_df[11,])
output_brake <- output_df[11,]
View(output_brake)
output_brake <- output_brake[,-1]
output_brake <- output_df[11,]
output_brake <- output_brake[,-1]
output_brake <- output_df[11,]
output_brake <- output_brake[,-12]
output_brake <- ccm_means(output_brake)
View(output_brake)
View(ccm_speed_xmap_brake_neg400)
output_brake <- ccm_means(ccm_speed_xmap_brake_neg400)
View(output_brake)
View(ccm_speed_xmap_brake_neg400)
brake_observed <- compute_stats
View(brake_observed)
compute_stats(ccm_speed_xmap_brake_neg400)
compute_stats(speed_brake_rpm$brake, ccm_speed_xmap_brake_neg400)
View(ccm_speed_xmap_brake_neg400)
brake_multiview <- multiview(speed_brake_rpm, lib = c(1, floor(NROW(speed_brake_rpm)/2)), pred = c(floor(NROW(speed_brake_rpm)/2) + 1, NROW(speed_brake_rpm)), norm_type = "L2 norm", P = 0.5, E = 9, tau = 1, tp = -300, max_lag = 3, num_neighbors = "e+1", k = "sqrt", na.rm = FALSE, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, exclusion_radius = NULL, silent = TRUE)
brake_multiview <- multiview(speed_brake_rpm, lib = c(1, floor(NROW(speed_brake_rpm)/2)), pred = c(floor(NROW(speed_brake_rpm)/2) + 1, NROW(speed_brake_rpm)), norm_type = "L2 norm", P = 0.5, E = 9, tau = 1, tp = -300, max_lag = 3, num_neighbors = "e+1", k = "sqrt", na.rm = FALSE, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, exclusion_radius = NULL, silent = TRUE, k = "all")
brake_multiview <- multiview(speed_brake_rpm, lib = c(1, floor(NROW(speed_brake_rpm)/2)), pred = c(floor(NROW(speed_brake_rpm)/2) + 1, NROW(speed_brake_rpm)), norm_type = "L2 norm", P = 0.5, E = 9, tau = 1, tp = -300, max_lag = 3, num_neighbors = "e+1", k = "sqrt", na.rm = FALSE, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, exclusion_radius = NULL, silent = TRUE)
brake_multiview <- multiview(speed_brake_rpm, lib = c(1, floor(NROW(speed_brake_rpm)/2)), pred = c(floor(NROW(speed_brake_rpm)/2) + 1, NROW(speed_brake_rpm)), norm_type = "L2 norm", E = 9, tau = 1, tp = -300, max_lag = 3, num_neighbors = "e+1", k = "sqrt", na.rm = FALSE, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, exclusion_radius = NULL, silent = TRUE)
brake_multiview <- multiview(speed_brake_rpm, lib = c(1, floor(NROW(speed_brake_rpm)/2)), pred = c(floor(NROW(speed_brake_rpm)/2) + 1, NROW(speed_brake_rpm)), norm_type = "L2 norm", E = 9, tau = 1, tp = 1, max_lag = 3, num_neighbors = "e+1", k = "sqrt", na.rm = FALSE, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, exclusion_radius = NULL, silent = TRUE)
View(speed_brake_rpm)
brake_multiview <- multiview(speed_brake_rpm, lib = c(1, floor(NROW(speed_brake_rpm)/2)), pred = c(floor(NROW(speed_brake_rpm)/2) + 1, NROW(speed_brake_rpm)), norm_type = "L2 norm", E = 9, tau = 1, tp = 1, max_lag = 3, num_neighbors = "e+1", k = "sqrt", na.rm = FALSE, target_column = "brake", stats_only = FALSE, first_column_time = TRUE, silent = TRUE)
brake_multiview <- multiview(speed_brake_rpm, target_column = "brake", stats_only = FALSE, first_column_time = TRUE, silent = TRUE)
View(brake_multiview)
predictions <- brake_multiview$model_output[[1]]
t <- predictions$time
plot(t, predictions$obs, type = "l", col = "black", ylab = "x", xlab = "")
lines(t, predictions$pred, lty = 2)
legend("topright", legend = c("observed", "predicted"), lty = c(1, 2), bty = "n")
save(brake_multiview, file = "brake_multiview.Rda")
View(brake_multiview)
brake_multiview <- multiview(speed_brake_rpm, lib = c(1, floor(NROW(speed_brake_rpm)/2)), pred = c(floor(NROW(speed_brake_rpm)/2) + 1, NROW(speed_brake_rpm)), norm_type = "L2 norm", E = 9, tau = 1, tp = -300, max_lag = 3, num_neighbors = "e+1", k = "sqrt", na.rm = FALSE, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, exclusion_radius = NULL, silent = TRUE)
brake_multiview <- multiview(speed_brake_rpm, E = 9, tau = 1, tp = -300, max_lag = 3, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, silent = TRUE)
brake_multiview <- multiview(speed_brake_rpm, tau = 1, tp = -300, max_lag = 3, target_column = "brake", stats_only = FALSE, save_lagged_block = TRUE, first_column_time = TRUE, silent = TRUE)
View(brake_multiview)
load(file = "brake_multiview.Rda")
multiview_output <- brake_multiview$model_output
View(multiview_output)
multiview_output <- multiview_output[1]
View(multiview_output)
multiview_output <- multiview_output[[1]]
View(multiview_output)
write.csv(multiview_output, file = "multiview_brake.csv")