-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initialize nuts sampler class * implement the burnin of nuts sampler * add tests and resolve bugs * implement e0 estimation in burnin of nuts * optimize leapfrog * integrate nuts into the R interface * document random walk in sample_points.cpp in R interface * fix burnin for the non-truncated case * resolve bugs in hmc and nuts pipelines * improve the preprocess in burin step of nuts * split large lines in sample_points.cpp * Add NUTS C++ example and update CMake (#29) * resolve PR comments * fix minor bug * fix compiler bug * fix error in building the C++ examples * resolve warnings in sample_points * fix lpsolve cran warning * fix cran warning on mac * improve lpsolve cmake for cran check * fix R warning in mac test * remove lpsolve header * resolve PR comments --------- Co-authored-by: Marios Papachristou <[email protected]> Co-authored-by: Apostolos Chalkis (TolisChal) <[email protected]>
- Loading branch information
1 parent
9cfdfe1
commit 9539796
Showing
17 changed files
with
732 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# VolEsti (volume computation and sampling library) | ||
|
||
# Copyright (c) 2012-2020 Vissarion Fisikopoulos | ||
# Copyright (c) 2018-2020 Apostolos Chalkis | ||
# Copyright (c) 2020-2020 Marios Papachristou | ||
|
||
# Contributed and/or modified by Marios Papachristou, as part of Google Summer of Code 2020 program. | ||
|
||
# Licensed under GNU LGPL.3, see LICENCE file | ||
|
||
# Example script for using the logconcave sampling methods | ||
|
||
# Import required libraries | ||
library(ggplot2) | ||
library(volesti) | ||
|
||
# Sampling from logconcave density example | ||
|
||
# Helper function | ||
norm_vec <- function(x) sqrt(sum(x^2)) | ||
|
||
# Negative log-probability oracle | ||
f <- function(x) (norm_vec(x)^2 + sum(x)) | ||
|
||
# Negative log-probability gradient oracle | ||
grad_f <- function(x) (2 * x + 1) | ||
|
||
dimension <- 50 | ||
facets <- 200 | ||
|
||
# Create domain of truncation | ||
H <- gen_rand_hpoly(dimension, facets, seed = 15) | ||
|
||
# Rounding | ||
Tr <- rounding(H, seed = 127) | ||
|
||
P <- Hpolytope$new(A = Tr$Mat[1:nrow(Tr$Mat), 2:ncol(Tr$Mat)], b = Tr$Mat[,1]) | ||
|
||
x_min = matrix(0, dimension, 1) | ||
|
||
# Warm start point from truncated Gaussian | ||
warm_start <- sample_points(P, n = 1, random_walk = list("nburns" = 5000), distribution = list("density" = "gaussian", "variance" = 1/2, "mode" = x_min)) | ||
|
||
# Sample points | ||
n_samples <- 20000 | ||
|
||
samples <- sample_points(P, n = n_samples, random_walk = list("walk" = "NUTS", "solver" = "leapfrog", "starting_point" = warm_start[,1]), | ||
distribution = list("density" = "logconcave", "negative_logprob" = f, "negative_logprob_gradient" = grad_f)) | ||
|
||
# Plot histogram | ||
hist(samples[1,], probability=TRUE, breaks = 100) | ||
|
||
psrfs <- psrf_univariate(samples) | ||
n_ess <- ess(samples) | ||
|
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
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
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
Oops, something went wrong.