Skip to content

Instantly share code, notes, and snippets.

View njtierney's full-sized avatar
👷‍♂️
Have some work availability from July 2026

Nicholas Tierney njtierney

👷‍♂️
Have some work availability from July 2026
View GitHub Profile
choice_set_hours <- function(hour_increments, n_hour_options) {
  choice_set <- seq(
    from = 0,
    to = (n_hour_options - 1) * hour_increments,
    by = hour_increments
  )
  choice_set
}
@njtierney
njtierney / ugh-optim.md
Last active May 30, 2025 07:03
ugh-optim
## requires pass by position?

fr_pos <- function(x) {   ## Rosenbrock Banana function
    x1 <- x[1]
    x2 <- x[2]
    100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}

pars <- list(a = -1.2, b = 1)
# example code from test_posteriors_geweke
devtools::load_all(".")
n <- 10
# mu1 <- rnorm(1, 0, 3)
# sd1 <- rlnorm(1)
# sd2 <- rlnorm(1)
mu1 <- 0
sd1 <- 2
sd2 <- 1
e <- new.env()
e$x <- 10
e$y <- 20

eval(quote(x + y), envir = e)
#> [1] 30

e2 <- new.env()
# Warming up the sampler and running extra samples on the model with the initial dataset (ie. not changing it each iteration) should tell us whether the sampler is correctly adapted.
library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#> 
library(rlang)

preserved_goods_none <- function(goods = c("cucumber", "lemon", "pear")) {
  goods
}

preserved_goods_rlang <- function(goods = c("cucumber", "lemon", "pear")) {
  goods <- rlang::arg_match(
    arg = goods
mat1 <- matrix(1:10, ncol = 2)
mat2 <- matrix(2:11, ncol = 2)

list_matrices <- list(mat1, mat2)
list_matrices
#> [[1]]
#>      [,1] [,2]
#> [1,]    1    6
#> [2,]    2    7
mat <- matrix(
  sample(x = c(1, 0), size = 9, replace = TRUE),
  nrow = 3,
  ncol = 3
)

mat
#>      [,1] [,2] [,3]
#> [1,]    1    1    0
# implement bursted sampling, but unbirsted warmup using TFP adaptation

# use greta to get log prob for a knotty model
library(greta)
#> 
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#> 
#>     binomial, cov2cor, poisson
library(ggplot2)
ggplot(mtcars,
       aes(x = mpg,
           y = cyl)) + 
  geom_point()