From 6d3e46230a153ca24dda116cc0534a7e8891dd32 Mon Sep 17 00:00:00 2001 From: Vincent Jacques Date: Wed, 12 Jun 2024 07:22:14 +0000 Subject: [PATCH] Factorize --- .../accuracy-heuristic-on-cpu.cpp | 436 +++++------------- .../accuracy-heuristic-on-cpu.hpp | 26 +- 2 files changed, 136 insertions(+), 326 deletions(-) diff --git a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.cpp b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.cpp index 176d391e..917df10b 100644 --- a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.cpp +++ b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.cpp @@ -57,118 +57,101 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_then_high_pr const unsigned boundary_index, const unsigned criterion_index ) { - // Low profile - { - const unsigned lowest_destination_rank = - boundary_index == 0 ? - 0 : - learning_data.low_profile_ranks[model_index][boundary_index - 1][criterion_index]; - const unsigned highest_destination_rank = - boundary_index == learning_data.boundaries_count - 1 ? - learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]: - learning_data.low_profile_ranks[model_index][boundary_index + 1][criterion_index]; - - assert(lowest_destination_rank <= highest_destination_rank); - if (lowest_destination_rank == highest_destination_rank) { - assert(learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] == lowest_destination_rank); - } else { - unsigned best_destination_rank = learning_data.low_profile_ranks[model_index][boundary_index][criterion_index]; - float best_desirability = Desirability().value(); - - if (highest_destination_rank - lowest_destination_rank >= max_destinations_count) { - // We could try uniformly spread-out destinations instead of uniform random ones - for (unsigned destination_index = 0; destination_index != max_destinations_count; ++destination_index) { - const unsigned destination_rank = std::uniform_int_distribution(lowest_destination_rank, highest_destination_rank)(learning_data.urbgs[model_index]); - const float desirability = compute_move_desirability_for_low_profile_first( - model_index, - boundary_index, - criterion_index, - destination_rank).value(); - // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) - if (desirability > best_desirability) { - best_desirability = desirability; - best_destination_rank = destination_rank; - } - } - } else { - for (unsigned destination_rank = lowest_destination_rank; destination_rank <= highest_destination_rank; ++destination_rank) { - const float desirability = compute_move_desirability_for_low_profile_first( - model_index, - boundary_index, - criterion_index, - destination_rank).value(); - // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) - if (desirability > best_desirability) { - best_desirability = desirability; - best_destination_rank = destination_rank; - } - } - } + improve_low_profile( + model_index, + boundary_index, + criterion_index, + boundary_index == 0 ? + 0 : + learning_data.low_profile_ranks[model_index][boundary_index - 1][criterion_index], + boundary_index == learning_data.boundaries_count - 1 ? + learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]: + learning_data.low_profile_ranks[model_index][boundary_index + 1][criterion_index] + ); + + improve_high_profile( + model_index, + boundary_index, + criterion_index, + boundary_index == learning_data.boundaries_count - 1 ? + learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] : + learning_data.high_profile_ranks[model_index][boundary_index + 1][criterion_index], + boundary_index == 0 ? + learning_data.values_counts[criterion_index] - 1 : + learning_data.high_profile_ranks[model_index][boundary_index - 1][criterion_index] + ); +} - // @todo(Project management, later) Desirability can be as high as 2. The [0, 1] interval is a weird choice. - if (std::uniform_real_distribution(0, 1)(learning_data.urbgs[model_index]) <= best_desirability) { - learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] = best_destination_rank; - } - } - } +void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_only( + const unsigned model_index, + const unsigned boundary_index, + const unsigned criterion_index +) { + improve_low_profile( + model_index, + boundary_index, + criterion_index, + boundary_index == 0 ? + 0 : + learning_data.low_profile_ranks[model_index][boundary_index - 1][criterion_index], + boundary_index == learning_data.boundaries_count - 1 ? + learning_data.values_counts[criterion_index] - 1 : + learning_data.low_profile_ranks[model_index][boundary_index + 1][criterion_index] + ); +} - // High profile - { - const unsigned lowest_destination_rank = - boundary_index == learning_data.boundaries_count - 1 ? - learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] : - learning_data.high_profile_ranks[model_index][boundary_index + 1][criterion_index]; - const unsigned highest_destination_rank = - boundary_index == 0 ? - learning_data.values_counts[criterion_index] - 1 : - learning_data.high_profile_ranks[model_index][boundary_index - 1][criterion_index]; - - assert(lowest_destination_rank <= highest_destination_rank); - if (lowest_destination_rank == highest_destination_rank) { - assert(learning_data.high_profile_ranks[model_index][boundary_index][criterion_index] == lowest_destination_rank); - } else { - unsigned best_destination_rank = learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]; - float best_desirability = Desirability().value(); - - if (highest_destination_rank - lowest_destination_rank >= max_destinations_count) { - // We could try uniformly spread-out destinations instead of uniform random ones - for (unsigned destination_index = 0; destination_index != max_destinations_count; ++destination_index) { - const unsigned destination_rank = std::uniform_int_distribution(lowest_destination_rank, highest_destination_rank)(learning_data.urbgs[model_index]); - const float desirability = compute_move_desirability_for_high_profile_second( - model_index, - boundary_index, - criterion_index, - destination_rank).value(); - // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) - if (desirability > best_desirability) { - best_desirability = desirability; - best_destination_rank = destination_rank; - } +void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile( + const unsigned model_index, + const unsigned boundary_index, + const unsigned criterion_index, + const unsigned lowest_destination_rank, + const unsigned highest_destination_rank +) { + assert(lowest_destination_rank <= highest_destination_rank); + if (lowest_destination_rank == highest_destination_rank) { + assert(learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] == lowest_destination_rank); + } else { + unsigned best_destination_rank = learning_data.low_profile_ranks[model_index][boundary_index][criterion_index]; + float best_desirability = Desirability().value(); + + if (highest_destination_rank - lowest_destination_rank >= max_destinations_count) { + // We could try uniformly spread-out destinations instead of uniform random ones + for (unsigned destination_index = 0; destination_index != max_destinations_count; ++destination_index) { + const unsigned destination_rank = std::uniform_int_distribution(lowest_destination_rank, highest_destination_rank)(learning_data.urbgs[model_index]); + const float desirability = compute_move_desirability_for_low_profile( + model_index, + boundary_index, + criterion_index, + destination_rank).value(); + // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) + if (desirability > best_desirability) { + best_desirability = desirability; + best_destination_rank = destination_rank; } - } else { - for (unsigned destination_rank = lowest_destination_rank; destination_rank <= highest_destination_rank; ++destination_rank) { - const float desirability = compute_move_desirability_for_high_profile_second( - model_index, - boundary_index, - criterion_index, - destination_rank).value(); - // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) - if (desirability > best_desirability) { - best_desirability = desirability; - best_destination_rank = destination_rank; - } + } + } else { + for (unsigned destination_rank = lowest_destination_rank; destination_rank <= highest_destination_rank; ++destination_rank) { + const float desirability = compute_move_desirability_for_low_profile( + model_index, + boundary_index, + criterion_index, + destination_rank).value(); + // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) + if (desirability > best_desirability) { + best_desirability = desirability; + best_destination_rank = destination_rank; } } + } - // @todo(Project management, later) Desirability can be as high as 2. The [0, 1] interval is a weird choice. - if (std::uniform_real_distribution(0, 1)(learning_data.urbgs[model_index]) <= best_desirability) { - learning_data.high_profile_ranks[model_index][boundary_index][criterion_index] = best_destination_rank; - } + // @todo(Project management, later) Desirability can be as high as 2. The [0, 1] interval is a weird choice. + if (std::uniform_real_distribution(0, 1)(learning_data.urbgs[model_index]) <= best_desirability) { + learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] = best_destination_rank; } } } -Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirability_for_low_profile_first( +Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirability_for_low_profile( const unsigned model_index, const unsigned boundary_index, const unsigned criterion_index, @@ -177,7 +160,7 @@ Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirabilit Desirability d; for (unsigned alternative_index = 0; alternative_index != learning_data.alternatives_count; ++alternative_index) { - update_move_desirability_for_low_profile_first( + update_move_desirability_for_low_profile( model_index, boundary_index, criterion_index, @@ -189,7 +172,7 @@ Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirabilit return d; } -void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low_profile_first( +void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low_profile( const unsigned model_index, const unsigned boundary_index, const unsigned criterion_index, @@ -207,7 +190,7 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low // @todo(Project management, later) Factorize with get_assignment // (Same remark in accuracy-heuristic-on-gpu.cu) float accepted_weight = 0; - // There is a criterion parameter above, *and* a local criterion just here + // There is a 'criterion_index' parameter above, *and* a local 'crit_index' just here for (unsigned crit_index = 0; crit_index != learning_data.criteria_count; ++crit_index) { if (is_accepted(learning_data, model_index, boundary_index, crit_index, alternative_index)) { accepted_weight += learning_data.weights[model_index][crit_index]; @@ -317,186 +300,28 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low } } -Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirability_for_high_profile_second( - const unsigned model_index, - const unsigned boundary_index, - const unsigned criterion_index, - const unsigned destination_rank -) { - Desirability d; - - for (unsigned alternative_index = 0; alternative_index != learning_data.alternatives_count; ++alternative_index) { - update_move_desirability_for_high_profile_second( - model_index, - boundary_index, - criterion_index, - destination_rank, - alternative_index, - &d); - } - - return d; -} - -void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_high_profile_second( +void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_high_profile( const unsigned model_index, const unsigned boundary_index, const unsigned criterion_index, - const unsigned destination_rank, - const unsigned alternative_index, - Desirability* desirability -) { - const unsigned current_rank = learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]; - const float weight = learning_data.weights[model_index][criterion_index]; - - const unsigned alternative_rank = learning_data.performance_ranks[criterion_index][alternative_index]; - const unsigned learning_assignment = learning_data.assignments[alternative_index]; - const unsigned model_assignment = LearnMrsortByWeightsProfilesBreed::get_assignment(learning_data, model_index, alternative_index); - - // @todo(Project management, later) Factorize with get_assignment - // (Same remark in accuracy-heuristic-on-gpu.cu) - float accepted_weight = 0; - // There is a criterion parameter above, *and* a local criterion just here - for (unsigned crit_index = 0; crit_index != learning_data.criteria_count; ++crit_index) { - if (is_accepted(learning_data, model_index, boundary_index, crit_index, alternative_index)) { - accepted_weight += learning_data.weights[model_index][crit_index]; - } - } - - // These imbricated conditionals could be factorized, but this form has the benefit - // of being a direct translation of the top of page 78 of Sobrie's thesis. - // Correspondance: - // - learning_assignment: bottom index of A* - // - model_assignment: top index of A* - // - boundary_index: h - // - destination_value: b_j +/- \delta - // - current_value: b_j - // - alternative_value: a_j - // - accepted_weight: \sigma - // - weight: w_j - // - 1: \lambda - if (destination_rank < current_rank) { - if ( - learning_assignment == boundary_index - && model_assignment == boundary_index + 1 - && destination_rank < alternative_rank - && alternative_rank <= current_rank - && accepted_weight - weight < 1 - ) { - ++desirability->v; - } - if ( - learning_assignment == boundary_index - && model_assignment == boundary_index + 1 - && destination_rank < alternative_rank - && alternative_rank <= current_rank - && accepted_weight - weight >= 1 - ) { - ++desirability->w; - } - if ( - learning_assignment == boundary_index + 1 - && model_assignment == boundary_index + 1 - && destination_rank < alternative_rank - && alternative_rank <= current_rank - && accepted_weight - weight < 1 - ) { - ++desirability->q; - } - if ( - learning_assignment == boundary_index + 1 - && model_assignment == boundary_index - && destination_rank < alternative_rank - && alternative_rank <= current_rank - ) { - ++desirability->r; - } - if ( - learning_assignment < boundary_index - && model_assignment > boundary_index - && destination_rank < alternative_rank - && alternative_rank <= current_rank - ) { - ++desirability->t; - } - } else { - if ( - learning_assignment == boundary_index + 1 - && model_assignment == boundary_index - && alternative_rank < destination_rank - && current_rank < alternative_rank - && accepted_weight + weight >= 1 - ) { - ++desirability->v; - } - if ( - learning_assignment == boundary_index + 1 - && model_assignment == boundary_index - && alternative_rank < destination_rank - && current_rank < alternative_rank - && accepted_weight + weight < 1 - ) { - ++desirability->w; - } - if ( - learning_assignment == boundary_index - && model_assignment == boundary_index - && alternative_rank < destination_rank - && current_rank < alternative_rank - && accepted_weight + weight >= 1 - ) { - ++desirability->q; - } - if ( - learning_assignment == boundary_index - && model_assignment == boundary_index + 1 - && alternative_rank <= destination_rank - && current_rank < alternative_rank - ) { - ++desirability->r; - } - if ( - learning_assignment > boundary_index + 1 - && model_assignment < boundary_index + 1 - && alternative_rank < destination_rank - && current_rank <= alternative_rank - ) { - ++desirability->t; - } - } -} - -void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_only( - const unsigned model_index, - const unsigned boundary_index, - const unsigned criterion_index + const unsigned lowest_destination_rank, + const unsigned highest_destination_rank ) { - const unsigned lowest_destination_rank = - boundary_index == 0 ? - 0 : - learning_data.low_profile_ranks[model_index][boundary_index - 1][criterion_index]; - const unsigned highest_destination_rank = - boundary_index == learning_data.boundaries_count - 1 ? - learning_data.values_counts[criterion_index] - 1 : - learning_data.low_profile_ranks[model_index][boundary_index + 1][criterion_index]; - assert(lowest_destination_rank <= highest_destination_rank); if (lowest_destination_rank == highest_destination_rank) { - assert(learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] == lowest_destination_rank); + assert(learning_data.high_profile_ranks[model_index][boundary_index][criterion_index] == lowest_destination_rank); } else { - unsigned best_destination_rank = learning_data.low_profile_ranks[model_index][boundary_index][criterion_index]; + unsigned best_destination_rank = learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]; float best_desirability = Desirability().value(); if (highest_destination_rank - lowest_destination_rank >= max_destinations_count) { - // We could try uniformly spread-out destinations instead of uniform random ones for (unsigned destination_index = 0; destination_index != max_destinations_count; ++destination_index) { const unsigned destination_rank = std::uniform_int_distribution(lowest_destination_rank, highest_destination_rank)(learning_data.urbgs[model_index]); - const float desirability = compute_move_desirability_for_low_profile_only( + const float desirability = compute_move_desirability_for_high_profile( model_index, boundary_index, criterion_index, destination_rank).value(); - // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) if (desirability > best_desirability) { best_desirability = desirability; best_destination_rank = destination_rank; @@ -504,12 +329,11 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_only( } } else { for (unsigned destination_rank = lowest_destination_rank; destination_rank <= highest_destination_rank; ++destination_rank) { - const float desirability = compute_move_desirability_for_low_profile_only( + const float desirability = compute_move_desirability_for_high_profile( model_index, boundary_index, criterion_index, destination_rank).value(); - // Single-key reduce (divide and conquer?) (atomic compare-and-swap?) if (desirability > best_desirability) { best_desirability = desirability; best_destination_rank = destination_rank; @@ -517,14 +341,13 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_only( } } - // @todo(Project management, later) Desirability can be as high as 2. The [0, 1] interval is a weird choice. if (std::uniform_real_distribution(0, 1)(learning_data.urbgs[model_index]) <= best_desirability) { - learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] = best_destination_rank; + learning_data.high_profile_ranks[model_index][boundary_index][criterion_index] = best_destination_rank; } } } -Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirability_for_low_profile_only( +Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirability_for_high_profile( const unsigned model_index, const unsigned boundary_index, const unsigned criterion_index, @@ -533,7 +356,7 @@ Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirabilit Desirability d; for (unsigned alternative_index = 0; alternative_index != learning_data.alternatives_count; ++alternative_index) { - update_move_desirability_for_low_profile_only( + update_move_desirability_for_high_profile( model_index, boundary_index, criterion_index, @@ -545,7 +368,7 @@ Desirability ImproveProfilesWithAccuracyHeuristicOnCpu::compute_move_desirabilit return d; } -void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low_profile_only( +void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_high_profile( const unsigned model_index, const unsigned boundary_index, const unsigned criterion_index, @@ -553,41 +376,28 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low const unsigned alternative_index, Desirability* desirability ) { - const unsigned current_rank = learning_data.low_profile_ranks[model_index][boundary_index][criterion_index]; + const unsigned current_rank = learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]; const float weight = learning_data.weights[model_index][criterion_index]; const unsigned alternative_rank = learning_data.performance_ranks[criterion_index][alternative_index]; const unsigned learning_assignment = learning_data.assignments[alternative_index]; const unsigned model_assignment = LearnMrsortByWeightsProfilesBreed::get_assignment(learning_data, model_index, alternative_index); - // @todo(Project management, later) Factorize with get_assignment - // (Same remark in accuracy-heuristic-on-gpu.cu) float accepted_weight = 0; - // There is a criterion parameter above, *and* a local criterion just here + // There is a 'criterion_index' parameter above, *and* a local 'crit_index' just here for (unsigned crit_index = 0; crit_index != learning_data.criteria_count; ++crit_index) { if (is_accepted(learning_data, model_index, boundary_index, crit_index, alternative_index)) { accepted_weight += learning_data.weights[model_index][crit_index]; } } - // These imbricated conditionals could be factorized, but this form has the benefit - // of being a direct translation of the top of page 78 of Sobrie's thesis. - // Correspondance: - // - learning_assignment: bottom index of A* - // - model_assignment: top index of A* - // - boundary_index: h - // - destination_value: b_j +/- \delta - // - current_value: b_j - // - alternative_value: a_j - // - accepted_weight: \sigma - // - weight: w_j - // - 1: \lambda - if (destination_rank > current_rank) { + // Similar to 'update_move_desirability_for_low_profile' but inequalities involving 'destination_rank' and/or 'current_rank' are reversed + if (destination_rank < current_rank) { if ( learning_assignment == boundary_index && model_assignment == boundary_index + 1 - && destination_rank > alternative_rank - && alternative_rank >= current_rank + && destination_rank < alternative_rank + && alternative_rank <= current_rank && accepted_weight - weight < 1 ) { ++desirability->v; @@ -595,8 +405,8 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low if ( learning_assignment == boundary_index && model_assignment == boundary_index + 1 - && destination_rank > alternative_rank - && alternative_rank >= current_rank + && destination_rank < alternative_rank + && alternative_rank <= current_rank && accepted_weight - weight >= 1 ) { ++desirability->w; @@ -604,8 +414,8 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low if ( learning_assignment == boundary_index + 1 && model_assignment == boundary_index + 1 - && destination_rank > alternative_rank - && alternative_rank >= current_rank + && destination_rank < alternative_rank + && alternative_rank <= current_rank && accepted_weight - weight < 1 ) { ++desirability->q; @@ -613,16 +423,16 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low if ( learning_assignment == boundary_index + 1 && model_assignment == boundary_index - && destination_rank > alternative_rank - && alternative_rank >= current_rank + && destination_rank < alternative_rank + && alternative_rank <= current_rank ) { ++desirability->r; } if ( learning_assignment < boundary_index && model_assignment > boundary_index - && destination_rank > alternative_rank - && alternative_rank >= current_rank + && destination_rank < alternative_rank + && alternative_rank <= current_rank ) { ++desirability->t; } @@ -630,8 +440,8 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low if ( learning_assignment == boundary_index + 1 && model_assignment == boundary_index - && alternative_rank > destination_rank - && current_rank > alternative_rank + && alternative_rank < destination_rank + && current_rank < alternative_rank && accepted_weight + weight >= 1 ) { ++desirability->v; @@ -639,8 +449,8 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low if ( learning_assignment == boundary_index + 1 && model_assignment == boundary_index - && alternative_rank > destination_rank - && current_rank > alternative_rank + && alternative_rank < destination_rank + && current_rank < alternative_rank && accepted_weight + weight < 1 ) { ++desirability->w; @@ -648,8 +458,8 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low if ( learning_assignment == boundary_index && model_assignment == boundary_index - && alternative_rank > destination_rank - && current_rank > alternative_rank + && alternative_rank < destination_rank + && current_rank < alternative_rank && accepted_weight + weight >= 1 ) { ++desirability->q; @@ -657,16 +467,16 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_low if ( learning_assignment == boundary_index && model_assignment == boundary_index + 1 - && alternative_rank >= destination_rank - && current_rank > alternative_rank + && alternative_rank <= destination_rank + && current_rank < alternative_rank ) { ++desirability->r; } if ( learning_assignment > boundary_index + 1 && model_assignment < boundary_index + 1 - && alternative_rank > destination_rank - && current_rank >= alternative_rank + && alternative_rank < destination_rank + && current_rank <= alternative_rank ) { ++desirability->t; } diff --git a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.hpp b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.hpp index 23e9c585..62936e38 100644 --- a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.hpp +++ b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-cpu.hpp @@ -31,30 +31,28 @@ class ImproveProfilesWithAccuracyHeuristicOnCpu : public LearnMrsortByWeightsPro unsigned criterion_index ); - Desirability compute_move_desirability_for_low_profile_first( + void improve_low_profile_only( unsigned model_index, unsigned profile_index, - unsigned criterion_index, - unsigned destination_rank + unsigned criterion_index ); - void update_move_desirability_for_low_profile_first( + void improve_low_profile( unsigned model_index, unsigned profile_index, unsigned criterion_index, - unsigned destination_rank, - unsigned alternative_index, - Desirability* desirability + unsigned lowest_destination_rank, + unsigned highest_destination_rank ); - Desirability compute_move_desirability_for_high_profile_second( + Desirability compute_move_desirability_for_low_profile( unsigned model_index, unsigned profile_index, unsigned criterion_index, unsigned destination_rank ); - void update_move_desirability_for_high_profile_second( + void update_move_desirability_for_low_profile( unsigned model_index, unsigned profile_index, unsigned criterion_index, @@ -63,20 +61,22 @@ class ImproveProfilesWithAccuracyHeuristicOnCpu : public LearnMrsortByWeightsPro Desirability* desirability ); - void improve_low_profile_only( + void improve_high_profile( unsigned model_index, unsigned profile_index, - unsigned criterion_index + unsigned criterion_index, + unsigned lowest_destination_rank, + unsigned highest_destination_rank ); - Desirability compute_move_desirability_for_low_profile_only( + Desirability compute_move_desirability_for_high_profile( unsigned model_index, unsigned profile_index, unsigned criterion_index, unsigned destination_rank ); - void update_move_desirability_for_low_profile_only( + void update_move_desirability_for_high_profile( unsigned model_index, unsigned profile_index, unsigned criterion_index,