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

How to run sampler with sigma fixed? #64

Open
jacobenglert opened this issue Dec 22, 2023 · 0 comments
Open

How to run sampler with sigma fixed? #64

jacobenglert opened this issue Dec 22, 2023 · 0 comments

Comments

@jacobenglert
Copy link

jacobenglert commented Dec 22, 2023

Suppose we are fitting a normal BART model using a dbarts sampler and we know the true residual variance is equal to one. When I specify resid.prior = fixed(1), it seems like the sampler is respecting my wishes. But when I interrogate the state of the sampler after running there is a sigma $\ne 1$. Can someone explain what exactly is happening here?

I actually do have a problem where I will need to be able to do this. The above solution appears to be working despite the sigma inside sampler$state, but I just want to confirm. If this actually is not working, I will need to find some other way around it.

Reproducible example:

# Fixed sigma reprex

# Simulate Data
set.seed(1)
n <- 100
p <- 5
x <- t(replicate(n, runif(p, 0, 1)))
f <- function(x){
  10*sin(pi*x[,1]*x[,2]) + 20*(x[,3] - .5)^2 + 10*x[,4] + 5*x[,5]
}

y <- rnorm(n, f(x), 1)

# Create dbarts sampler object
library(dbarts)
control <- dbartsControl(n.trees = 100, n.samples = 1000, n.burn = 0,
                         n.chains = 1, keepTrees = TRUE, keepTrainingFits = TRUE,
                         updateState = TRUE, verbose = FALSE)

sampler <- dbarts(x, y, control = control, resid.prior = fixed(1), sigma = 1)

sigma <- numeric(1000)
for(k in seq_len(1000)){
  samples <- sampler$run(0, 1)
  sigma[k] <- samples$sigma
}

# Print sigma stored in state
print(sampler$state[[1]]@sigma)

# Plot sigma values
plot(sigma)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant