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

Use of SIMD computation in CRHMC walk [fixed] #286

Merged
merged 186 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 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
47f0bd7
Merge branch 'develop' into integrate_crmhc_simd
Oct 16, 2023
4fe8a20
delete commented out code
Oct 17, 2023
e9792a3
resolve conflicts from develop
Oct 17, 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
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")
}
98 changes: 98 additions & 0 deletions R-proj/examples/logconcave/sparse_crhmc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# 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(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)

# Interval [-1, 1]
A = matrix(c(1, -1), ncol=1, nrow=2, byrow=TRUE)
b = c(2,1)

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

# Mode of logconcave density
x_min <- c(-0.5)

# Smoothness and strong-convexity
L <- 2
m <- 2

# Sample points
n_samples <- 80000
n_burns <- n_samples / 2
cat("---Sampling without hessian\n")
pts <- sample_points(P, n = n_samples, random_walk = list("walk" = "CRHMC", "step_size" = 0.3, "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))
jpeg("histogram_without_hessian.jpg")
# Plot histogram
hist(pts, probability=TRUE, breaks = 100)

cat("Sample mean is: ")
sample_mean <- mean(pts)
cat(sample_mean)
cat("\n")
cat("Sample variance is: ")
sample_variance <- mean((pts - sample_mean)^2)
cat(sample_variance)
cat("\n")
invisible(capture.output(dev.off()))

# Negative log-probability hessian oracle
hess_f <- function(x) (2)
cat("---Sampling with hessian\n")
pts <- sample_points(P, n = n_samples, random_walk = list("walk" = "CRHMC", "step_size" = 0.3, "nburns" = n_burns, "walk_length" = 1, "solver" = "implicit_midpoint"), distribution = list("density" = "logconcave", "negative_logprob" = f, "negative_logprob_gradient" = grad_f,"negative_logprob_hessian" = hess_f, "L_" = L, "m" = m))
jpeg("histogram_with_hessian.jpg")
# Plot histogram
hist(pts, probability=TRUE, breaks = 100)

cat("Sample mean is: ")
sample_mean <- mean(pts)
cat(sample_mean)
cat("\n")
cat("Sample variance is: ")
sample_variance <- mean((pts - sample_mean)^2)
cat(sample_variance)
cat("\n")
invisible(capture.output(dev.off()))

walk="CRHMC"
library(Matrix)
bineq=matrix(c(10,10,10,10,10), nrow=5, ncol=1, byrow=TRUE)
Aineq = matrix(c(1,0,-0.25,-1,2.5,1,0.4,-1,-0.9,0.5), nrow=5, ncol=2, byrow = TRUE)
Aineq = as( Aineq, 'dgCMatrix' )
beq=matrix(,nrow=0, ncol=1, byrow=TRUE)
Aeq = matrix(, nrow=0, ncol=2, byrow = TRUE)
Aeq=as( Aeq, 'dgCMatrix' )
lb=-100000*c(1,1);
ub=100000*c(1,1);
cat("---Sampling the normal distribution in a pentagon\n")
P <- volesti::sparse_constraint_problem$new(Aineq, bineq,Aeq, beq, lb, ub)
points <- sample_points(P, n = n_samples, random_walk = list("walk" = "CRHMC", "step_size" = 0.3, "nburns" = n_burns, "walk_length" = 1, "solver" = "implicit_midpoint"), distribution = list("density" = "logconcave", "variance" = 8))
jpeg("pentagon.jpg")
plot(ggplot(data.frame( x=points[1,], y=points[2,] )) +
geom_point( aes(x=x, y=y, color=walk)) + coord_fixed(xlim = c(-15,15),
ylim = c(-15,15)) + ggtitle(sprintf("Sampling a random pentagon with walk %s", walk)))
invisible(capture.output(dev.off()))
write.table(points, file="pentagon.txt", row.names=FALSE, col.names=FALSE)
34 changes: 34 additions & 0 deletions R-proj/man/Rcpp_sparse_constraint_problem.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
\docType{class}
\name{Rcpp_sparse_constraint_problem}
\alias{Rcpp_sparse_constraint_problem-class}
\alias{[,Rcpp_sparse_constraint_problem-method}
\alias{[,Rcpp_sparse_constraint_problem,ANY,ANY,ANY-method}
\alias{$<-,Rcpp_sparse_constraint_problem-method}
\alias{$,Rcpp_sparse_constraint_problem-method}
\alias{filepaths<-,Rcpp_sparse_constraint_problem-method}
\title{
An \code{Rcpp} class to represent sparse_constraint_problems, exposed to \code{R} via modules.
}
\description{
A constraint problem is defined by a set of linear inequalities and equalities or equivalently a \eqn{d}-dimensional constraint problem is defined by a \eqn{mineq\times d} matrix Aineq and a \eqn{mineq}-dimensional vector bineq, s.t.: \eqn{Aineqx\leq bineq}, a \eqn{meq\times d} matrix Aeq and a \eqn{meq}-dimensional vector beq, s.t.: \eqn{Aeqx= beq} and two \eqn{d} vectors lb, ub such that \eqn{lb\leq x \leq ub}.}
\details{
\describe{
\item{\code{Aineq} }{\eqn{mineq\times d} sparse matrix Aineq}

\item{\code{bineq} }{\eqn{mineq}-dimensional vector bineq}

\item{\code{Aeq} }{\eqn{meq\times d} sparse matrix Aeq}

\item{\code{beq} }{\eqn{meq}-dimensional vector beq}

\item{\code{lb} }{\eqn{d}-dimensional vector bineq}

\item{\code{ub} }{\eqn{d}-dimensional vector bineq}

\item{\code{type} }{An integer that declares the representation of the polytope. For sparse_constraint_problem the default value is 5.}

\item{\code{dimension} }{The dimension of the polytope.}

}
}
\keyword{internal}
4 changes: 2 additions & 2 deletions R-proj/man/sample_points.Rd

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

26 changes: 26 additions & 0 deletions R-proj/man/sparse_constraint_problem.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
\name{sparse_constraint_problem}
\alias{sparse_constraint_problem}
\title{An \code{R} class to represent sparse constraint problems.}

\description{
A constraint problem is defined by a set of linear inequalities and equalities or equivalently a \eqn{d}-dimensional constraint problem is defined by a \eqn{mineq\times d} matrix Aineq and a \eqn{mineq}-dimensional vector bineq, s.t.: \eqn{Aineqx\leq bineq}, a \eqn{meq\times d} matrix Aeq and a \eqn{meq}-dimensional vector beq, s.t.: \eqn{Aeqx\eq beq} and two \eqn{d} vectors lb, ub such that \eqn{lb\leq x \leq ub}.
}
\section{Fields}{
\itemize{
\item{\code{Aineq} }{\eqn{mineq\times d} sparse matrix Aineq}

\item{\code{bineq} }{\eqn{mineq}-dimensional vector bineq}

\item{\code{Aeq} }{\eqn{meq\times d} sparse matrix Aeq}

\item{\code{beq} }{\eqn{meq}-dimensional vector beq}

\item{\code{lb} }{\eqn{d}-dimensional vector bineq}

\item{\code{ub} }{\eqn{d}-dimensional vector bineq}

\item{\code{type} }{An integer that declares the representation of the polytope. For sparse_constraint_problem the default value is 5.}

\item{\code{dimension} }{The dimension of the polytope.}

}}
9 changes: 7 additions & 2 deletions R-proj/src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ PKG_CXXFLAGS= -Wno-deprecated-declarations -lm -ldl -Wno-ignored-attributes -DBO

CXX_STD = CXX11

PKG_LIBS=-LRproj_externals/lp_solve -llp_solve $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_LIBS=-LRproj_externals/lp_solve -llp_solve -L../../external/PackedCSparse/qd -lqd $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

$(SHLIB): Rproj_externals/lp_solve/liblp_solve.a
$(SHLIB): Rproj_externals/lp_solve/liblp_solve.a ../../external/PackedCSparse/qd/libqd.a

Rproj_externals/lp_solve/liblp_solve.a:
@(cd Rproj_externals/lp_solve && $(MAKE) liblp_solve.a \
CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \
CPICFLAGS="$(CPICFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)")

../../external/PackedCSparse/qd/libqd.a:
@(cd ../../PackedCSparse/qd && $(MAKE) libqd.a \
CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \
CPICFLAGS="$(CPICFLAGS)" AR="$(AR)")
9 changes: 7 additions & 2 deletions R-proj/src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ PKG_CPPFLAGS=-I../../external/boost -I../../external/LPsolve_src/run_headers -I.
PKG_CXXFLAGS= -Wno-deprecated-declarations -lm -ldl -Wno-ignored-attributes -DBOOST_NO_AUTO_PTR -DDISABLE_NLP_ORACLES
CXX_STD = CXX11

PKG_LIBS=-LRproj_externals/lp_solve -llp_solve $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_LIBS=-LRproj_externals/lp_solve -llp_solve -L../../external/PackedCSparse/qd -lqd $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)

$(SHLIB): Rproj_externals/lp_solve/liblp_solve.a
$(SHLIB): Rproj_externals/lp_solve/liblp_solve.a ../../external/PackedCSparse/qd/libqd.a

Rproj_externals/lp_solve/liblp_solve.a:
@(cd Rproj_externals/lp_solve && $(MAKE) liblp_solve.a \
CC="$(CC)" CPPFLAGS="$(CPPFLAGS) -DUSRDLL -DINLINE=static" \
CFLAGS="$(CFLAGS)" CPICFLAGS="$(CPICFLAGS)" AR="$(AR)" \
RANLIB="$(RANLIB)")

../../external/PackedCSparse/qd/libqd.a:
@(cd ../../PackedCSparse/qd && $(MAKE) libqd.a \
CC="$(CC)" CPPFLAGS="$(CPPFLAGS)" CFLAGS="$(CFLAGS)" \
CPICFLAGS="$(CPICFLAGS)" AR="$(AR)")
39 changes: 38 additions & 1 deletion R-proj/src/oracle_functors_rcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ enum ode_solvers {
euler,
runge_kutta,
richardson,
collocation
collocation,
implicit_midpoint
};

// Holds Oracle Functor that wraps an R function via RCpp
Expand Down Expand Up @@ -91,6 +92,17 @@ struct RcppFunctor {
}
}

Point operator() (Point const& x) const {
VT y = Rcpp::as<VT>(neg_grad_f(Rcpp::wrap(x.getCoefficients())));

Point z(y);

if (negate) z = (-1.0) * z;

// Return result as Point
return z;
}

};

// Negative log-probability functor
Expand Down Expand Up @@ -118,6 +130,31 @@ struct RcppFunctor {

};

// Log-probability hessian functor
template
<
typename Point
>
struct HessianFunctor {
typedef typename Point::FT NT;
typedef typename Point::Coeff VT;

parameters<NT> params;
Rcpp::Function hessian; // Negative hessian as an Rcpp::Function

HessianFunctor(
parameters<NT> params_,
Rcpp::Function hessian_) :
params(params_),
hessian(hessian_)
{};

Point operator() (Point const& x) const {
VT y= Rcpp::as<VT>(hessian(Rcpp::wrap(x.getCoefficients())));
return Point(y);
}

};
};

#endif
Loading
Loading