Skip to content

Commit

Permalink
Merge pull request #4 from kaybenleroll/create-simple-hier-models
Browse files Browse the repository at this point in the history
create simple hier models
  • Loading branch information
kaybenleroll authored Oct 24, 2023
2 parents f27a10f + 3d91071 commit bb5c603
Show file tree
Hide file tree
Showing 54 changed files with 80,689 additions and 6,379 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

*.qmd
*.html
*.log
*.R

data/*
precompute/*
.git/*

stan_code/*
stan_models/*
img/*

*_cache/*
*_files/*
17 changes: 10 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
.Rhistory
.RData

.Rproj.user/

temp.R
.vscode/

*_cache/*
*_files/*

output.log

*.rmarkdown
*.dot

.Rhistory
.RData

*.log

temp*.R

precompute_*.bz2

34 changes: 30 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
FROM rocker/tidyverse:4.2.3
FROM rocker/tidyverse:4.3.1

COPY build/Rprofile.site /usr/local/lib/R/etc/
COPY build/Renviron.site /usr/local/lib/R/etc/

ENV TZ=Europe/Dublin

Expand All @@ -17,23 +20,38 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
libglpk-dev \
libgsl-dev \
libnlopt-dev \
libomp-dev \
p7zip-full \
pbzip2 \
rsyslog \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& mkdir -p $HOME/.R \
&& echo "" > $HOME/.R/Makevars \
&& echo "CC=clang" >> $HOME/.R/Makevars \
&& echo "CXX=clang++" >> $HOME/.R/Makevars \
&& echo "CXXFLAGS=-Os" >> $HOME/.R/Makevars \
&& echo "CXXFLAGS+= -Wno-unused-variable -Wno-unused-function" >> $HOME/.R/Makevars \
&& echo "CXXFLAGS+= -Wno-unknown-pragmas -Wno-macro-redefined" >> $HOME/.R/Makevars \
&& echo "" >> $HOME/.R/Makevars \
&& echo "CC11=clang" >> $HOME/.R/Makevars \
&& echo "CXX11=clang++" >> $HOME/.R/Makevars \
&& echo "CXX11FLAGS=-Os" >> $HOME/.R/Makevars \
&& echo "CXX11FLAGS+= -Wno-unused-variable -Wno-unused-function" >> $HOME/.R/Makevars \
&& echo "CXX11FLAGS+= -Wno-unknown-pragmas -Wno-macro-redefined" >> $HOME/.R/Makevars \
&& echo "" >> $HOME/.R/Makevars \
&& echo "CC14=clang" >> $HOME/.R/Makevars \
&& echo "CXX14=clang++" >> $HOME/.R/Makevars \
&& echo "CXX14FLAGS=-Os" >> $HOME/.R/Makevars \
&& echo "CXX14FLAGS+= -Wno-unused-variable -Wno-unused-function" >> $HOME/.R/Makevars \
&& echo "CXX14FLAGS+= -Wno-unknown-pragmas -Wno-macro-redefined" >> $HOME/.R/Makevars \
&& echo "" >> $HOME/.R/Makevars \
&& echo "CC17=clang++" >> $HOME/.R/Makevars \
&& echo "CXX17=clang++" >> $HOME/.R/Makevars \
&& echo "CXX17FLAGS=-Os" >> $HOME/.R/Makevars \
&& echo "CXX17FLAGS+= -Wno-unused-variable -Wno-unused-function" >> $HOME/.R/Makevars \
&& echo "CXX17FLAGS+= -Wno-unknown-pragmas -Wno-macro-redefined" >> $HOME/.R/Makevars \
&& echo "" >> $HOME/.R/Makevars \
&& install2.r --error \
anytime \
bayesplot \
Expand All @@ -50,6 +68,7 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
fs \
furrr \
loo \
markdown \
modeltime \
posterior \
projpred \
Expand All @@ -70,8 +89,6 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime \
timetk


COPY build/logging.conf /etc/rstudio/

WORKDIR /tmp

COPY build/docker_install_sys_rpkgs.R /tmp
Expand Down Expand Up @@ -107,5 +124,14 @@ RUN Rscript /tmp/docker_install_user_rpkgs.R
USER root

RUN chown -R rstudio:rstudio /home/rstudio \
&& chmod ugo+rx /home/rstudio
&& chmod ugo+rx /home/rstudio \
&& chown -R rstudio:rstudio /home/rstudio/.cmdstan


ARG BUILD_DATE

LABEL org.opencontainers.image.source="https://github.com/kaybenleroll/btydbayes_investigation" \
org.opencontainers.image.authors="Mick Cooney <[email protected]>" \
org.label-schema.build-date=$BUILD_DATE


37 changes: 30 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DOCKER_USER=rstudio
DOCKER_PASS=CHANGEME
DOCKER_UID=$(shell id -u)
DOCKER_GID=$(shell id -g)
DOCKER_BUILD_ARGS=

RSTUDIO_PORT=8787

Expand All @@ -30,8 +31,7 @@ all-html: $(HTML_FILES)

.qmd.html:
echo "TIMESTAMP:" `date` "- Rendering script $<" >> output.log 2>&1
quarto render $< --to html >> output.log 2>&1
# Rscript -e 'quarto::quarto_render("$<")' >> output.log 2>&1
quarto render $< --to html >> output.log 2>&1
echo "TIMESTAMP:" `date` "- Finished $*.html" >> output.log 2>&1


Expand All @@ -44,14 +44,25 @@ full_deps.dot:
depgraph: full_deps.png


exploring_shortsynth_data.html: generate_transaction_datasets.html
exploring_longsynth_data.html: generate_transaction_datasets.html
exploring_online_retail_transactions.html: retrieve_retail_data.html
exploring_cdnow_dataset.html: retrieve_retail_data.html

initial_pnbd_models.html: exploring_shortsynth_data.html
construct_longsynth_fixed_pnbd_models.html: exploring_longsynth_data.html
construct_onlineretail_fixed_pnbd_models.html: exploring_online_retail_transactions.html
construct_cdnow_fixed_pnbd_models.html: exploring_cdnow_dataset.html

initial_pnbd_models.html: generate_transaction_datasets.html
construct_shortsynth_onehier_pnbd_models.html: initial_pnbd_models.html
construct_longsynth_onehier_pnbd_models.html: construct_longsynth_fixed_pnbd_models.html
construct_onlineretail_onehier_pnbd_models.html: construct_onlineretail_fixed_pnbd_models.html
construct_cdnow_onehier_pnbd_models.html: construct_cdnow_fixed_pnbd_models.html

construct_longsynth_fixed_pnbd_models.html: initial_pnbd_models.html
construct_onlineretail_fixed_pnbd_models.html: exploring_online_retail_transactions.html \
initial_pnbd_models.html
construct_shortsynth_twohier_pnbd_models.html: construct_shortsynth_onehier_pnbd_models.html
construct_longsynth_twohier_pnbd_models.html: construct_longsynth_onehier_pnbd_models.html
construct_onlineretail_twohier_pnbd_models.html: construct_onlineretail_onehier_pnbd_models.html
construct_cdnow_twohier_pnbd_models.html: construct_cdnow_onehier_pnbd_models.html


mrproper: clean-cache clean-data clean-html clean-precompute clean-models
Expand Down Expand Up @@ -79,7 +90,15 @@ clean-models:

### Docker targets
docker-build-image: Dockerfile
docker build -t ${IMAGE_TAG} -f Dockerfile .
docker build -t ${IMAGE_TAG} \
${DOCKER_BUILD_ARGS} \
--build-arg BUILD_DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ') \
-f Dockerfile . 2>&1 | tee -a docker_build.log

docker-show-context:
docker build -f build/context.dockerfile -t context-image .
docker run --rm -it context-image find /tmp/build
docker rmi test:latest

docker-run:
docker run --rm -d \
Expand All @@ -92,6 +111,10 @@ docker-run:
--name ${CONTAINER_NAME} \
${IMAGE_TAG}

docker-fix-permissions:
docker exec ${CONTAINER_NAME} bash -c "chown -R ${DOCKER_USER}:${DOCKER_USER} /home/${DOCKER_USER}"


docker-bash:
docker exec -it -u ${DOCKER_USER} ${CONTAINER_NAME} bash

Expand Down
2 changes: 2 additions & 0 deletions btydbayes_investigation.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Makefile

MarkdownReferences: Document
15 changes: 15 additions & 0 deletions build/Renviron.site
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
R_LIBS=${R_LIBS-'/usr/local/lib/R/site-library:/usr/local/lib/R/library'}
CRAN=https://packagemanager.posit.co/cran/2023-10-06
CWD=/home/rstudio
DEFAULT_USER=rstudio
GROUPID=1000
HOSTNAME=2a08c571a82c
LANG=en_US.UTF-8
PANDOC_VERSION=default
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
QUARTO_VERSION=default
R_HOME=/usr/local/lib/R
R_VERSION=4.3.1
S6_VERSION=v2.1.0.2
USER=rstudio
USERID=1000
3 changes: 3 additions & 0 deletions build/Rprofile.site
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
options(repos = c(CRAN = 'https://packagemanager.posit.co/cran/2023-10-06'), download.file.method = 'libcurl')
# https://docs.rstudio.com/rspm/admin/serving-binaries/#binaries-r-configuration-linux
options(HTTPUserAgent = sprintf("R/%s R (%s)", getRversion(), paste(getRversion(), R.version["platform"], R.version["arch"], R.version["os"])))
5 changes: 5 additions & 0 deletions build/context.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM busybox

RUN mkdir /tmp/build/
# Add context to /tmp/build/
COPY . /tmp/build/
14 changes: 11 additions & 3 deletions build/docker_install_user_rpkgs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
remotes::install_github(
"stan-dev/cmdstanr",
ref = "v0.5.3",
ref = "v0.6.1",
upgrade = "never"
)

Expand All @@ -15,16 +15,24 @@ remotes::install_github(
library(cmdstanr)

cmdstan_flags <- list(
"CC" = "clang",
"CXX" = "clang++",
"CXXFLAGS" = "-Os -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -Wno-macro-redefined",
"CC11" = "clang",
"CXX11" = "clang++",
"CXX11FLAGS" = "-Os -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -Wno-macro-redefined",
"CC14" = "clang",
"CXX14" = "clang++",
"CXX14FLAGS" = "-Os -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -Wno-macro-redefined"
"CXX14FLAGS" = "-Os -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -Wno-macro-redefined",
"CC17" = "clang",
"CXX17" = "clang++",
"CXX17FLAGS" = "-Os -Wno-unused-variable -Wno-unused-function -Wno-unknown-pragmas -Wno-macro-redefined"
)

install_cmdstan(
cores = parallel::detectCores(),
cpp_options = cmdstan_flags,
quiet = FALSE,
overwrite = FALSE,
version = "2.32.1"
version = "2.33.0"
)
3 changes: 0 additions & 3 deletions build/logging.conf

This file was deleted.

71 changes: 0 additions & 71 deletions build/test_report.qmd

This file was deleted.

23 changes: 23 additions & 0 deletions calculate_var_sizes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

calculate_object_size <- function(x) {
message(glue("Calculating size for object {x}"))

size <- x |>
get() |>
obj_size()

return(size)
}


var_sizes_tbl <- ls() |>
enframe(name = NULL, value = "object_name") |>
mutate(
object_size = map_dbl(
object_name, calculate_object_size,
.progress = FALSE
),
object_size_mb = object_size / (1024 * 1024)
)

var_sizes_tbl |> glimpse()
Loading

0 comments on commit bb5c603

Please sign in to comment.