Skip to content

Commit b30d884

Browse files
committed
support for ternary
1 parent 91bc36b commit b30d884

8 files changed

Lines changed: 43 additions & 9 deletions

File tree

mt-kahypar/application/mt_kahypar.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,16 @@ int main(int argc, char* argv[]) {
125125
// Read Frequencies
126126
vec<EdgeMetadata> edge_metadata;
127127
if ( context.partition.frequencies_filename != "" ) {
128-
edge_metadata = io::getEdgeMetadataFromFile(hypergraph, context.partition.frequencies_filename, context.coarsening.rating.guiding_binary_treshold);
128+
edge_metadata = io::getEdgeMetadataFromFile(hypergraph, context.partition.frequencies_filename,
129+
context.coarsening.rating.guiding_binary_treshold,
130+
context.coarsening.rating.guiding_ternary_treshold,
131+
context.coarsening.rating.guiding_ternary_value);
129132
} else if ( context.partition.frequencies_default_file ) {
130133
std::string frequencies_file = context.partition.graph_filename + ".freq.csv";
131-
edge_metadata = io::getEdgeMetadataFromFile(hypergraph, frequencies_file, context.coarsening.rating.guiding_binary_treshold);
134+
edge_metadata = io::getEdgeMetadataFromFile(hypergraph, frequencies_file,
135+
context.coarsening.rating.guiding_binary_treshold,
136+
context.coarsening.rating.guiding_ternary_treshold,
137+
context.coarsening.rating.guiding_ternary_value);
132138
}
133139

134140
if ( context.partition.fixed_vertex_filename != "" ) {

mt-kahypar/io/command_line_options.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ namespace mt_kahypar {
378378
po::value<double>(&context.coarsening.rating.guiding_binary_treshold)->value_name(
379379
"<double>")->default_value(-1.0),
380380
"Binary treshold for guided coarsening (e.g. by ML with classification).")
381+
("c-guiding-ternary-threshold",
382+
po::value<double>(&context.coarsening.rating.guiding_ternary_treshold)->value_name(
383+
"<double>")->default_value(-1.0),
384+
"Ternary treshold for guided coarsening (e.g. by ML with classification).")
385+
("c-guiding-ternary-value",
386+
po::value<double>(&context.coarsening.rating.guiding_ternary_value)->value_name(
387+
"<double>")->default_value(-1.0),
388+
"Value used as ternary between 0 and 1 when using ternary threshold.")
381389
("c-guiding-threshold-max",
382390
po::value<double>(&context.coarsening.rating.guiding_treshold_max)->value_name(
383391
"<double>")->default_value(0.8),

mt-kahypar/io/hypergraph_factory.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,11 @@ vec<EdgeMetadata> getEdgeMetadata(const Hypergraph& hypergraph,
293293

294294
vec<EdgeMetadata> getEdgeMetadataFromFile(mt_kahypar_hypergraph_t hypergraph,
295295
const std::string& filename,
296-
double binary_threshold) {
296+
double binary_threshold,
297+
double ternary_threshold,
298+
double ternary_value) {
297299
ds::DynamicSparseMap<__uint128_t, float> frequencies;
298-
io::readFrequencyFile(filename, frequencies, binary_threshold);
300+
io::readFrequencyFile(filename, frequencies, binary_threshold, ternary_threshold, ternary_value);
299301
switch ( hypergraph.type ) {
300302
// case STATIC_HYPERGRAPH:
301303
// return getEdgeMetadata(utils::cast<ds::StaticHypergraph>(hypergraph), frequencies);

mt-kahypar/io/hypergraph_factory.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ void removeFixedVertices(mt_kahypar_hypergraph_t hypergraph);
6363

6464
vec<EdgeMetadata> getEdgeMetadataFromFile(mt_kahypar_hypergraph_t hypergraph,
6565
const std::string& filename,
66-
double binary_threshold);
66+
double binary_threshold,
67+
double ternary_threshold,
68+
double ternary_value);
6769

6870
} // namespace io
6971
} // namespace mt_kahypar

mt-kahypar/io/hypergraph_io.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,11 @@ namespace mt_kahypar::io {
681681
}
682682
}
683683

684-
void readFrequencyFile(const std::string& filename, ds::DynamicSparseMap<__uint128_t, float>& frequencies, double binary_threshold) {
684+
void readFrequencyFile(const std::string& filename,
685+
ds::DynamicSparseMap<__uint128_t, float>& frequencies,
686+
double binary_threshold,
687+
double ternary_threshold,
688+
double ternary_value) {
685689
ALWAYS_ASSERT(!filename.empty(), "No filename for frequency file specified");
686690
std::ifstream file(filename);
687691
if (file) {
@@ -716,7 +720,13 @@ namespace mt_kahypar::io {
716720
ALWAYS_ASSERT(!frequencies.contains(key) && f <= max);
717721
frequencies[key] = f / static_cast<double>(max);
718722
if (binary_threshold >= 0) {
719-
frequencies[key] = frequencies[key] > binary_threshold ? 1.0 : 0.0;
723+
if (ternary_threshold >= 0) {
724+
ALWAYS_ASSERT(binary_threshold < ternary_threshold && ternary_threshold < 1);
725+
const double mid = ternary_value >= 0 ? ternary_value : ternary_threshold;
726+
frequencies[key] = frequencies[key] > binary_threshold ? (frequencies[key] > ternary_threshold ? 1.0 : mid) : 0.0;
727+
} else {
728+
frequencies[key] = frequencies[key] > binary_threshold ? 1.0 : 0.0;
729+
}
720730
}
721731
}
722732
file.close();

mt-kahypar/io/hypergraph_io.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ namespace io {
5959
void readPartitionFile(const std::string& filename, HypernodeID num_nodes, std::vector<PartitionID>& partition);
6060
void readPartitionFile(const std::string& filename, HypernodeID num_nodes, PartitionID* partition);
6161

62-
void readFrequencyFile(const std::string& filename, ds::DynamicSparseMap<__uint128_t, float>& frequencies, double binary_threshold);
62+
void readFrequencyFile(const std::string& filename,
63+
ds::DynamicSparseMap<__uint128_t, float>& frequencies,
64+
double binary_threshold,
65+
double ternary_threshold,
66+
double ternary_value);
6367

6468
inline __uint128_t hashedEdgeKey(const utils_tm::hash_tm::murmur2_hash& hasher, HypernodeID u, HypernodeID v) {
6569
// this is a bit ugly, but we need it to avoid collisions (since we don't have a good hashmap with a non-trivial hash function)

mt-kahypar/partition/coarsening/policies/rating_degree_similarity_policy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class GuidedCoarseningPolicy final : public kahypar::meta::PolicyBase {
364364
sum += value;
365365
break;
366366
case GuidedEdgeAccumulation::quadratic:
367-
sum += value / static_cast<double>(edge_weight) * value;
367+
sum += value == 0 ? 0 : value / static_cast<double>(edge_weight) * value;
368368
break;
369369
case GuidedEdgeAccumulation::max:
370370
sum = std::max(sum, value / static_cast<float>(edge_weight));

mt-kahypar/partition/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ struct RatingParameters {
122122
double guiding_treshold = 1.0;
123123
double guiding_treshold_max = 1.0;
124124
double guiding_binary_treshold = -1.0;
125+
double guiding_ternary_treshold = -1.0;
126+
double guiding_ternary_value = -1.0;
125127
size_t num_guided_subrounds = 1;
126128
size_t guided_coarsening_levels = std::numeric_limits<size_t>::max();
127129
bool consider_edges_deleted = false;

0 commit comments

Comments
 (0)