Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support intersection between an Hpolytope and an ellipsoid #287

Open
wants to merge 205 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
205 commits
Select commit Hold shift + click to select a range
f9b6879
Added some images
iakoviid Mar 28, 2022
6e32382
bringing simd files
iakoviid Sep 2, 2022
3900223
debugging
iakoviid Sep 2, 2022
82a52c8
debugging
iakoviid Sep 2, 2022
574fe71
debugging
iakoviid Sep 2, 2022
6d9af17
minor change
iakoviid Sep 2, 2022
436a7ce
minor change
iakoviid Sep 2, 2022
0e7e94e
minor change
iakoviid Sep 2, 2022
bcdd03e
debugging
iakoviid Sep 2, 2022
af35785
debugging
iakoviid Sep 2, 2022
bb7086c
debugging
iakoviid Sep 2, 2022
f76519c
debugging
iakoviid Sep 2, 2022
0a898fd
minor changes
iakoviid Sep 3, 2022
5ced85a
debugging
iakoviid Sep 3, 2022
114b78c
debugging
iakoviid Sep 3, 2022
b27467c
debugging
iakoviid Sep 3, 2022
b1ae3fd
Matrix manipulation changes
iakoviid Sep 3, 2022
88c9756
debugging
iakoviid Sep 3, 2022
447c9d2
debugging
iakoviid Sep 3, 2022
04770da
debugging
iakoviid Sep 3, 2022
4d40c5c
making the additional units
iakoviid Sep 3, 2022
e69f177
Making dynamic weights module
iakoviid Sep 3, 2022
1600d15
dynamic weight vectorization
iakoviid Sep 3, 2022
e9c44fa
dynamic step size vectorization
iakoviid Sep 4, 2022
699debd
clean up
iakoviid Sep 4, 2022
7e11f96
debugging
iakoviid Sep 4, 2022
124e734
minor changes
iakoviid Sep 4, 2022
fbfac88
bring on changes on preparation module
iakoviid Sep 6, 2022
928107d
changed walk contructor
iakoviid Sep 6, 2022
4bafc16
minor changes
iakoviid Sep 6, 2022
2240c61
minor changes
iakoviid Sep 6, 2022
cb8c0cc
bring in oracle functors
iakoviid Sep 6, 2022
455846a
minor changes
iakoviid Sep 6, 2022
adc5971
minor change
iakoviid Sep 6, 2022
efbde5a
integrating simdlen in tests
iakoviid Sep 7, 2022
c6188da
changes in unit test
iakoviid Sep 7, 2022
f4f0782
fixed minor issue
iakoviid Sep 7, 2022
e6768e8
typo
iakoviid Sep 7, 2022
84a0594
minor changes
iakoviid Sep 8, 2022
57b4bca
typo
iakoviid Sep 8, 2022
7c8eba1
simd benchmark testing
iakoviid Sep 8, 2022
cca6e4f
Minor change
iakoviid Sep 9, 2022
d5e4a16
enabling additional modules
iakoviid Sep 9, 2022
b314bbc
counting only non burnin time
iakoviid Sep 9, 2022
f2bd94c
updating benchmark
iakoviid Sep 9, 2022
3147851
changed benchmark
iakoviid Sep 9, 2022
69f4b76
changes in benchmark
iakoviid Sep 9, 2022
36b15c0
changes in benchmark file
iakoviid Sep 9, 2022
c633a45
changes in benchmark file
iakoviid Sep 9, 2022
4868343
putting additional datasets in the benchmark target times TO DO
iakoviid Sep 9, 2022
9852770
merging with the current develop
iakoviid Sep 10, 2022
79e1ed1
minor change
iakoviid Sep 10, 2022
8504f14
set benchmarking for trials
iakoviid Sep 10, 2022
9c00afd
changes in benchmark
iakoviid Sep 10, 2022
7a26c56
typo
iakoviid Sep 10, 2022
5f276d9
changes in benchmark
iakoviid Sep 10, 2022
872d9ad
small changes
iakoviid Sep 10, 2022
4b56af7
typo
iakoviid Sep 10, 2022
a9ae488
small changes
iakoviid Sep 10, 2022
90380e7
typo
iakoviid Sep 10, 2022
ea4f351
vectorized masked choice
iakoviid Sep 10, 2022
ff0a060
minor changes
iakoviid Sep 10, 2022
bced157
Added a second file to test simdlen 4 it will be removed sortly
iakoviid Sep 11, 2022
3aaa9ed
removed extra files
iakoviid Sep 11, 2022
c7dc275
change in external folder
iakoviid Sep 11, 2022
8aef6cd
changes in external folder
iakoviid Sep 11, 2022
6babfe9
example changes
iakoviid Sep 12, 2022
4fca33b
typo
iakoviid Sep 12, 2022
3e1fd1f
crhmc_sampling example changes
iakoviid Sep 12, 2022
1aa3f0d
changes in examples
iakoviid Sep 12, 2022
fee2fed
minor changes
iakoviid Sep 12, 2022
e04fd4e
minor changes
iakoviid Sep 12, 2022
6a48674
minor changes
iakoviid Sep 12, 2022
054a1aa
minor changes
iakoviid Sep 12, 2022
067bb15
file formating
iakoviid Sep 14, 2022
41d32ae
file formating
iakoviid Sep 14, 2022
70580d1
made sparse input entry function with extra example
iakoviid Sep 23, 2022
817b1a4
example change
iakoviid Sep 24, 2022
14ba89d
gitignore
iakoviid Sep 24, 2022
36f2d4c
changed fill reducing permutations
iakoviid Sep 25, 2022
808ec00
remove binary
iakoviid Sep 25, 2022
9dbffa9
minor change
iakoviid Sep 25, 2022
c124ad0
minor change
iakoviid Sep 26, 2022
d6fd6eb
get rid of norm check
iakoviid Sep 26, 2022
53d73ab
changes in example
iakoviid Sep 26, 2022
f6615b7
typo
iakoviid Sep 26, 2022
a3be965
typo
iakoviid Sep 26, 2022
28299ff
changes in example
iakoviid Sep 26, 2022
cc3f7d1
Made crhmc_sampling function and coresponding example.
iakoviid Sep 27, 2022
eb40442
made constraint problem struct
iakoviid Sep 28, 2022
e2b9d9d
changed sampling functions
iakoviid Sep 28, 2022
ac24e3b
changes in example
iakoviid Sep 28, 2022
cf53a7b
converted pointers to unique_ptr
iakoviid Sep 28, 2022
34b7f1f
added include
iakoviid Sep 28, 2022
d1934ba
changed examples
iakoviid Sep 28, 2022
87f51e8
changes in constraint problem
iakoviid Sep 28, 2022
879e76b
changed example
iakoviid Sep 28, 2022
5c69441
minor changes
iakoviid Sep 28, 2022
090756e
adding hessian to Rcpp functors
iakoviid Oct 7, 2022
3762638
removing eigen_indexing from analytic center
iakoviid Oct 7, 2022
ac342c1
removing eigen indexing from lewis center
iakoviid Oct 7, 2022
6da786d
removing eigen indexing from walk
iakoviid Oct 7, 2022
9110320
removing eigen indexing from simple barrier
iakoviid Oct 7, 2022
a6c4d1a
removing eigen indexing from weighted barrier
iakoviid Oct 7, 2022
1f8a5da
adding functions to handle indexing in utils
iakoviid Oct 7, 2022
f924b15
overloading convert2crhmc_input function
iakoviid Oct 7, 2022
5b8fd49
added a new sampling hunction
iakoviid Oct 7, 2022
b1de25e
removing indexing from crhmc_problem
iakoviid Oct 7, 2022
7357e66
minor changes
iakoviid Oct 7, 2022
0a9f929
minor changes
iakoviid Oct 7, 2022
3272404
simple R example
iakoviid Oct 7, 2022
d6856dc
added qd library dependency in makefile
iakoviid Oct 7, 2022
0497d86
adding hessian to rcpp functors
iakoviid Oct 7, 2022
663b226
adding CRHMC walk to the sample points documentation
iakoviid Oct 7, 2022
207bb9a
constraint object documentation
iakoviid Oct 7, 2022
2e0c5c0
added qd dependance of the windows makefile
iakoviid Oct 7, 2022
1109ea1
added sparse constraint problem in polytope modules
iakoviid Oct 7, 2022
f018732
added crhmc capability in sample points
iakoviid Oct 7, 2022
8723189
added qd makefile
iakoviid Oct 7, 2022
d162f9e
added qd dependency to the cran makefile
iakoviid Oct 7, 2022
e669243
added qd dependency to the cran makefile windows
iakoviid Oct 7, 2022
046c147
automaticaly downloading qd in genCRANpkg
iakoviid Oct 7, 2022
38b8031
minor changes
iakoviid Oct 7, 2022
3fa02f1
cleanup
iakoviid Oct 7, 2022
f257d9a
cleanup
iakoviid Oct 7, 2022
bfd82d9
removed std::cerr
iakoviid Oct 7, 2022
db16607
minor change
iakoviid Oct 7, 2022
915a075
minor change
iakoviid Oct 7, 2022
efac612
minor change
iakoviid Oct 7, 2022
f28ed4a
updated documentation
iakoviid Oct 7, 2022
ac78f2c
updated documentation
iakoviid Oct 7, 2022
82b7f01
documentation
iakoviid Oct 8, 2022
0036dd7
updated documentation
iakoviid Oct 8, 2022
6e1197b
added unit test in R
iakoviid Oct 8, 2022
b78d207
typo
iakoviid Oct 8, 2022
0a91ee1
review changes
iakoviid Oct 27, 2022
bfa1df8
review changes
iakoviid Oct 27, 2022
fe0cf38
adding new test
iakoviid Oct 28, 2022
b243726
new test
iakoviid Oct 28, 2022
80d0f02
adding new test
iakoviid Oct 28, 2022
d388485
typo
iakoviid Oct 28, 2022
d82f7d6
new test
iakoviid Oct 28, 2022
060653b
typo
iakoviid Oct 28, 2022
ee0dd07
typo
iakoviid Oct 28, 2022
d9b538f
typo
iakoviid Oct 28, 2022
a38dcc7
adding test to cmake
iakoviid Oct 28, 2022
a2f371c
new test
iakoviid Oct 28, 2022
6bb5b6d
new test
iakoviid Oct 28, 2022
1ed807a
new test
iakoviid Oct 28, 2022
6de04a8
new test
iakoviid Oct 29, 2022
9acb723
test unbounded polytopes
iakoviid Oct 29, 2022
83c6f37
test unbounded polytope
iakoviid Oct 29, 2022
c377aba
test undbounded
iakoviid Oct 29, 2022
42a1e01
test invalid polytopes
iakoviid Oct 29, 2022
595e273
increase coverage
iakoviid Oct 29, 2022
6808df1
test unbounded
iakoviid Oct 29, 2022
82c775e
coding style changes
iakoviid Nov 1, 2022
7690670
changes in test
iakoviid Nov 1, 2022
f8135f3
typo
iakoviid Nov 1, 2022
b4093d0
Merge remote-tracking branch 'upstream/develop' into crhmc_simd
iakoviid Nov 2, 2022
bb2ae85
simpler examples
iakoviid Jan 19, 2023
08beb46
simple example
iakoviid Jan 19, 2023
cae8307
simple examples
iakoviid Jan 19, 2023
7768e1a
cleanup examples
iakoviid Jan 19, 2023
9f0cd2c
Merge branch 'develop' into crhmc_simd
iakoviid Feb 3, 2023
4e8429d
changes in example
iakoviid Feb 3, 2023
c6b6192
images
iakoviid Feb 4, 2023
bc20763
images
iakoviid Feb 4, 2023
157a42d
cleanup
iakoviid Feb 4, 2023
789c4bb
cleanup
iakoviid Feb 4, 2023
d40c53a
cleanup
iakoviid Feb 5, 2023
8f24055
qd for windows
iakoviid Feb 5, 2023
b0fa29f
qd
iakoviid Feb 5, 2023
7c17292
qd makefile
iakoviid Feb 5, 2023
2d36416
r tests
iakoviid Feb 5, 2023
7df1fb4
qd
iakoviid Feb 5, 2023
0aecdfe
r example
iakoviid Feb 5, 2023
33dce2f
cleanup
iakoviid Feb 6, 2023
0070004
reorder
iakoviid Feb 6, 2023
7b9b29c
windows test
iakoviid Feb 9, 2023
03a08c5
checking tests
iakoviid Feb 9, 2023
3f815ad
Merge branch 'develop' into integrate_crmhc_simd
Oct 16, 2023
5138c90
disable an R sampling test for windows
Oct 16, 2023
157955c
Fix the warning message in R Mac's cran test (#285)
TolisChal Oct 16, 2023
47f0bd7
Merge branch 'develop' into integrate_crmhc_simd
Oct 16, 2023
4fe8a20
delete commented out code
Oct 17, 2023
074a562
No-U-Turn Sampler in HMC (#216)
TolisChal Oct 17, 2023
e9792a3
resolve conflicts from develop
Oct 17, 2023
bcd4364
implement sampling from the intersection between an ellipsoid and a p…
Oct 26, 2023
2d4a72f
expose in R sampling from the intersection EllPoly
Oct 31, 2023
a5e5b3e
fix error in defining the new class
Oct 31, 2023
9528896
fix compile errors when building cran pkg
Oct 31, 2023
215149d
fix compile error in sample_points
Oct 31, 2023
255b083
add documentation for the intersection between an Hpolytope and an el…
Oct 31, 2023
a732ec9
fix brackets in new documentation
Oct 31, 2023
c31e98b
Use of SIMD computation in CRHMC walk [fixed] (#286)
iakoviid Nov 2, 2023
7fcc704
implement Dirichlet oracles
Nov 2, 2023
3f22a00
resolve conflicts
Nov 2, 2023
6987bf7
expose dirichlet sampling in R
Nov 2, 2023
de43217
fix compile errors in dirichlet oracles and implement an example
Nov 4, 2023
0098e45
fix compile error in sample_points.cpp
Nov 4, 2023
41f99c0
fix compile errors and provide a dirichlet sampling example in r
Nov 10, 2023
bebef71
adding dirichlet r examples
Nov 11, 2023
7cc37b7
change position of the new polytope module
Nov 12, 2023
9a7d876
fixing cran warnings on new rcpp module
Nov 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check-ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
config:
- {os: ubuntu-latest, r: 'devel'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-18.04, r: 'devel'}
- {os: ubuntu-18.04, r: 'release'}
- {os: ubuntu-20.04, r: 'devel'}
- {os: ubuntu-20.04, r: 'release'}

env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
Expand Down
5 changes: 0 additions & 5 deletions R-proj/R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,6 @@ sample_points <- function(P, n, random_walk = NULL, distribution = NULL, seed =
.Call(`_volesti_sample_points`, P, n, random_walk, distribution, seed)
}

#' @export
sample_spectra <- function(file = NULL, N = NULL, walk_length = NULL) {
.Call(`_volesti_sample_spectra`, file, N, walk_length)
}

#' Write a SDPA format file
#'
#' Outputs a spectrahedron (the matrices defining a linear matrix inequality) and a vector (the objective function)
Expand Down
42 changes: 42 additions & 0 deletions R-proj/examples/Dirichlet/dirichlet_crhmc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# VolEsti (volume computation and sampling library)

# Copyright (c) 2012-2023 Vissarion Fisikopoulos
# Copyright (c) 2018-2023 Apostolos Chalkis
# Copyright (c) 2020-2023 Elias Tsigaridas

# Licensed under GNU LGPL.3, see LICENCE file

# Example script for sampling from the Dirichlet distribution with CRHMC

# Import required libraries
library(volesti)
library(Matrix)

Aeq = matrix(c(1, 1, 1), ncol=3, nrow=1, byrow=TRUE)
Aeq = as( Aeq, 'dgCMatrix' )
beq = matrix(c(1), ncol=1, nrow=1, byrow=TRUE)
Aineq = matrix(, ncol=3, nrow=0, byrow=TRUE)
Aineq = as( Aineq, 'dgCMatrix' )
bineq = matrix(, ncol=0, nrow=0, byrow=TRUE)
lb = c(0,0,0)
ub = c(1, 1 ,1)

# Create domain of truncation
P <- volesti::sparse_constraint_problem$new(Aineq, bineq, Aeq, beq, lb, ub)

a_vec = c(2,3,4)
# Negative log-probability oracle
f <- function(x) (-((a_vec-1)%*%log(x))[1])

# Negative log-probability gradient oracle
grad_f <- function(x) (-(a_vec-1)/x)

n_samples <- 5000
n_burns <- n_samples / 2
pts <- sample_points(P, n = n_samples,
random_walk = list("walk" = "CRHMC",
"nburns" = n_burns, "walk_length" = 1,
"solver" = "implicit_midpoint"),
distribution = list("density" = "logconcave",
"negative_logprob" = f,
"negative_logprob_gradient" = grad_f))
88 changes: 88 additions & 0 deletions R-proj/examples/Dirichlet/dirichlet_ellipsoid_nuts.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# VolEsti (volume computation and sampling library)

# Copyright (c) 2012-2023 Vissarion Fisikopoulos
# Copyright (c) 2018-2023 Apostolos Chalkis
# Copyright (c) 2020-2023 Elias Tsigaridas

# Licensed under GNU LGPL.3, see LICENCE file

# Example script for sampling from the Dirichlet distribution with CRHMC

# Import required libraries
library(volesti)
library(Matrix)

n = 3
Aeq = matrix(rep(1,n), ncol=n, nrow=1, byrow=TRUE)
beq = c(1)
A = -diag(n)
b = rep(0, n)

# ellipsoid x'Ex <= 1
E = matrix(c(7.8791, 3.6018, -6.9191, 3.6018, 2.2995,
-4.4496, -6.9191, -4.4496, 11.7993),
nrow = 3, ncol = 3, byrow = TRUE)

x0 = c(0.2455, 0.4287, 0.3258) #interior point

# Projecting everything onto the null space of Aeq
N_trans = pracma::nullspace(Aeq)
N_shift = x0

b = b - A %*% N_shift
A = A %*% N_trans
p0 = rep(0, n-1) #interior point of the projected point

#the new matrix of the projected ellipsoid
Et = t(N_trans) %*% E %*% N_trans
#the new center of the projected ellipsoid
center = -MASS::ginv(Et) %*% (t(N_trans) %*% E) %*% N_shift
#the new offset of the projeced ellipsoid
R = 1 + t(center)%*%Et%*%center - t(N_shift)%*%E%*%N_shift
R = R[1]
#normalizing the offset
Et = Et / R

#we shift by the ellipsoid's center so that it is given by x'Etx <= 1
b = b - A %*% center # shift ellipsoid's center to origin
# interior point in the projected body
p0 = p0 - center

#now, from a point y, in the projected body, we get
#the point oin the initial body as follows: x = N_trans%*%(y+center) + x0

# Create domain of truncation
P <- volesti::PolytopeIntersectEllipsoid$new(A, b, Et)

a_vec = c(2,3,4)
# Transformed negative log-probability oracle
f <- function(y) (-((a_vec-1)%*%log(N_trans%*%(y+center) + x0))[1])

# Transformed negative log-probability gradient oracle
grad_f <- function(y) (-(a_vec-1)/(N_trans%*%(y+center) + x0))

n_samples <- 5000
n_burns <- n_samples / 2
samples <- volesti::sample_points(P, n = n_samples,
random_walk = list("walk" = "NUTS", "solver" = "leapfrog",
"starting_point" = p0),
distribution = list("density" = "logconcave", "negative_logprob" = f,
"negative_logprob_gradient" = grad_f))

M = dim(samples)[2]
# samples in the initial body following Dirichlet distribution
random_portfolios = N_trans %*% (samples + kronecker(matrix(1, 1, M), matrix(center, ncol = 1))) +
kronecker(matrix(1, 1, M), matrix(N_shift, ncol = 1))

######################
## UNIFORM SAMPLING ##
######################
# it's better to use Billiard walk instead of a dirichlet with ones

samples <- volesti::sample_points(P, n = n_samples,
random_walk = list("walk" = "aBiW", "starting_point" = p0))

M = dim(samples)[2]
# samples in the initial body following uniform distribution
random_portfolios = N_trans %*% (samples + kronecker(matrix(1, 1, M), matrix(center, ncol = 1))) +
kronecker(matrix(1, 1, M), matrix(N_shift, ncol = 1))
47 changes: 47 additions & 0 deletions R-proj/examples/logconcave/nuts_poly_intersect_ellipsoid.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# VolEsti (volume computation and sampling library)

# Copyright (c) 2012-2020 Vissarion Fisikopoulos
# Copyright (c) 2018-2020 Apostolos Chalkis
# Copyright (c) 2020-223 Elias Tsigaridas

# 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)

# Create domain of truncation
A = matrix(c(1,0,0,1,-1,0,0,-1), nrow=4, ncol=2, byrow=TRUE)
b = rep(1,4)
E = matrix(c(0.25, 0.75, 0.75, 3.25), nrow=2, ncol=2, byrow=TRUE)
EP = PolytopeIntersectEllipsoid$new(A, b, E)
dim = 2

x0 = rep(0, dim)

# Sample points
n_samples = 2000

samples = sample_points(EP, n = n_samples, random_walk = list("walk" = "NUTS", "solver" = "leapfrog", "starting_point" = x0),
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)


55 changes: 55 additions & 0 deletions R-proj/examples/logconcave/nuts_rand_poly.R
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)

49 changes: 49 additions & 0 deletions R-proj/examples/logconcave/simple_crhmc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# VolEsti (volume computation and sampling library)

# Copyright (c) 2012-2020 Vissarion Fisikopoulos
# Copyright (c) 2018-2020 Apostolos Chalkis
# Copyright (c) 2020-2020 Marios Papachristou
# Copyright (c) 2022-2022 Ioannis Iakovidis

# Contributed and/or modified by Ioannis Iakovidis, as part of Google Summer of Code 2022 program.

# Licensed under GNU LGPL.3, see LICENCE file

# Example script for using the logconcave sampling methods

# Import required libraries
library(volesti)

# Sampling from uniform density example

logconcave_sample<- function(P,distribution, n_samples ,n_burns){
if (distribution == "uniform"){
f <- function(x) (0)
grad_f <- function(x) (0)
L=1
m=1
pts <- sample_points(P, n = n_samples, random_walk = list("walk" = "CRHMC", "nburns" = n_burns, "walk_length" = 1, "solver" = "implicit_midpoint"), distribution = list("density" = "logconcave", "negative_logprob" = f, "negative_logprob_gradient" = grad_f, "L_" = L, "m" = m))
return(max(psrf_univariate(pts, "interval")))
}
else if(distribution == "gaussian"){
pts <- sample_points(P, n = n_samples, random_walk = list("walk" = "CRHMC", "nburns" = n_burns, "walk_length" = 1, "solver" = "implicit_midpoint"), distribution = list("density" = "logconcave", "variance"=8))
return(max(psrf_univariate(pts, "interval")))
}
}

for (i in 1:2) {

if (i==1) {
distribution = 'gaussian'
cat("Gaussian ")
} else {
distribution = 'uniform'
cat("Uniform ")
}

P = gen_simplex(10, 'H')
psrf = logconcave_sample(P,distribution,5000,2000)
cat("psrf = ")
cat(psrf)
cat("\n")
}
4 changes: 2 additions & 2 deletions R-proj/examples/logconcave/simple_hmc_rand_poly.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ dimension <- 50
facets <- 200

# Create domain of truncation
H <- gen_rand_hpoly(dimension, facets)
H <- gen_rand_hpoly(dimension, facets, seed = 15)

# Rounding
Tr <- rounding(H)
Tr <- rounding(H, seed = 127)

P <- Hpolytope$new(A = Tr$Mat[1:nrow(Tr$Mat), 2:ncol(Tr$Mat)], b = Tr$Mat[,1])

Expand Down
Loading
Loading