-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exporting exact partition function (#412)
* fixing documentation typo * fixing #409
- Loading branch information
Showing
12 changed files
with
132 additions
and
6 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
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
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,26 @@ | ||
#' @title Compute exact partition function | ||
#' | ||
#' @description For Cayley, Hamming, and Kendall distances, computationally | ||
#' tractable functions are available for the exact partition function. | ||
#' | ||
#' @param alpha Dispersion parameter. | ||
#' @param n_items Number of items. | ||
#' @param metric Distance function, one of "cayley", "hamming", or "kendall". | ||
#' | ||
#' @return The logarithm of the partition function. | ||
#' @export | ||
#' | ||
#' @references \insertAllCited{} | ||
#' | ||
#' @example inst/examples/compute_exact_partition_function_example.R | ||
#' @family partition function | ||
compute_exact_partition_function <- function( | ||
alpha, n_items, | ||
metric = c("cayley", "hamming", "kendall")) { | ||
metric <- match.arg(metric, c("cayley", "hamming", "kendall")) | ||
validate_integer(n_items) | ||
validate_positive(n_items) | ||
validate_positive(alpha) | ||
|
||
get_partition_function(alpha, n_items, metric, NULL) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
compute_exact_partition_function( | ||
alpha = 3.4, n_items = 34, metric = "cayley" | ||
) | ||
|
||
compute_exact_partition_function( | ||
alpha = 3.4, n_items = 34, metric = "hamming" | ||
) | ||
|
||
compute_exact_partition_function( | ||
alpha = 3.4, n_items = 34, metric = "kendall" | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,35 @@ | ||
test_that("compute_exact_partition_function works", { | ||
expect_error( | ||
compute_exact_partition_function(3, -1), | ||
"n_items must be a positive integer" | ||
) | ||
expect_error( | ||
compute_exact_partition_function(3, 2.3), | ||
"n_items must be a positive integer" | ||
) | ||
expect_error( | ||
compute_exact_partition_function(3, 0), | ||
"n_items must be a strictly positive number of length one" | ||
) | ||
expect_error( | ||
compute_exact_partition_function(-2, 3), | ||
"alpha must be a strictly positive number of length one" | ||
) | ||
expect_error( | ||
compute_exact_partition_function(rnorm(2), 3), | ||
"alpha must be a strictly positive number of length one" | ||
) | ||
|
||
expect_equal( | ||
compute_exact_partition_function(alpha = 3, n_items = 10, metric = "cayley"), | ||
13.0481794289176 | ||
) | ||
expect_equal( | ||
compute_exact_partition_function(alpha = 3, n_items = 10, metric = "hamming"), | ||
12.4542713806513 | ||
) | ||
expect_equal( | ||
compute_exact_partition_function(alpha = 3, n_items = 10, metric = "kendall"), | ||
9.69641008390133 | ||
) | ||
}) |