Skip to content

Commit

Permalink
Added docs annotations, related to #9
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjwilliams1 committed Aug 7, 2017
1 parent d84d5dd commit d9363df
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 18 deletions.
31 changes: 13 additions & 18 deletions src/ABCalgorithm.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
"""
runabc(ABCsetup::ABCtype, targetdata; progress = false)
Run the ABC algorithm specified by ABCsetup and return and ABCresults type containing posterior distribution samples. If progress is set to true, will print out a ProgressMeter bar.
"""
function runabc(ABCsetup::ABCRejection, targetdata; progress = false)

#initalize array of particles
Expand Down Expand Up @@ -42,7 +46,6 @@ function runabc(ABCsetup::ABCRejection, targetdata; progress = false)

end


function runabc(ABCsetup::ABCRejectionModel, targetdata; progress = false)

ABCsetup.nmodels > 1 || error("Only 1 model specified, use ABCRejection method to estimate parameters for a single model")
Expand Down Expand Up @@ -80,8 +83,6 @@ function runabc(ABCsetup::ABCRejectionModel, targetdata; progress = false)
next!(p)
end
end


end

i > ABCsetup.Models[1].nparticles || error("Only accepted $(i-1) particles with ϵ < $(ABCsetup.Models[1].ϵ). \n\tDecrease ϵ or increase maxiterations ")
Expand Down Expand Up @@ -192,15 +193,10 @@ function runabc(ABCsetup::ABCSMC, targetdata; verbose = false, progress = false)
flush(STDOUT)
flush(STDERR)
end

popnum = popnum + 1

end

out = ABCSMCresults(particles, numsims, ABCsetup, ϵvec)

return out

return ABCSMCresults(particles, numsims, ABCsetup, ϵvec)
end


Expand Down Expand Up @@ -237,7 +233,6 @@ function runabc(ABCsetup::ABCSMCModel, targetdata; verbose = false, progress = f
end

popnum = 1

finalpop = false

if verbose == true
Expand Down Expand Up @@ -338,12 +333,14 @@ function runabc(ABCsetup::ABCSMCModel, targetdata; verbose = false, progress = f

end

out = ABCSMCmodelresults(particles, numsims, ABCsetup, ϵvec)

return out

return ABCSMCmodelresults(particles, numsims, ABCsetup, ϵvec)
end

"""
runabcCancer(ABCsetup::ABCtype, targetdata; progress = false)
Specific implementation of the runabc function to be applied with CancerSeqSim.jl. Only lets a sample be considered true if it returns a the correct clonal structure. If progress is set to true, will print out a ProgressMeter bar.
"""
function runabcCancer(ABCsetup::ABCSMCModel, targetdata; verbose = false, progress = false)

ABCsetup.nmodels > 1 || error("Only 1 model specified, use ABCSMC method to estimate parameters for a single model")
Expand Down Expand Up @@ -487,14 +484,12 @@ function runabcCancer(ABCsetup::ABCSMCModel, targetdata; verbose = false, progre
if verbose == true
show(ABCSMCmodelresults(oldparticles, numsims, ABCsetup, ϵvec))
end

end

out = ABCSMCmodelresults(particles, numsims, ABCsetup, ϵvec)
return ABCSMCmodelresults(particles, numsims, ABCsetup, ϵvec)
end

return out

end

function runabcCancer(ABCsetup::ABCSMC, targetdata; verbose = false, progress = false)

Expand Down
53 changes: 53 additions & 0 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ type ParticleSMCModel <: Particle

end

"""
ABCrejection(sim_func::Function, nparams::Int64, ϵ::Float64, prior::Prior, <keyword arguments>)
Construct an ABCrejection type with simulation function `sim_func`, `nparams` parameters, `ϵ` distance threshold and prior distribution over parameters.
...
## Arguments
- `maxiterations = 10^3`: Maximum number of iterations before algorithm terminates
- `constants = [1.0]`: Any constants required in `sim_func` function
- `nparticles = 100`: Number of posterior samples
...
"""
type ABCRejection <: ABCtype

simfunc::Function
Expand All @@ -64,6 +75,21 @@ type ABCRejection <: ABCtype

end

"""
ABCSMC(sim_func::Function, nparams::Int64, ϵT::Float64, prior::Prior, <keyword arguments>)
Construct an ABCSMC type with simulation function `sim_func`, `nparams` parameters, `ϵT` target distance threshold and `prior` distribution over parameters.
...
## Arguments
- `maxiterations = 10^3`: Maximum number of iterations before algorithm terminates
- `constants = [1.0]`: Any constants required in `sim_func` function
- `nparticles = 100`: Number of posterior samples
- `α = 0.3`: SMC adaptive parameter, next population takes αth quantile of previous population distance
- `ϵ1 = 10^5`: ϵ of first population which is ABCrejection
- `convergence = 0.05`: Algorithm terminates if distance decreases < convergence
- `scalefactor = 2`: Parameter perturbation kernel scalefactor, larger numbers means perturbation are smaller
...
"""
type ABCSMC <: ABCtype

simfunc::Function
Expand Down Expand Up @@ -91,6 +117,16 @@ type ABCSMC <: ABCtype

end

"""
ABCrejectionModel(sim_func::Array{Function, 1}, nparams::Array{Int64, 1}, ϵ::Float64, prior::Array{Prior, 1}, <keyword arguments>)
Construct an ABCrejection Model type with simulation functions `sim_func`, `nparams` parameters, `ϵT` target distance threshold and `prior` distributions over parameters.
## Arguments
- `maxiterations = 10^3`: Maximum number of iterations before algorithm terminates
- `constants = [1.0]`: Any constants required in `sim_func` function
- `nparticles = 100`: Number of posterior samples
...
"""
type ABCRejectionModel <: ABCtype

Models::Array{ABCRejection, 1}
Expand All @@ -105,6 +141,23 @@ type ABCRejectionModel <: ABCtype

end


"""
ABCSMCmodel(sim_func::Array{Function, 1}, nparams::Array{Int64, 1}, ϵT::Float64, prior::Array{Prior, 1}, <keyword arguments>)
Construct an ABCSMCModel type with simulation functions `sim_func`, `nparams` parameters, `ϵT` target distance threshold and `prior` distributions over parameters. All arrays should be the same size.
...
## Arguments
- `maxiterations = 10^3`: Maximum number of iterations before algorithm terminates
- `constants = [1.0]`: Any constants required in `sim_func` function
- `nparticles = 100`: Number of posterior samples
- `α = 0.3`: SMC adaptive parameter, next population takes αth quantile of previous population distance
- `modelkern = 0.7`: Probability model stays the same following perturbation
- `ϵ1 = 10^5`: ϵ of first population which is ABCrejection
- `convergence = 0.05`: Algorithm terminates if distance decreases < convergence
- `scalefactor = 2`: Parameter perturbation kernel scalefactor, larger numbers means perturbation are smaller
...
"""
type ABCSMCModel <: ABCtype

Models::Array{ABCSMC, 1}
Expand Down

0 comments on commit d9363df

Please sign in to comment.