Skip to content

Commit

Permalink
Mostly fixed?
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebd99 committed Dec 7, 2023
1 parent 72b6516 commit a749ce0
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Experiments/Scripts/coloring_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Profile
include("../Experiments.jl")

datasets = [human]
datasets = [aids]
partitioning_schemes = [
[(Degree, 64)],
[(NeighborNodeLabels, 64)],
Expand All @@ -21,7 +21,7 @@ for dataset in datasets
end
end

build_experiments(experiment_params)
#build_experiments(experiment_params)

run_estimation_experiments(experiment_params)

Expand Down
9 changes: 3 additions & 6 deletions Experiments/run_estimators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function run_estimation_experiments(experiment_params_list::Vector{ExperimentPar
!isfile(summary_file_location) && error("The summary has not been built yet! \n Attempted File Location: $(summary_file_location)")
summary::ColorSummary = deserialize(summary_file_location)
experiment_results = []
push!(experiment_results, ("UpperBound", "Estimate", "LowerBound", "TrueCard", "EstimationTime", "QueryType", "QueryPath"))
push!(experiment_results, ("Estimate", "TrueCard", "EstimationTime", "QueryType", "QueryPath"))
for i in 1:length(all_queries[dataset])
query::QueryGraph = all_queries[dataset][i].query
query_path = all_queries[dataset][i].query_path
Expand All @@ -17,12 +17,9 @@ function run_estimation_experiments(experiment_params_list::Vector{ExperimentPar
sampling_strategy=experiment_params.sampling_strategy,
only_shortest_path_cycle= experiment_params.only_shortest_path_cycle)) for _ in 1:3]
estimate_time = median([x.time for x in estimate_results]) # Convert back to seconds from nano seconds
bounds = estimate_results[1].value
upper_bound = bounds[3]
estimate = max(1, bounds[2])
lower_bound = bounds[1]
estimate = estimate_results[1].value
query_type = all_queries[dataset][i].query_type
push!(experiment_results, (upper_bound, estimate, lower_bound, exact_size, estimate_time, query_type, query_path))
push!(experiment_results, (estimate, exact_size, estimate_time, query_type, query_path))
end
results_file_location = "Experiments/Results/Estimation_" * params_to_results_filename(experiment_params)
writedlm(results_file_location, experiment_results, ",")
Expand Down
2 changes: 1 addition & 1 deletion Source/ColorSummary.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ function generate_color_summary(g::DataGraph, params::ColorSummaryParams=ColorSu
for c1 in keys(color_to_color_edge_list[edge_label][vertex_label])
edge_deg[edge_label][vertex_label][c1] = Dict()
for c2 in keys(color_to_color_edge_list[edge_label][vertex_label][c1])
edge_deg[edge_label][vertex_label][c1][c2] = DS(g, color_to_color_edge_list[edge_label][vertex_label][c1][c2])
edge_deg[edge_label][vertex_label][c1][c2] = DS(g, color_to_color_edge_list[edge_label][vertex_label][c1][c2], color_label_cardinality[c1][-1])
end
end
end
Expand Down
20 changes: 8 additions & 12 deletions Source/DegreeStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mutable struct MinDegStats <:DegreeStats
min_out::Float64
end

function MinDegStats(g::DataGraph, edges::Vector{Tuple{NodeId, NodeId, Bool}})
function MinDegStats(g::DataGraph, edges::Vector{Tuple{NodeId, NodeId, Bool}}, color_size::Int)
length(edges) == 0 && return MinDegStats(0,0)
in_counter = counter(NodeId)
out_counter = counter(NodeId)
Expand Down Expand Up @@ -104,7 +104,7 @@ end

struct MinAccumulator <:StatAccumulator
weight::Float64
MinAccumulator(c::Float64) = new(c)
MinAccumulator(c::Union{Float64, Int64}) = new(c)
end
get_count(w::MinAccumulator) = w.weight
sum_colorings(w1::MinAccumulator, w2::MinAccumulator) = MinAccumulator(w1.weight + w2.weight)
Expand Down Expand Up @@ -137,23 +137,19 @@ mutable struct AvgDegStats <:DegreeStats
avg_out::Float64
end

function AvgDegStats(g::DataGraph, edges::Vector{Tuple{NodeId, NodeId, Bool}})
function AvgDegStats(g::DataGraph, edges::Vector{Tuple{NodeId, NodeId, Bool}}, color_size::Int)
length(edges) == 0 && return AvgDegStats(0,0)
in_counter = counter(NodeId)
out_counter = counter(NodeId)
unique_nodes = Set()
for edge in edges
if edge[3]
inc!(out_counter, edge[1])
push!(unique_nodes, edge[1])
else
inc!(in_counter, edge[1])
push!(unique_nodes, edge[1])
end

end
avg_in = sum([x for x in values(in_counter)]; init=0)/length(unique_nodes)
avg_out = sum([x for x in values(out_counter)]; init=0)/length(unique_nodes)
avg_in = sum([x for x in values(in_counter)]; init=0)/color_size
avg_out = sum([x for x in values(out_counter)]; init=0)/color_size
return AvgDegStats(avg_in, avg_out)
end
get_in_deg_estimate(d::AvgDegStats) = d.avg_in
Expand All @@ -169,7 +165,7 @@ end

struct AvgAccumulator <:StatAccumulator
weight::Float64
AvgAccumulator(c::Float64) = new(c)
AvgAccumulator(c::Union{Float64, Int64}) = new(c)
end

get_count(w::AvgAccumulator) = w.weight
Expand All @@ -191,7 +187,7 @@ mutable struct MaxDegStats <:DegreeStats
max_out::Float64
end

function MaxDegStats(g::DataGraph, edges::Vector{Tuple{NodeId, NodeId, Bool}})
function MaxDegStats(g::DataGraph, edges::Vector{Tuple{NodeId, NodeId, Bool}}, color_size::Int)
length(edges) == 0 && return MaxDegStats(0,0)
in_counter = counter(NodeId)
out_counter = counter(NodeId)
Expand All @@ -218,7 +214,7 @@ end

struct MaxAccumulator <:StatAccumulator
weight::Float64
MaxAccumulator(c::Float64) = new(c)
MaxAccumulator(c::Union{Float64, Int64}) = new(c)
end
get_count(w::MaxAccumulator) = w.weight
sum_colorings(w1::MaxAccumulator, w2::MaxAccumulator) = MaxAccumulator(w1.weight + w2.weight)
Expand Down
13 changes: 8 additions & 5 deletions Source/QuasiStableCardinalityEstimator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
end
deleteat!(current_query_nodes, nodeIdx)
partial_paths = zeros(Color, length(current_query_nodes), length(keys(new_partial_paths)))
partial_weights = fill(W(), length(keys(new_partial_paths)))
partial_weights = fill(W(0.0), length(keys(new_partial_paths)))

path_idx = 1
for path in keys(new_partial_paths)
Expand All @@ -43,7 +43,7 @@ function sample_paths(partial_paths::Matrix{Color}, partial_weights::Vector{W},
# if we want to sample more paths than there are existing nonzero paths,
# then just return the original partial paths
new_partial_paths = zeros(Color, size(partial_paths))
new_partial_weights = fill(W(), size(partial_weights))
new_partial_weights = fill(W(0.0), size(partial_weights))
new_path_idx = 1
for i in eachindex(partial_weights)
if get_count(partial_weights[i]) > 0
Expand All @@ -61,7 +61,7 @@ function sample_paths(partial_paths::Matrix{Color}, partial_weights::Vector{W},
end

# sum up all of the bounds
overall_bounds_sum::Float64 = 0.0
overall_bounds_sum = 0.0
for w in new_partial_weights
overall_bounds_sum += get_count(w)
end
Expand All @@ -75,7 +75,7 @@ function sample_paths(partial_paths::Matrix{Color}, partial_weights::Vector{W},
sample_indices::Vector{Int} = sample(1:length(new_partial_weights), sample_weights, num_samples; replace=false)

# sum up the sampled bounds
sampled_bounds_sum::Float64 = 0
sampled_bounds_sum = 0
for idx in sample_indices
sampled_bounds_sum += get_count(new_partial_weights[idx])
end
Expand All @@ -92,7 +92,7 @@ function sample_paths(partial_paths::Matrix{Color}, partial_weights::Vector{W},
else
1.0 / sample_weights[i]
end
sampled_partial_weights[i] = scale_colorings(new_partial_weights[idx], inverse_sampling_probability)
sampled_partial_weights[i] = scale_coloring(new_partial_weights[idx], inverse_sampling_probability)
end
return sampled_partial_paths, sampled_partial_weights
end
Expand Down Expand Up @@ -427,5 +427,8 @@ function get_cardinality_bounds(query::QueryGraph, summary::ColorSummary{DS}; ma
for w in partial_weights
final_estimate += get_count(w)
end
if final_estimate == 0
println("ISSUE")
end
return final_estimate
end

0 comments on commit a749ce0

Please sign in to comment.