Skip to content

Commit

Permalink
update to Julia 0.5 -- remove deprecated usage of ASCIIString and hist
Browse files Browse the repository at this point in the history
  • Loading branch information
jwmi committed Oct 6, 2016
1 parent 50f151b commit 03054ab
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1 +1 @@
julia 0.4
julia 0.5
26 changes: 24 additions & 2 deletions src/BayesianMixtures.jl
Expand Up @@ -136,11 +136,33 @@ function t_running(result)
return cdfs
end

# Compute histogram with the specified bin edges,
# where x[i] is in bin j if edges[j] < x[i] <= edges[j+1].
function histogram(x, edges=[]; n_bins=50)
if isempty(edges)
mn,mx = minimum(x),maximum(x)
r = mx-mn
edges = linspace(mn-r/n_bins, mx+r/n_bins, n_bins)
else
n_bins = length(edges)-1
end
counts = zeros(Int,n_bins)
for i=1:length(x)
for j=1:n_bins
if (edges[j] < x[i] <= edges[j+1])
counts[j] += 1
break
end
end
end
return counts,edges
end

# Compute posterior on t (# of clusters)
function t_posterior(result)
o = result.options
use = o.n_burn+1:o.n_total
edges,counts = hist(result.t[use], 0:o.t_max) # bins are: (0,1],(1,2],...,(t_max-1,t_max]
counts,edges = histogram(result.t[use], 0:o.t_max) # bins are: (0,1],(1,2],...,(t_max-1,t_max]
return counts/length(use)
end

Expand Down Expand Up @@ -413,7 +435,7 @@ end
function plot_histogram(data; kwargs...) # Histogram of data
checkplotting()
@assert(all(map(length,data).==1),"Histogram only enabled for univariate data.")
edges,counts = hist(data,50)
counts,edges = histogram(data; n_bins=50)
PyPlot.bar(edges[1:end-1],counts./(length(data)*diff(edges)),diff(edges); kwargs...)
title("Histogram")
draw_now()
Expand Down
10 changes: 5 additions & 5 deletions src/generic.jl
@@ -1,7 +1,7 @@

type Options
mode::ASCIIString
model_type::ASCIIString
mode::String
model_type::String
x::Array{Data,1}
n_total::Int64
n_keep::Int64
Expand All @@ -11,10 +11,10 @@ type Options
t_max::Int64
# MFM options
gamma::Float64
log_pk::ASCIIString
log_pk::String
# DPM options
alpha_random::Bool
p_alpha::ASCIIString
p_alpha::String
alpha::Float64
# Jain-Neal split-merge options
use_splitmerge::Bool
Expand All @@ -28,7 +28,7 @@ type Options
log_v::Array{Float64,1}
# Other
n::Int64
module_name::ASCIIString
module_name::String
end

type Result
Expand Down

0 comments on commit 03054ab

Please sign in to comment.