Skip to content

Commit

Permalink
Merge pull request #134 from kbarbary/readability
Browse files Browse the repository at this point in the history
Grab-bag of cosmetic changes
  • Loading branch information
jeff-regier committed Mar 5, 2016
2 parents 207a7bc + 90c56c9 commit 4844d43
Show file tree
Hide file tree
Showing 30 changed files with 1,165 additions and 1,211 deletions.
17 changes: 7 additions & 10 deletions bin/benchmark_elbo.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
#!/usr/bin/env julia

using Celeste
using CelesteTypes
import Celeste: SampleData, ElboDeriv

import Synthetic
import ModelInit
import SampleData

const dat_dir = joinpath(Pkg.dir("Celeste"), "dat")
const CALC_HESS = false # with hessian?

srand(1)
println("Loading data.")
Expand All @@ -19,14 +14,16 @@ blob, mp, body, tiled_blob =
println("Calculating ELBO.")

# do a trial run first, so we don't profile/time compling the code
@time elbo = ElboDeriv.elbo(tiled_blob, mp, calculate_hessian=false);
@time elbo = ElboDeriv.elbo(tiled_blob, mp, calculate_hessian=CALC_HESS);

# let's time it without any overhead from profiling
@time elbo = ElboDeriv.elbo(tiled_blob, mp, calculate_hessian=false);
@time elbo = ElboDeriv.elbo(tiled_blob, mp, calculate_hessian=CALC_HESS);

# on a intel core2 Q6600 processor,
# median runtime is consistently 27 seconds with Julia 0.3
# median runtime is consistently 24 seconds with Julia 0.4
Profile.init(10^8, 0.001)
@profile elbo = ElboDeriv.elbo(tiled_blob, mp, calculate_hessian=false);
Profile.clear_malloc_data()
#@profile elbo = ElboDeriv.elbo(tiled_blob, mp, calculate_hessian=CALC_HESS);
@profile elbo = ElboDeriv.elbo_likelihood(tiled_blob, mp, calculate_hessian=CALC_HESS);
Profile.print(format=:flat)
32 changes: 0 additions & 32 deletions bin/benchmark_elbo_with_hessian.jl

This file was deleted.

6 changes: 1 addition & 5 deletions bin/celeste.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
#!/usr/bin/env julia

using Celeste
using CelesteTypes
using DocOpt
using JLD
import SloanDigitalSkySurvey: SDSS
import Base: convert
import Celeste

const DOC =
"""Run Celeste.
Expand Down
31 changes: 14 additions & 17 deletions src/Celeste.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
module Celeste

push!(LOAD_PATH, joinpath(Pkg.dir("Celeste"), "src"))

import SkyImages
import ElboDeriv
import OptimizeElbo
import ModelInit
import SampleData
import Transform
import KL

using CelesteTypes

using DataFrames
using JLD
using FITSIO
import SloanDigitalSkySurvey.SDSS
# submodules
include("Types.jl")
include("SensitiveFloats.jl")
include("Util.jl")
include("KL.jl")
include("ElboDeriv.jl")
include("SkyImages.jl")
include("Transform.jl")
include("OptimizeElbo.jl")
include("ModelInit.jl")
include("Synthetic.jl")
include("SampleData.jl")

# public API
export infer, score_field
include("api.jl")
include("score.jl")

end # module
45 changes: 22 additions & 23 deletions src/CelesteCluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# TODO: this used to be in ElboDeriv and everything that uses it needs
# to be fixed.
@doc """
"""
A type containing all the information that needs to be communicated
to worker nodes at each iteration. This currently consists of pre-computed
information about each source.
Expand All @@ -16,18 +16,18 @@ Attributes:
star_mcs_vec: A vector of star BVN components, one for each band
gal_mcs_vec: A vector of galaxy BVN components, one for each band
sbs_vec: A vector of brightness vectors, one for each band
""" ->
"""
type ParameterMessage{NumType <: Number}
vp::VariationalParams{NumType}
star_mcs_vec::Vector{Array{BvnComponent{NumType},2}}
gal_mcs_vec::Vector{Array{GalaxyCacheComponent{NumType},4}}
sbs_vec::Vector{Vector{SourceBrightness{NumType}}}
end

@doc """
"""
This allocates memory for but does not initialize the source parameters.
""" ->
ParameterMessage{NumType <: Number}(mp::ModelParams{NumType}) = begin
"""
function ParameterMessage{NumType <: Number}(mp::ModelParams{NumType})
num_bands = size(mp.patches)[2]
star_mcs_vec = Array(Array{BvnComponent{NumType},2}, num_bands)
gal_mcs_vec = Array(Array{GalaxyCacheComponent{NumType},4}, num_bands)
Expand All @@ -36,14 +36,14 @@ ParameterMessage{NumType <: Number}(mp::ModelParams{NumType}) = begin
end


@doc """
"""
Update a ParameterMessage in place using mp.
Args:
- mp: A ModelParams object
- param_msg: A ParameterMessage that is updated using the parameter values
in mp.
""" ->
"""
function update_parameter_message!{NumType <: Number}(
mp::ModelParams{NumType}, param_msg::ParameterMessage{NumType})
for b=1:5
Expand All @@ -54,10 +54,10 @@ function update_parameter_message!{NumType <: Number}(
end
end

@doc """
"""
Evaluate the ELBO with pre-computed brightnesses and components
stored in ParameterMessage.
""" ->
"""
function elbo_likelihood!{NumType <: Number}(
tiled_blob::TiledBlob,
param_msg::ParameterMessage{NumType},
Expand All @@ -76,10 +76,9 @@ end


VERSION < v"0.4.0-dev" && using Docile
using Celeste
using CelesteTypes
using Celeste.Types
using JLD
import SampleData.dat_dir
import Celeste.SampleData.dat_dir

# Like @everywhere but for remote workers only.
macro everywhereelse(ex)
Expand All @@ -100,12 +99,12 @@ macro runat(p, ex)
end


@doc """
"""
Return a vector of the sources that affect the node. Assumes tiled_blob
and mp are globally defined.
""" ->
"""
function node_sources()
sources = Int64[]
sources = Int[]
for b in 1:5
for tile_ind in 1:length(tiled_blob[b])
append!(sources, mp.tile_sources[b][tile_ind])
Expand All @@ -114,10 +113,10 @@ function node_sources()
unique(sources)
end

@doc """
"""
Close all but the current worker and then add nw of them.
""" ->
function create_workers(nw::Int64)
"""
function create_workers(nw::Int)
println("Adding workers.")
for worker in workers()
if worker != myid()
Expand All @@ -129,7 +128,7 @@ function create_workers(nw::Int64)
end


@doc """
"""
Load synthetic or actual data across the cluster of workers.
This requires certain variables to be defined in the global scope.
Expand All @@ -139,7 +138,7 @@ This requires certain variables to be defined in the global scope.
If synthetic is false, the file frame_jld_file must contain a dictionary
with an initialized TiledBlob and ModelParams object.
""" ->
"""
function load_cluster_data()
println("Loading data.")
@everywhere begin
Expand All @@ -157,7 +156,7 @@ function load_cluster_data()
end


@doc """
"""
Perform a number of initialization tasks across the cluster. The result
is a set of globally defined variables on each worker. It assumes that
each worker has its own identical copy of mp and tiled_blob as global
Expand All @@ -169,7 +168,7 @@ The tasks are:
- Initialize the ParameterMessage objects and define RemoteRefs for
communicating updates.
- Initialize the sensitive floats and define RemoteRefs for communicating them.
""" ->
"""
function initialize_cluster()
# It's more convenient to define global variables than
# to make RemoteRefs for everything. Eventually maybe we should wrap
Expand Down Expand Up @@ -253,7 +252,7 @@ end


function eval_worker_hessian()
omitted_ids = Int64[]
omitted_ids = Int[]

global hess_i, hess_j, hess_val, new_hess_time

Expand Down
Loading

0 comments on commit 4844d43

Please sign in to comment.