-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Working function resides in cbrw.R - Updated documentation - Improved performance of Wb generation slightly - Made all dplyr functions specify namespace explicitly - Removed full import of tidyr in favor of only `spread()` - Removed `plot_cbrw()` for now, as it was non-functional - fill arugment in matrix.R#61 replaced with numeric instead of int which was being coerced anyway TODO: More documentation
- Loading branch information
1 parent
d9ae52b
commit 08e8e02
Showing
5 changed files
with
123 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ License: file LICENSE | |
Encoding: UTF-8 | ||
LazyData: true | ||
RoxygenNote: 6.1.1 | ||
Suggests: testthat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(biased_trans_matrix) | ||
export(cbrw) | ||
import(dplyr) | ||
import(rlang) | ||
import(tidyr) | ||
importFrom(tidyr,spread) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#' @title Coupled Biased Random Walks | ||
#' TODO | ||
#' @param data a data.frame containing catgorical data | ||
#' @value the input data frame with an additional \emph{score} variable representing | ||
#' relative outlier-ness of the observation | ||
#' @export | ||
cbrw <- function(data) { | ||
# TODO: defensive programming for type, id vars, high-dimensionality | ||
|
||
# Set up and compute the biased transistion matrix | ||
# returns a list with Wb, nodes, and edges | ||
computed <- biased_trans_matrix(data, all_data = TRUE) | ||
|
||
# Run random walk on Wb | ||
pi_t <- random_walk(computed$Wb) | ||
|
||
# Compute feature relevance and use that to compute | ||
# the value score for each feature value | ||
computed$nodes <- computed$nodes %>% | ||
dplyr::mutate( | ||
value_score = c(pi_t) | ||
) %>% | ||
dplyr::group_by(feature) %>% | ||
dplyr::mutate( | ||
rel = sum(value_score) | ||
) %>% | ||
dplyr::ungroup() %>% | ||
dplyr::mutate(total_score = rel * value_score) | ||
|
||
# Using the integer tibble as an index, create a new tibble | ||
# with the value scores in place of each feature value int | ||
# then take the rowsum to compute the observation score | ||
obs_scores <- computed$data %>% | ||
dplyr::mutate_all(dplyr::funs(computed$nodes[["total_score"]][.])) %>% | ||
rowSums | ||
|
||
# Append the observation scores and return | ||
data <- data %>% | ||
dplyr::mutate(score = obs_scores) | ||
|
||
return(data) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters