Skip to content

Commit

Permalink
Merge pull request #130 from dwijenchawra/master
Browse files Browse the repository at this point in the history
Fix for #121
  • Loading branch information
mykelk authored May 13, 2021
2 parents b700d78 + dc240d6 commit bae05ed
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"


[compat]
DataFrames = "0.21,0.22"
DataFrames = "0.22,1.0,1.1"
DataStructures = "0.11,0.12,0.13,0.14,0.15,0.16,0.17,0.18"
Discretizers = "3.0"
Distributions = "0.17,0.18,0.19,0.20,0.21,0.22,0.23,0.24"
Expand Down
5 changes: 2 additions & 3 deletions src/DiscreteBayesNet/discrete_bayes_net.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ function statistics(dag::DAG, data::DataFrame)

parents = [inneighbors(dag, i) for i in 1:n]
ncategories = [Int(infer_number_of_instantiations(data[!,i])) for i in 1 : n]
datamat = convert(Matrix{Int}, data)'
datamat = Matrix{Int}(data)'

statistics(parents, ncategories, datamat)
end
Expand All @@ -255,8 +255,7 @@ function statistics(bn::DiscreteBayesNet, target::NodeName, data::DataFrame)
targetind = bn.name_to_index[target]
parents = inneighbors(bn.dag, targetind)
ncategories = [Int(infer_number_of_instantiations(data[!,i])) for i in 1 : n]
datamat = convert(Matrix{Int}, data)'

datamat = Matrix{Int}(data)'
statistics(targetind, parents, ncategories, datamat)
end

Expand Down
2 changes: 1 addition & 1 deletion src/DiscreteBayesNet/greedy_hill_climbing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function Distributions.fit(::Type{DiscreteBayesNet}, data::DataFrame, params::Gr

n = ncol(data)
parent_list = map!(i->Int[], Array{Vector{Int}}(undef, n), 1:n)
datamat = convert(Matrix{Int}, data)'
datamat = Matrix{Int}(data)'
score_components = bayesian_score_components(parent_list, ncategories, datamat, params.prior, params.cache)

while true
Expand Down
2 changes: 1 addition & 1 deletion src/DiscreteBayesNet/greedy_thick_thinning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function Distributions.fit(::Type{DiscreteBayesNet}, data::DataFrame, params::Gr

n = ncol(data)
parent_list = map!(i->Int[], Array{Vector{Int}}(n), 1:n)
datamat = convert(Matrix{Int}, data)'
datamat = Matrix{Int}(data)'
score_components = bayesian_score_components(parent_list, ncategories, datamat, params.prior, params.cache)

while true
Expand Down
2 changes: 1 addition & 1 deletion src/DiscreteBayesNet/scan_greedy_hill_climbing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function Distributions.fit(::Type{DiscreteBayesNet}, data::DataFrame, params::Sc

n = ncol(data)
parent_list = map!(i->Int[], Array{Vector{Int}}(undef, n), 1:n)
datamat = convert(Matrix{Int}, data)'
datamat = Matrix{Int}(data)'
score_components = bayesian_score_components(parent_list, ncategories, datamat, params.prior, params.cache)

# 0 depth
Expand Down
4 changes: 2 additions & 2 deletions src/DiscreteBayesNet/structure_scoring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function bayesian_score(bn::DiscreteBayesNet, data::DataFrame, prior::DirichletP
n = length(bn)
parent_list = Array{Vector{Int}}(undef, n)
ncategories = Array{Int}(undef, n)
datamat = convert(Matrix{Int}, data)'
datamat = Matrix{Int}(data)'

for (i,cpd) in enumerate(bn.cpds)
parent_list[i] = inneighbors(bn.dag, i)
Expand Down Expand Up @@ -168,7 +168,7 @@ function bayesian_score_components(bn::DiscreteBayesNet, data::DataFrame, prior:
n = length(bn)
parent_list = Array{Vector{Int}}(undef, n)
ncategories = Array{Int}(undef, n)
datamat = convert(Matrix{Int}, data)'
datamat = Matrix{Int}(data)'

for (i,cpd) in enumerate(bn.cpds)
parent_list[i] = inneighbors(bn.dag, i)
Expand Down
2 changes: 1 addition & 1 deletion src/Factors/factors_dataframes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Convert a Factor to a DataFrame
"""
function Base.convert(::Type{DataFrame}, ϕ::Factor)
df = DataFrames.DataFrame(pattern(ϕ))
df = DataFrames.DataFrame(pattern(ϕ), :auto)
DataFrames.rename!(df, [f => t for (f, t) = zip(names(df), names(ϕ))] )
df[!,:potential] = ϕ.potential[:]

Expand Down
2 changes: 1 addition & 1 deletion src/gibbs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function gibbs_sample_main_loop(

end

return convert(DataFrame, t), (now() - start_time).value
return DataFrame(t), (now() - start_time).value
end

"""
Expand Down
3 changes: 2 additions & 1 deletion src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ function get_weighted_dataframe(bn::BayesNet, nsamples::Integer, evidence::Assig
end
t[:p] = w / sum(w)

convert(DataFrame, t)

t = DataFrame(t)
end

get_weighted_dataframe(bn::BayesNet, nsamples::Integer, pair::Pair{NodeName}...) =
Expand Down
2 changes: 1 addition & 1 deletion test/test_discrete_bayes_nets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let
n = length(bn)
parent_list = Array{Vector{Int}}(undef, n)
bincounts = Array{Int}(undef, n)
datamat = convert(Matrix{Int}, data)'
datamat = Matrix{Int}(data)'

for (i,cpd) in enumerate(bn.cpds)
parent_list[i] = inneighbors(bn.dag, i)
Expand Down

0 comments on commit bae05ed

Please sign in to comment.