Skip to content

Commit

Permalink
fix clean calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mdancho84 committed Oct 29, 2023
1 parent 1f04fab commit d9a251c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/00_global_vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ globalVariables(
".metric", ".metrics", ".rank_metric", ".rank_std_err", "failure_rate", "std_err",
".rank_failure_rate", ".txt", "training", "testing", "fitted", "model", "..val", "..nm",
".white_noise_lower", ".white_noise_upper", ".date_var_collapsed", ".rowid", "..date_agg", "grp_names",
"check_row_exists", ".box_group", ".observed_cleaned")
"check_row_exists", ".box_group", ".observed_clean")
)
6 changes: 3 additions & 3 deletions R/anomalize-plotting.R
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ plot_anomalies_cleaned <- function(
}

column_names <- names(.data)
check_names <- c("observed", "observed_cleaned") %in% column_names
check_names <- c("observed", "observed_clean") %in% column_names
if (!all(check_names)) stop('Error in plot_anomalies_decomp(): column names are missing. Run `anomalize()` and make sure: observed, remainder, anomaly, recomposed_l1, and recomposed_l2 are present', call. = FALSE)

UseMethod("plot_anomalies_cleaned", .data)
Expand Down Expand Up @@ -821,10 +821,10 @@ plot_anomalies_cleaned.data.frame <- function(
g <- g +
ggplot2::scale_color_manual(values = c(.line_color, .cleaned_line_color))

# Add line - observed_cleaned
# Add line - observed_clean
g <- g +
ggplot2::geom_line(
ggplot2::aes(y = observed_cleaned, color = "Observed Cleaned"),
ggplot2::aes(y = observed_clean, color = "Observed Cleaned"),
# color = .cleaned_line_color,
linewidth = .cleaned_line_size,
linetype = .cleaned_line_type,
Expand Down
6 changes: 3 additions & 3 deletions R/anomalize.R
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ anomalize.data.frame <- function(
# Clean
ret <- ret %>%
dplyr::mutate(
observed_cleaned = dplyr::case_when(
anomaly_direction == -1 ~ .clean_alpha * recomposed_l1,
anomaly_direction == 1 ~ .clean_alpha * recomposed_l2,
observed_clean = dplyr::case_when(
anomaly_direction == -1 ~ recomposed_l1 + (1-.clean_alpha)*anomaly_score,
anomaly_direction == 1 ~ recomposed_l2 - (1-.clean_alpha)*anomaly_score,
TRUE ~ observed
)
)
Expand Down

0 comments on commit d9a251c

Please sign in to comment.