Skip to content

Commit

Permalink
Clean up naming conventions in algorithms.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurp committed Apr 22, 2021
1 parent 7ebd234 commit 81b8738
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,31 @@ class LocalClusteringCoefficientPlan : public Plan {
};

static const Relabeling kDefaultRelabeling = kAutoRelabel;
static const bool kDefaultEdgeSorted = false;
static const bool kDefaultEdgesSorted = false;

private:
Algorithm algorithm_;
Relabeling relabeling_;
bool edges_sorted_;
Relabeling relabeling_;

LocalClusteringCoefficientPlan(
Architecture architecture, Algorithm algorithm, bool edges_sorted,
Relabeling relabeling)
: Plan(architecture),
algorithm_(algorithm),
relabeling_(relabeling),
edges_sorted_(edges_sorted) {}
edges_sorted_(edges_sorted),
relabeling_(relabeling) {}

public:
LocalClusteringCoefficientPlan()
: LocalClusteringCoefficientPlan{
kCPU, kOrderedCountPerThread, kDefaultEdgeSorted,
kCPU, kOrderedCountPerThread, kDefaultEdgesSorted,
kDefaultRelabeling} {}

Algorithm algorithm() const { return algorithm_; }
// TODO(amp): These parameters should be documented.
Relabeling relabeling() const { return relabeling_; }
bool edges_sorted() const { return edges_sorted_; }
Relabeling relabeling() const { return relabeling_; }

/**
* An ordered count algorithm that sorts the nodes by degree before
Expand All @@ -58,14 +58,14 @@ class LocalClusteringCoefficientPlan : public Plan {
* @param edges_sorted Are the edges of the graph already sorted.
* @param relabeling Should the algorithm relabel the nodes.
*/
static LocalClusteringCoefficientPlan LocalClusteringCoefficientAtomics(
bool edges_sorted = kDefaultEdgeSorted,
static LocalClusteringCoefficientPlan OrderedCountAtomics(
bool edges_sorted = kDefaultEdgesSorted,
Relabeling relabeling = kDefaultRelabeling) {
return {kCPU, kOrderedCountAtomics, edges_sorted, relabeling};
}

static LocalClusteringCoefficientPlan LocalClusteringCoefficientPerThread(
bool edges_sorted = kDefaultEdgeSorted,
static LocalClusteringCoefficientPlan OrderedCountPerThread(
bool edges_sorted = kDefaultEdgesSorted,
Relabeling relabeling = kDefaultRelabeling) {
return {kCPU, kOrderedCountPerThread, edges_sorted, relabeling};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,20 @@ class LouvainClusteringPlan : public Plan {
kDoAll,
};

static const bool kEnableVF = false;
static constexpr double kModularityThresholdPerRound = 0.01;
static constexpr double kModularityThresholdTotal = 0.01;
static const uint32_t kMaxIterations = 10;
static const uint32_t kMinGraphSize = 100;
static const bool kDefaultEnableVF = false;
static constexpr double kDefaultModularityThresholdPerRound = 0.01;
static constexpr double kDefaultModularityThresholdTotal = 0.01;
static const uint32_t kDefaultMaxIterations = 10;
static const uint32_t kDefaultMinGraphSize = 100;

// Don't allow people to directly construct these, so as to have only one
// consistent way to configure.
private:
Algorithm algorithm_;
//Flag to enable vertex following optimization.
bool enable_vf_;
//Threshold for modularity gain per round.
double modularity_threshold_per_round_;
//Threshold for overall modularity gain.
double modularity_threshold_total_;
//Maximum number of iterations to execute.
uint32_t max_iterations_;
//Minimum coarsened graph size
uint32_t min_graph_size_;

LouvainClusteringPlan(
Expand All @@ -55,30 +50,35 @@ class LouvainClusteringPlan : public Plan {
: LouvainClusteringPlan{
kCPU,
kDoAll,
kEnableVF,
kModularityThresholdPerRound,
kModularityThresholdTotal,
kMaxIterations,
kMinGraphSize} {}
kDefaultEnableVF,
kDefaultModularityThresholdPerRound,
kDefaultModularityThresholdTotal,
kDefaultMaxIterations,
kDefaultMinGraphSize} {}

Algorithm algorithm() const { return algorithm_; }
// TODO(amp): These parameters should be documented.
bool is_enable_vf() const { return enable_vf_; }
/// Enable vertex following optimization
bool enable_vf() const { return enable_vf_; }
/// Threshold for modularity gain per round.
double modularity_threshold_per_round() const {
return modularity_threshold_per_round_;
}
/// Threshold for overall modularity gain.
double modularity_threshold_total() const {
return modularity_threshold_total_;
}
/// Maximum number of iterations to execute.
uint32_t max_iterations() const { return max_iterations_; }
/// Minimum coarsened graph size
uint32_t min_graph_size() const { return min_graph_size_; }

static LouvainClusteringPlan DoAll(
bool enable_vf = kEnableVF,
double modularity_threshold_per_round = kModularityThresholdPerRound,
double modularity_threshold_total = kModularityThresholdTotal,
uint32_t max_iterations = kMaxIterations,
uint32_t min_graph_size = kMinGraphSize) {
bool enable_vf = kDefaultEnableVF,
double modularity_threshold_per_round =
kDefaultModularityThresholdPerRound,
double modularity_threshold_total = kDefaultModularityThresholdTotal,
uint32_t max_iterations = kDefaultMaxIterations,
uint32_t min_graph_size = kDefaultMinGraphSize) {
return {
kCPU,
kDoAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ struct LouvainClusteringImplementation
/*
* Vertex following optimization
*/
if (plan.is_enable_vf()) {
if (plan.enable_vf()) {
Base::VertexFollowing(&graph_curr); // Find nodes that follow other nodes

uint64_t num_unique_clusters =
Expand Down Expand Up @@ -314,7 +314,7 @@ struct LouvainClusteringImplementation

if (iter < plan.max_iterations() &&
(curr_mod - prev_mod) > plan.modularity_threshold_total()) {
if (!plan.is_enable_vf() && phase == 1) {
if (!plan.enable_vf() && phase == 1) {
KATANA_LOG_DEBUG_ASSERT(num_nodes_orig == graph_curr.num_nodes());
katana::do_all(katana::iterate(graph_curr), [&](GNode n) {
clusters_orig[n] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ main(int argc, char** argv) {

switch (algo) {
case LocalClusteringCoefficientPlan::kOrderedCountAtomics:
plan = LocalClusteringCoefficientPlan::LocalClusteringCoefficientAtomics(
relabeling_flag);
plan = LocalClusteringCoefficientPlan::OrderedCountAtomics(relabeling_flag);
break;
case LocalClusteringCoefficientPlan::kOrderedCountPerThread:
plan = LocalClusteringCoefficientPlan::LocalClusteringCoefficientPerThread(
relabeling_flag);
plan =
LocalClusteringCoefficientPlan::OrderedCountPerThread(relabeling_flag);
break;
default:
std::cerr << "Unknown algo: " << algo << "\n";
Expand Down

0 comments on commit 81b8738

Please sign in to comment.