-
Notifications
You must be signed in to change notification settings - Fork 7
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
Fix bug in dpMean$release to fix "variable 'fun' not found" error #49
Comments
tracing the bug:the boot_mean <- dpMean$new(mechanism='mechanismBootstrap', var.type='numeric',
variable='income', n=10000, epsilon=0.1, rng=c(0, 750000),
n.boot=n.boot) Then we have the call: boot_mean$release(PUMS5extract10000) which refers to the
dpMean$methods(
release = function(data, ...) {
x <- data[, variable]
sens <- diff(rng) / n
.self$result <- export(mechanism)$evaluate(mean, x, sens, .self$postProcess, ...)
})
mechanismBootstrap$methods(
evaluate = function(fun, x, sens, postFun) {
x <- censordata(x, .self$var.type, .self$rng)
x <- fillMissing(x, .self$var.type, .self$impute.rng[0], .self$impute.rng[1])
epsilon.part <- epsilon / .self$n.boot
release <- replicate(.self$n.boot, bootstrap.replication(x, n, sens, epsilon.part, fun=.self$bootStatEval))
std.error <- .self$bootSE(release, .self$n.boot, sens)
out <- list('release' = release, 'std.error' = std.error)
out <- postFun(out)
return(out)
}) Interesting to note that the According to the stack trace from the error, the problem here is the
bootstrap.replication <- function(x, n, sensitivity, epsilon, fun) {
partition <- rmultinom(n=1, size=n, prob=rep(1 / n, n))
max.appearances <- max(partition)
probs <- sapply(1:max.appearances, dbinom, size=n, prob=(1 / n))
stat.partitions <- vector('list', max.appearances)
for (i in 1:max.appearances) {
variance.i <- (i * probs[i] * (sensitivity^2)) / (2 * epsilon)
stat.i <- fun(x[partition == i])
noise.i <- dpNoise(n=length(stat.i), scale=sqrt(variance.i), dist='gaussian')
stat.partitions[[i]] <- i * stat.i + noise.i
}
stat.out <- do.call(rbind, stat.partitions)
return(apply(stat.out, 2, sum))
}
Here, I wanted to figure out what
mechanismBootstrap$methods(
bootStatEval = function(xi) {
fun.args <- getFuncArgs(fun, inputList=list(...), inputObject=.self)
input.vals = c(list(x=x), fun.args)
stat <- do.call(boot.fun, input.vals)
return(stat)
}) I think I found the problem: The Then, in In the I think the call to The error happens because (Similarly, a |
fixed the bug:in changed
changed
changed
changed
changed
changed
changed
|
Now the |
The |
Also fix a bug that becomes apparent after fixing the original bug: Not all partitions in the bootstrap replication are necessarily be filled, yielding NaN values when the statistic is calculated. Add data validation to ensure only calculating statistic on partitions that contain values.
Fixed all problems. Added validation in bootstrap.replication to ensure it is only calculating a statistic for a partition that contains values. |
Will discuss with Ira which option is best
…n instead of sum. This addresses the huge standard error that results from bootstrapping. This was another bug found after fixing Issue #49.
Bug found 6/4
error:
When running the
dp-mean.Rmd
vignette, at lineboot_mean$release(PUMS5extract10000)
, get the error:Error in formals(targetFunc) : object 'fun' not found
source:
mechanism-bootstrap.R, line 41:
getFuncArgs
uses a variable calledfun
, but there is nofun
parameter in the method signature.The text was updated successfully, but these errors were encountered: