Closed MathiasRenaud closed 7 years ago
Currently tracing run.smc
to solve issue
Running initialize.smc
with the same config as above gives 50 trees in ws$sim.trees (5 samples * 10 particles).
@MathiasRenaud noticed that in smcABC.R
we are needlessly replicating samples:
for (j in 1:config$nsample) {
# retain sim.trees in case we revert to previous particle
new.trees <- simulate.trees(ws, new.particle, model=model)
new.dists[,i] <- sapply(new.trees, function(sim.tree) {
distance(ws$obs.tree, sim.tree, config)
})
}
simulate.trees
should already be simulating config$nsample
trees per particle, so there should be no need to loop over nsample
. Fix and see if this explains this issue.
I have figured out that manually running each line of run.smc
works and updates the workspace to store the simulated trees, particles, weights, new.weights, dists. However, calling the function directly gives the same result but does not update the items in workspace.
.epsilon.obj.func
is called by .next.epsilon
to solve for the new epsilon. The function takes the arguments ws & epsilon and returns the value of (.ess(ws$new.weights) - config$quality * .ess(ws$weights))
but not ws.
Currently working on a way to pass both the value of the new epsilon and the updated workspace back to .next.epsilon
. The tricky part is that .epsilon.obj.func
is called within uniroot
, so the return value must numerical to be usable by uniroot
.
Here is the use in next.epsilon
:
res <- uniroot(function(x) .epsilon.obj.func(ws, x), lower=0,
upper=ws$epsilon, tol=config$step.tolerance, maxiter=1E6)
root <- res$root
run.smc
is not returning workspace object ws
, instead it returns list object results
. Try returning both as a list containing the two objects and see if ws
contains expected data, i.e., newick tree strings.
run.smc
now returns ret
, where ret
is a named list of workspace and result. Workspace now stores all expected data from run.smc
.
# pack ws and result into one list to be returned
ret <- list(workspace=ws, result=result)
return (ret)
run.smc
with 10 particles results in:ws$sim.trees should contain the simulated trees instead of integers.