Skip to content

Commit

Permalink
unify and cleanup docs, add package-level docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mnwright committed May 27, 2024
1 parent 4d9c6b0 commit 8b31843
Show file tree
Hide file tree
Showing 21 changed files with 194 additions and 22 deletions.
20 changes: 18 additions & 2 deletions R/adversarial_rf.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,28 @@
#'
#'
#' @examples
#' # Train ARF and estimate leaf parameters
#' arf <- adversarial_rf(iris)
#' psi <- forde(arf, iris)
#'
#' # Generate 100 synthetic samples from the iris dataset
#' x_synth <- forge(psi, n_synth = 100)
#'
#' # Condition on Species = "setosa" and Sepal.Length > 6
#' evi <- data.frame(Species = "setosa",
#' Sepal.Length = "(6, Inf)")
#' x_synth <- forge(psi, n_synth = 100, evidence = evi)
#'
#' @seealso
#' \code{\link{forde}}, \code{\link{forge}}
#' # Estimate average log-likelihood
#' ll <- lik(psi, iris, arf = arf, log = TRUE)
#' mean(ll)
#'
#' # Expectation of Sepal.Length for class setosa
#' evi <- data.frame(Species = "setosa")
#' expct(psi, query = "Sepal.Length", evidence = evi)
#'
#' @seealso
#' \code{\link{arf}}, \code{\link{forde}}, \code{\link{forge}}, \code{\link{expct}}, \code{\link{lik}}
#'
#' @export
#' @import ranger
Expand Down
34 changes: 34 additions & 0 deletions R/arf-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#' @seealso
#' \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{forge}}, \code{\link{expct}}, \code{\link{lik}}
#'
#' Useful links:
#' \itemize{
#' \item \url{https://github.com/bips-hb/arf}
#' \item \url{https://bips-hb.github.io/arf/}
#' \item Report bugs at \url{https://github.com/bips-hb/arf/issues}
#' }
#' @examples
#' # Train ARF and estimate leaf parameters
#' arf <- adversarial_rf(iris)
#' psi <- forde(arf, iris)
#'
#' # Generate 100 synthetic samples from the iris dataset
#' x_synth <- forge(psi, n_synth = 100)
#'
#' # Condition on Species = "setosa" and Sepal.Length > 6
#' evi <- data.frame(Species = "setosa",
#' Sepal.Length = "(6, Inf)")
#' x_synth <- forge(psi, n_synth = 100, evidence = evi)
#'
#' # Estimate average log-likelihood
#' ll <- lik(psi, iris, arf = arf, log = TRUE)
#' mean(ll)
#'
#' # Expectation of Sepal.Length for class setosa
#' evi <- data.frame(Species = "setosa")
#' expct(psi, query = "Sepal.Length", evidence = evi)
"_PACKAGE"

## usethis namespace: start
## usethis namespace: end
NULL
4 changes: 2 additions & 2 deletions R/expct.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#'
#'
#' @examples
#' # Train ARF and corresponding circuit
#' # Train ARF and estimate leaf parameters
#' arf <- adversarial_rf(iris)
#' psi <- forde(arf, iris)
#'
Expand All @@ -67,7 +67,7 @@
#' x_synth <- expct(psi, evidence = evi)
#'
#' @seealso
#' \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{lik}}
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{forge}}, \code{\link{lik}}
#'
#'
#' @export
Expand Down
19 changes: 17 additions & 2 deletions R/forde.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,28 @@
#'
#'
#' @examples
#' # Train ARF and estimate leaf parameters
#' arf <- adversarial_rf(iris)
#' psi <- forde(arf, iris)
#' head(psi)
#'
#' # Generate 100 synthetic samples from the iris dataset
#' x_synth <- forge(psi, n_synth = 100)
#'
#' # Condition on Species = "setosa" and Sepal.Length > 6
#' evi <- data.frame(Species = "setosa",
#' Sepal.Length = "(6, Inf)")
#' x_synth <- forge(psi, n_synth = 100, evidence = evi)
#'
#' # Estimate average log-likelihood
#' ll <- lik(psi, iris, arf = arf, log = TRUE)
#' mean(ll)
#'
#' # Expectation of Sepal.Length for class setosa
#' evi <- data.frame(Species = "setosa")
#' expct(psi, query = "Sepal.Length", evidence = evi)
#'
#' @seealso
#' \code{\link{adversarial_rf}}, \code{\link{forge}}, \code{\link{lik}}
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forge}}, \code{\link{expct}}, \code{\link{lik}}
#'
#'
#' @export
Expand Down
5 changes: 4 additions & 1 deletion R/forge.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@
#'
#'
#' @examples
#' # Train ARF and estimate leaf parameters
#' arf <- adversarial_rf(iris)
#' psi <- forde(arf, iris)
#'
#' # Generate 100 synthetic samples from the iris dataset
#' x_synth <- forge(psi, n_synth = 100)
#'
#' # Condition on Species = "setosa"
Expand Down Expand Up @@ -82,7 +85,7 @@
#' x_synth <- forge(psi, n_synth = 100, evidence = evi)
#'
#' @seealso
#' \code{\link{adversarial_rf}}, \code{\link{forde}}
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{expct}}, \code{\link{lik}}
#'
#' @export
#' @import data.table
Expand Down
6 changes: 4 additions & 2 deletions R/lik.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@
#'
#'
#' @examples
#' # Estimate average log-likelihood
#' # Train ARF and estimate leaf parameters
#' arf <- adversarial_rf(iris)
#' psi <- forde(arf, iris)
#'
#' # Estimate average log-likelihood
#' ll <- lik(psi, iris, arf = arf, log = TRUE)
#' mean(ll)
#'
Expand All @@ -75,7 +77,7 @@
#' lik(psi, query = iris[1, 1:3], evidence = evi)
#'
#' @seealso
#' \code{\link{adversarial_rf}}, \code{\link{forge}}
#' \code{\link{arf}}, \code{\link{adversarial_rf}}, \code{\link{forde}}, \code{\link{forge}}, \code{\link{expct}}
#'
#'
#' @export
Expand Down
13 changes: 8 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#'
#' @param cn Column names.
#' @param old_name Name of column to be renamed.
#'
#' @keywords internal

col_rename <- function(cn, old_name) {
k <- 1L
Expand All @@ -26,6 +26,7 @@ col_rename <- function(cn, old_name) {
#' @param cn Old column names.
#'
#' @return New columns names.
#' @keywords internal

col_rename_all <- function(cn) {

Expand Down Expand Up @@ -56,6 +57,7 @@ col_rename_all <- function(cn) {
#' @param ... Further arguments for sample().
#'
#' @return A vector of length size with elements drawn from x.
#' @keywords internal

resample <- function(x, ...) {
x[sample.int(length(x), ...)]
Expand All @@ -66,6 +68,7 @@ resample <- function(x, ...) {
#' @param x A numeric vector.
#'
#' @return Index of maximum value in x, with random tie-breaking.
#' @keywords internal

which.max.random <- function(x) {
if (all(is.na(x))) {
Expand All @@ -79,7 +82,7 @@ which.max.random <- function(x) {
#' This function prepares input data for ARFs.
#'
#' @param x Input data.frame.
#'
#' @keywords internal

prep_x <- function(x) {
# Reclass all non-numeric features as factors
Expand Down Expand Up @@ -129,7 +132,7 @@ prep_x <- function(x) {
#' @param params Circuit parameters learned via \code{\link{forde}}.
#'
#' @import data.table
#'
#' @keywords internal

post_x <- function(x, params) {

Expand Down Expand Up @@ -204,7 +207,7 @@ post_x <- function(x, params) {
#' @importFrom foreach foreach %dopar%
#' @importFrom truncnorm dtruncnorm ptruncnorm
#' @importFrom stats dunif punif
#'
#' @keywords internal

cforde <- function(params, evidence, row_mode = c("separate", "or"), stepsize = 0, parallel = TRUE) {

Expand Down Expand Up @@ -494,7 +497,7 @@ cforde <- function(params, evidence, row_mode = c("separate", "or"), stepsize =
#'
#' @import data.table
#' @import stringr
#'
#' @keywords internal

prep_cond <- function(evidence, params, row_mode) {

Expand Down
19 changes: 18 additions & 1 deletion man/adversarial_rf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions man/arf-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/cforde.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/col_rename.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/col_rename_all.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/expct.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions man/forde.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion man/forge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8b31843

Please sign in to comment.