Skip to content

Commit

Permalink
d
Browse files Browse the repository at this point in the history
earge branch 'main' of https://github.com/google/bsynth into main

merge ok
  • Loading branch information
jvivesb committed Aug 19, 2021
2 parents 52bf27b + 1a1ac9e commit 52b7169
Show file tree
Hide file tree
Showing 43 changed files with 10,400 additions and 727 deletions.
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
^.*\.Rproj$
^\.Rproj\.user$
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
src/*.o
src/*.so
src/*.dll
*.cc
*.h
*.Rproj
17 changes: 12 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@ Depends:
R (>= 3.4.0)
Imports:
R6,
Rcpp,
RcppParallel,
Rcpp (>= 0.12.0),
RcppParallel (>= 5.0.1),
cubelyr,
dplyr,
ggplot2,
glue,
magrittr,
methods,
purrr,
rstan,
rstantools,
rstan (>= 2.18.1),
rstantools (>= 2.1.1),
scales,
tibble,
tidyr,
vizdraws
vizdraws (>= 1.1)
LinkingTo:
BH (>= 1.66.0),
Rcpp (>= 0.12.0),
RcppEigen (>= 0.3.3.3.0),
RcppParallel (>= 5.0.1),
rstan (>= 2.18.1),
StanHeaders (>= 2.18.0)
Suggests:
knitr,
rmarkdown,
Expand Down
1 change: 1 addition & 0 deletions Docker/build_test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.tar.gz
45 changes: 45 additions & 0 deletions Docker/build_test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM rocker/r-base:latest
LABEL maintainer="Ignacio Martinez <[email protected]>"

RUN apt-get update -qq \
&& apt-get install -y \
libxml2-dev \
libssl-dev \
libcurl4-openssl-dev \
libv8-dev \
texlive-latex-extra \
libharfbuzz-dev \
libfribidi-dev \
libpng-dev \
libtiff5-dev \
libjpeg-dev \
libpq5 \
pandoc \
&& install.r \
magrittr \
R6 \
Rcpp \
cubelyr \
dplyr \
ggplot2 \
glue \
magrittr \
methods \
purrr \
rstan \
rstantools \
scales \
tibble \
tidyr \
vizdraws \
devtools \
BH \
RcppEigen \
methods \
rmarkdown \
vizdraws \
knitr \
rmarkdown \
roxygen2 \
gsynth

12 changes: 12 additions & 0 deletions Docker/build_test/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

docker build --tag bsynth .

docker run --rm \
-v $(pwd):/tmp/working_dir \
-v $(pwd)/../..:/tmp/bsynth \
-w /tmp/working_dir \
bsynth \
R -e "devtools::test(pkg = '/tmp/bsynth'); devtools::build(pkg = '/tmp/bsynth', path = '/tmp/working_dir, binary = TRUE')"


1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ import(Rcpp)
import(methods)
importFrom(magrittr,"%>%")
importFrom(rstan,sampling)
useDynLib(bsynth, .registration = TRUE)
4 changes: 2 additions & 2 deletions R/bfactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ bayesianFactor <- R6::R6Class(
# dplyr::select(-{{id}}) %>%
# any(is.na()))

private$stan_model <- bsynth.models::factor_model_with_covariates
private$stan_model <- stanmodels$factor_model_with_covariates
} else {
private$stan_model <- bsynth.models::factor_model_without_covariates
private$stan_model <- stanmodels$factor_model_without_covariates
}

private$data <- data %>%
Expand Down
18 changes: 9 additions & 9 deletions R/factory.R
Original file line number Diff line number Diff line change
Expand Up @@ -248,35 +248,35 @@ bayesianSynth <- R6::R6Class(
if (length(private$treated_ids) == 1) {
if (is.null(covariates)) {
if (gp) {
private$stan_model <- bsynth.models::model2 # stanmodels$model2
private$stan_model <- stanmodels$model2
} else {
if (predictor_match) {
private$stan_model <- bsynth.models::model1_gammaOmega # gamma BCS
private$stan_model <- stanmodels$model1_gammaOmega
} else {
private$stan_model <- bsynth.models::model1 # stanmodels$model1
private$stan_model <- stanmodels$model1
}
}
} else {
if (gp) {
private$stan_model <- bsynth.models::model4 # stanmodels$model4
private$stan_model <- stanmodels$model4
} else {
private$stan_model <- bsynth.models::model3 # stanmodels$model3
private$stan_model <- stanmodels$model3
}
private$covariates <- covariates %>%
dplyr::arrange(!!private$time)
}
} else {
if (is.null(covariates)) {
if (gp) {
private$stan_model <- bsynth.models::model8 # stanmodels$model8
private$stan_model <- stanmodels$model8
} else {
private$stan_model <- bsynth.models::model5 # stanmodels$model5
private$stan_model <- stanmodels$model5
}
} else {
if (gp) {
private$stan_model <- bsynth.models::model7 # stanmodels$model7
private$stan_model <- stanmodels$model7
} else {
private$stan_model <- bsynth.models::model6 # stanmodels$model6
private$stan_model <- stanmodels$model6
}
private$covariates <- covariates %>%
dplyr::arrange(!!private$time)
Expand Down
36 changes: 36 additions & 0 deletions R/stanmodels.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by rstantools. Do not edit by hand.

# names of stan models
stanmodels <- c("factor_functions", "factor_model_with_covariates", "factor_model_without_covariates", "model1_gammaOmega", "model1", "model2", "model3", "model4", "model5", "model6", "model7", "model8")

# load each stan module
Rcpp::loadModule("stan_fit4factor_functions_mod", what = TRUE)
Rcpp::loadModule("stan_fit4factor_model_with_covariates_mod", what = TRUE)
Rcpp::loadModule("stan_fit4factor_model_without_covariates_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model1_gammaOmega_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model1_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model2_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model3_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model4_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model5_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model6_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model7_mod", what = TRUE)
Rcpp::loadModule("stan_fit4model8_mod", what = TRUE)

# instantiate each stanmodel object
stanmodels <- sapply(stanmodels, function(model_name) {
# create C++ code for stan model
stan_file <- if(dir.exists("stan")) "stan" else file.path("inst", "stan")
stan_file <- file.path(stan_file, paste0(model_name, ".stan"))
stanfit <- rstan::stanc_builder(stan_file,
allow_undefined = TRUE,
obfuscate_model_name = FALSE)
stanfit$model_cpp <- list(model_cppname = stanfit$model_name,
model_cppcode = stanfit$cppcode)
# create stanmodel object
methods::new(Class = "stanmodel",
model_name = stanfit$model_name,
model_code = stanfit$model_code,
model_cpp = stanfit$model_cpp,
mk_cppmodule = function(x) get(paste0("model_", model_name)))
})
1 change: 1 addition & 0 deletions inst/include/stan_meta_header.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// Insert all #include<foo.hpp> statements here
9 changes: 9 additions & 0 deletions src/Makevars
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated by rstantools. Do not edit by hand.

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DBOOST_MATH_OVERFLOW_ERROR_POLICY=errno_on_error
PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()")
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")

CXX_STD = CXX14
9 changes: 9 additions & 0 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Generated by rstantools. Do not edit by hand.

STANHEADERS_SRC = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "message()" -e "cat(system.file('include', 'src', package = 'StanHeaders', mustWork = TRUE))" -e "message()" | grep "StanHeaders")

PKG_CPPFLAGS = -I"../inst/include" -I"$(STANHEADERS_SRC)" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -DRCPP_PARALLEL_USE_TBB=1
PKG_CXXFLAGS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::CxxFlags()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::CxxFlags()")
PKG_LIBS = $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "RcppParallel::RcppParallelLibs()") $(shell "$(R_HOME)/bin$(R_ARCH_BIN)/Rscript" -e "StanHeaders:::LdFlags()")

CXX_STD = CXX14
47 changes: 47 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Generated by using Rcpp::compileAttributes() -> do not edit by hand
// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#include <RcppEigen.h>
#include <Rcpp.h>

using namespace Rcpp;

#ifdef RCPP_USE_GLOBAL_ROSTREAM
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif


RcppExport SEXP _rcpp_module_boot_stan_fit4factor_functions_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4factor_model_with_covariates_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4factor_model_without_covariates_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model1_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model1_gammaOmega_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model2_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model3_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model4_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model5_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model6_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model7_mod();
RcppExport SEXP _rcpp_module_boot_stan_fit4model8_mod();

static const R_CallMethodDef CallEntries[] = {
{"_rcpp_module_boot_stan_fit4factor_functions_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4factor_functions_mod, 0},
{"_rcpp_module_boot_stan_fit4factor_model_with_covariates_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4factor_model_with_covariates_mod, 0},
{"_rcpp_module_boot_stan_fit4factor_model_without_covariates_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4factor_model_without_covariates_mod, 0},
{"_rcpp_module_boot_stan_fit4model1_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model1_mod, 0},
{"_rcpp_module_boot_stan_fit4model1_gammaOmega_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model1_gammaOmega_mod, 0},
{"_rcpp_module_boot_stan_fit4model2_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model2_mod, 0},
{"_rcpp_module_boot_stan_fit4model3_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model3_mod, 0},
{"_rcpp_module_boot_stan_fit4model4_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model4_mod, 0},
{"_rcpp_module_boot_stan_fit4model5_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model5_mod, 0},
{"_rcpp_module_boot_stan_fit4model6_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model6_mod, 0},
{"_rcpp_module_boot_stan_fit4model7_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model7_mod, 0},
{"_rcpp_module_boot_stan_fit4model8_mod", (DL_FUNC) &_rcpp_module_boot_stan_fit4model8_mod, 0},
{NULL, NULL, 0}
};

RcppExport void R_init_bsynth(DllInfo *dll) {
R_registerRoutines(dll, NULL, CallEntries, NULL, NULL);
R_useDynamicSymbols(dll, FALSE);
}
32 changes: 32 additions & 0 deletions src/stanExports_factor_functions.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Generated by rstantools. Do not edit by hand.

#include <Rcpp.h>
using namespace Rcpp ;
#include "stanExports_factor_functions.h"

RCPP_MODULE(stan_fit4factor_functions_mod) {


class_<rstan::stan_fit<stan_model, boost::random::ecuyer1988> >("model_factor_functions")

.constructor<SEXP,SEXP,SEXP>()


.method("call_sampler", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::call_sampler)
.method("param_names", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_names)
.method("param_names_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_names_oi)
.method("param_fnames_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_fnames_oi)
.method("param_dims", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_dims)
.method("param_dims_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_dims_oi)
.method("update_param_oi", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::update_param_oi)
.method("param_oi_tidx", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::param_oi_tidx)
.method("grad_log_prob", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::grad_log_prob)
.method("log_prob", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::log_prob)
.method("unconstrain_pars", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::unconstrain_pars)
.method("constrain_pars", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::constrain_pars)
.method("num_pars_unconstrained", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::num_pars_unconstrained)
.method("unconstrained_param_names", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::unconstrained_param_names)
.method("constrained_param_names", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::constrained_param_names)
.method("standalone_gqs", &rstan::stan_fit<stan_model, boost::random::ecuyer1988> ::standalone_gqs)
;
}
Loading

0 comments on commit 52b7169

Please sign in to comment.