diff --git a/doc-sources/reference/lincs.rst b/doc-sources/reference/lincs.rst index f9af061e..2902fd49 100644 --- a/doc-sources/reference/lincs.rst +++ b/doc-sources/reference/lincs.rst @@ -865,10 +865,15 @@ Indexed by ``[model_index][boundary_index][criterion_index]``. The current rank of each low profile, for each model and criterion. + .. property:: high_profile_rank_indexes + :type: list[unsigned] + + Indexed by ``[criterion_index]``. The index in ``high_profile_ranks``, for each single-peaked criterion. + .. property:: high_profile_ranks :type: list[list[list[int]]] - Indexed by ``[model_index][boundary_index][criterion_index]``. The current rank of each high profile, for each model and criterion. + Indexed by ``[model_index][boundary_index][high_profile_rank_indexes[criterion_index]]``. The current rank of each high profile, for each model and single-peaked criterion. .. property:: accuracies :type: list[int] diff --git a/doc-sources/reference/lincs.yml b/doc-sources/reference/lincs.yml index 6dad2b5a..81834de1 100644 --- a/doc-sources/reference/lincs.yml +++ b/doc-sources/reference/lincs.yml @@ -360,6 +360,8 @@ children: type: list[list[int]] - name: low_profile_ranks type: list[list[list[int]]] + - name: high_profile_rank_indexes + type: list[unsigned] - name: high_profile_ranks type: list[list[list[int]]] - name: accuracies diff --git a/integration-tests/dir-all/liblincs.txt b/integration-tests/dir-all/liblincs.txt index 4a2ab858..daf3329d 100644 --- a/integration-tests/dir-all/liblincs.txt +++ b/integration-tests/dir-all/liblincs.txt @@ -204,6 +204,7 @@ liblincs: module criteria_count: property get_best_accuracy: instancemethod get_best_model: instancemethod + high_profile_rank_indexes: property high_profile_ranks: property iteration_index: property low_profile_ranks: property diff --git a/integration-tests/dir-all/lincs.txt b/integration-tests/dir-all/lincs.txt index ea066370..05960945 100644 --- a/integration-tests/dir-all/lincs.txt +++ b/integration-tests/dir-all/lincs.txt @@ -184,6 +184,7 @@ lincs: module criteria_count: property get_best_accuracy: instancemethod get_best_model: instancemethod + high_profile_rank_indexes: property high_profile_ranks: property iteration_index: property low_profile_ranks: property diff --git a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.cpp b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.cpp index 00ce25dd..37283720 100644 --- a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.cpp +++ b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.cpp @@ -26,7 +26,8 @@ LearnMrsortByWeightsProfilesBreed::LearningData::LearningData( model_indexes(models_count), accuracies(models_count, zeroed), low_profile_ranks(models_count, boundaries_count, criteria_count, uninitialized), - high_profile_ranks(models_count, boundaries_count, criteria_count, uninitialized), + high_profile_rank_indexes(criteria_count, uninitialized), + high_profile_ranks(models_count, boundaries_count, count_single_peaked_criteria(), uninitialized), weights(models_count, criteria_count, uninitialized) { CHRONE(); @@ -36,6 +37,25 @@ LearnMrsortByWeightsProfilesBreed::LearningData::LearningData( for (unsigned model_index = 0; model_index != models_count; ++model_index) { random_generators[model_index].seed(random_seed * (model_index + 1)); } + + unsigned count = 0; + for (unsigned criterion_index = 0; criterion_index != criteria_count; ++criterion_index) { + if (single_peaked[criterion_index]) { + high_profile_rank_indexes[criterion_index] = count; + ++count; + } + } + assert(high_profile_ranks.s0() == count); +} + +unsigned LearnMrsortByWeightsProfilesBreed::LearningData::count_single_peaked_criteria() const { + unsigned count = 0; + for (unsigned criterion_index = 0; criterion_index != criteria_count; ++criterion_index) { + if (single_peaked[criterion_index]) { + ++count; + } + } + return count; } Model LearnMrsortByWeightsProfilesBreed::LearningData::get_model(const unsigned model_index) const { @@ -57,8 +77,8 @@ Model LearnMrsortByWeightsProfilesBreed::LearningData::get_model(const unsigned boundary_profile.reserve(criteria_count); for (unsigned criterion_index = 0; criterion_index != criteria_count; ++criterion_index) { const unsigned low_profile_rank = low_profile_ranks[model_index][boundary_index][criterion_index]; - const unsigned high_profile_rank = high_profile_ranks[model_index][boundary_index][criterion_index]; if (single_peaked[criterion_index]) { + const unsigned high_profile_rank = high_profile_ranks[model_index][boundary_index][high_profile_rank_indexes[criterion_index]]; boundary_profile.push_back(std::make_pair(low_profile_rank, high_profile_rank)); } else { boundary_profile.push_back(low_profile_rank); @@ -176,7 +196,7 @@ bool LearnMrsortByWeightsProfilesBreed::is_accepted( const unsigned alternative_rank = learning_data.performance_ranks[criterion_index][alternative_index]; const unsigned low_profile_rank = learning_data.low_profile_ranks[model_index][boundary_index][criterion_index]; if (learning_data.single_peaked[criterion_index]) { - const unsigned high_profile_rank = learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]; + const unsigned high_profile_rank = learning_data.high_profile_ranks[model_index][boundary_index][learning_data.high_profile_rank_indexes[criterion_index]]; return low_profile_rank <= alternative_rank && alternative_rank <= high_profile_rank; } else { return low_profile_rank <= alternative_rank; diff --git a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.hpp b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.hpp index 9efed930..179f7155 100644 --- a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.hpp +++ b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed.hpp @@ -71,7 +71,8 @@ struct LearnMrsortByWeightsProfilesBreed::LearningData : public PreProcessedLear std::vector model_indexes; // [model_index_index]: this is a reordering of the models' indexes Array1D accuracies; // [model_index] Array3D low_profile_ranks; // [model_index][boundary_index][criterion_index] - Array3D high_profile_ranks; // [model_index][boundary_index][criterion_index] + Array1D high_profile_rank_indexes; // [criterion_index], meaningful only for single-peaked criteria (i.e. when single_peaked[criterion_index] is true) + Array3D high_profile_ranks; // [model_index][boundary_index][high_profile_rank_indexes[criterion_index]] Array2D weights; // [model_index][criterion_index] // @todo(Performance, later) Add models' ages @@ -86,6 +87,9 @@ struct LearnMrsortByWeightsProfilesBreed::LearningData : public PreProcessedLear bool model_is_correct(unsigned model_index) const; bool models_are_correct() const; #endif + + private: + unsigned count_single_peaked_criteria() const; }; struct LearnMrsortByWeightsProfilesBreed::ProfilesInitializationStrategy { 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 bee215c5..90ec7237 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,6 +57,8 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_then_high_pr const unsigned boundary_index, const unsigned criterion_index ) { + assert(learning_data.single_peaked[criterion_index]); + improve_low_profile( model_index, boundary_index, @@ -65,7 +67,7 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_then_high_pr 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.high_profile_ranks[model_index][boundary_index][learning_data.high_profile_rank_indexes[criterion_index]]: learning_data.low_profile_ranks[model_index][boundary_index + 1][criterion_index] ); @@ -75,10 +77,10 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_low_profile_then_high_pr 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], + learning_data.high_profile_ranks[model_index][boundary_index + 1][learning_data.high_profile_rank_indexes[criterion_index]], boundary_index == 0 ? learning_data.values_counts[criterion_index] - 1 : - learning_data.high_profile_ranks[model_index][boundary_index - 1][criterion_index] + learning_data.high_profile_ranks[model_index][boundary_index - 1][learning_data.high_profile_rank_indexes[criterion_index]] ); } @@ -307,11 +309,12 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_high_profile( const unsigned lowest_destination_rank, const unsigned highest_destination_rank ) { + assert(learning_data.single_peaked[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); + assert(learning_data.high_profile_ranks[model_index][boundary_index][learning_data.high_profile_rank_indexes[criterion_index]] == lowest_destination_rank); } else { - unsigned best_destination_rank = learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]; + unsigned best_destination_rank = learning_data.high_profile_ranks[model_index][boundary_index][learning_data.high_profile_rank_indexes[criterion_index]]; float best_desirability = Desirability().value(); if (highest_destination_rank - lowest_destination_rank >= max_destinations_count) { @@ -342,7 +345,7 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::improve_high_profile( } if (std::uniform_real_distribution(0, 1)(learning_data.random_generators[model_index]) <= best_desirability) { - learning_data.high_profile_ranks[model_index][boundary_index][criterion_index] = best_destination_rank; + learning_data.high_profile_ranks[model_index][boundary_index][learning_data.high_profile_rank_indexes[criterion_index]] = best_destination_rank; } } } @@ -376,7 +379,8 @@ void ImproveProfilesWithAccuracyHeuristicOnCpu::update_move_desirability_for_hig const unsigned alternative_index, Desirability* desirability ) { - const unsigned current_rank = learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]; + assert(learning_data.single_peaked[criterion_index]); + const unsigned current_rank = learning_data.high_profile_ranks[model_index][boundary_index][learning_data.high_profile_rank_indexes[criterion_index]]; const float weight = learning_data.weights[model_index][criterion_index]; const unsigned alternative_rank = learning_data.performance_ranks[criterion_index][alternative_index]; diff --git a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.cu b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.cu index d57353f1..8d7b4eac 100644 --- a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.cu +++ b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.cu @@ -16,6 +16,7 @@ bool is_accepted( const ArrayView2D performance_ranks, const ArrayView1D single_peaked, const ArrayView3D low_profile_ranks, + const ArrayView1D high_profile_rank_indexes, const ArrayView3D high_profile_ranks, const unsigned model_index, const unsigned boundary_index, @@ -25,7 +26,7 @@ bool is_accepted( const unsigned alternative_rank = performance_ranks[criterion_index][alternative_index]; const unsigned low_profile_rank = low_profile_ranks[model_index][boundary_index][criterion_index]; if (single_peaked[criterion_index]) { - const unsigned high_profile_rank = high_profile_ranks[model_index][boundary_index][criterion_index]; + const unsigned high_profile_rank = high_profile_ranks[model_index][boundary_index][high_profile_rank_indexes[criterion_index]]; return low_profile_rank <= alternative_rank && alternative_rank <= high_profile_rank; } else { return low_profile_rank <= alternative_rank; @@ -38,6 +39,7 @@ unsigned get_assignment( const ArrayView2D weights, const ArrayView1D single_peaked, const ArrayView3D low_profile_ranks, + const ArrayView1D high_profile_rank_indexes, const ArrayView3D high_profile_ranks, const unsigned model_index, const unsigned alternative_index @@ -52,7 +54,7 @@ unsigned get_assignment( const unsigned boundary_index = category_index - 1; float accepted_weight = 0; for (unsigned criterion_index = 0; criterion_index != criteria_count; ++criterion_index) { - if (is_accepted(performance_ranks, single_peaked, low_profile_ranks, high_profile_ranks, model_index, boundary_index, criterion_index, alternative_index)) { + if (is_accepted(performance_ranks, single_peaked, low_profile_ranks, high_profile_rank_indexes, high_profile_ranks, model_index, boundary_index, criterion_index, alternative_index)) { accepted_weight += weights[model_index][criterion_index]; } } @@ -70,6 +72,7 @@ void update_move_desirability_for_low_profile( const ArrayView2D weights, const ArrayView1D single_peaked, const ArrayView3D low_profile_ranks, + const ArrayView1D high_profile_rank_indexes, const ArrayView3D high_profile_ranks, const unsigned model_index, const unsigned boundary_index, @@ -91,6 +94,7 @@ void update_move_desirability_for_low_profile( weights, single_peaked, low_profile_ranks, + high_profile_rank_indexes, high_profile_ranks, model_index, alternative_index); @@ -98,7 +102,7 @@ void update_move_desirability_for_low_profile( float accepted_weight = 0; // There is a 'criterion_index' parameter above, *and* a local 'crit_index' just here for (unsigned crit_index = 0; crit_index != criteria_count; ++crit_index) { - if (is_accepted(performance_ranks, single_peaked, low_profile_ranks, high_profile_ranks, model_index, boundary_index, crit_index, alternative_index)) { + if (is_accepted(performance_ranks, single_peaked, low_profile_ranks, high_profile_rank_indexes, high_profile_ranks, model_index, boundary_index, crit_index, alternative_index)) { accepted_weight += weights[model_index][crit_index]; } } @@ -202,6 +206,7 @@ void compute_move_desirabilities_for_low_profile__kernel( const ArrayView2D weights, const ArrayView1D single_peaked, const ArrayView3D low_profile_ranks, + const ArrayView1D high_profile_rank_indexes, const ArrayView3D high_profile_ranks, const unsigned model_index, const unsigned boundary_index, @@ -223,6 +228,7 @@ void compute_move_desirabilities_for_low_profile__kernel( weights, single_peaked, low_profile_ranks, + high_profile_rank_indexes, high_profile_ranks, model_index, boundary_index, @@ -270,6 +276,7 @@ void update_move_desirability_for_high_profile( const ArrayView2D weights, const ArrayView1D single_peaked, const ArrayView3D low_profile_ranks, + const ArrayView1D high_profile_rank_indexes, const ArrayView3D high_profile_ranks, const unsigned model_index, const unsigned boundary_index, @@ -281,7 +288,7 @@ void update_move_desirability_for_high_profile( const unsigned alternatives_count = performance_ranks.s0(); const unsigned criteria_count = performance_ranks.s1(); - const unsigned current_rank = high_profile_ranks[model_index][boundary_index][criterion_index]; + const unsigned current_rank = high_profile_ranks[model_index][boundary_index][high_profile_rank_indexes[criterion_index]]; const float weight = weights[model_index][criterion_index]; const unsigned alternative_rank = performance_ranks[criterion_index][alternative_index]; @@ -291,6 +298,7 @@ void update_move_desirability_for_high_profile( weights, single_peaked, low_profile_ranks, + high_profile_rank_indexes, high_profile_ranks, model_index, alternative_index); @@ -298,7 +306,7 @@ void update_move_desirability_for_high_profile( float accepted_weight = 0; // There is a 'criterion_index' parameter above, *and* a local 'crit_index' just here for (unsigned crit_index = 0; crit_index != criteria_count; ++crit_index) { - if (is_accepted(performance_ranks, single_peaked, low_profile_ranks, high_profile_ranks, model_index, boundary_index, crit_index, alternative_index)) { + if (is_accepted(performance_ranks, single_peaked, low_profile_ranks, high_profile_rank_indexes, high_profile_ranks, model_index, boundary_index, crit_index, alternative_index)) { accepted_weight += weights[model_index][crit_index]; } } @@ -402,6 +410,7 @@ void compute_move_desirabilities_for_high_profile__kernel( const ArrayView2D weights, const ArrayView1D single_peaked, const ArrayView3D low_profile_ranks, + const ArrayView1D high_profile_rank_indexes, const ArrayView3D high_profile_ranks, const unsigned model_index, const unsigned boundary_index, @@ -423,6 +432,7 @@ void compute_move_desirabilities_for_high_profile__kernel( weights, single_peaked, low_profile_ranks, + high_profile_rank_indexes, high_profile_ranks, model_index, boundary_index, @@ -435,6 +445,7 @@ void compute_move_desirabilities_for_high_profile__kernel( __global__ void apply_best_move_for_high_profile__kernel( + const ArrayView1D high_profile_rank_indexes, const ArrayView3D high_profile_ranks, const unsigned model_index, const unsigned boundary_index, @@ -459,7 +470,7 @@ void apply_best_move_for_high_profile__kernel( } if (best_desirability >= desirability_threshold) { - high_profile_ranks[model_index][boundary_index][criterion_index] = best_destination_rank; + high_profile_ranks[model_index][boundary_index][high_profile_rank_indexes[criterion_index]] = best_destination_rank; } } @@ -473,7 +484,8 @@ ImproveProfilesWithAccuracyHeuristicOnGpu::GpuLearningData::GpuLearningData(cons single_peaked(host_learning_data.single_peaked.template clone_to()), weights(host_learning_data.models_count, host_learning_data.criteria_count, uninitialized), low_profile_ranks(host_learning_data.models_count, host_learning_data.boundaries_count, host_learning_data.criteria_count, uninitialized), - high_profile_ranks(host_learning_data.models_count, host_learning_data.boundaries_count, host_learning_data.criteria_count, uninitialized), + high_profile_rank_indexes(host_learning_data.high_profile_rank_indexes.template clone_to()), + high_profile_ranks(host_learning_data.models_count, host_learning_data.boundaries_count, host_learning_data.high_profile_ranks.s0(), uninitialized), desirabilities(host_learning_data.models_count, ImproveProfilesWithAccuracyHeuristicOnGpu::max_destinations_count, uninitialized), destination_ranks(host_learning_data.models_count, ImproveProfilesWithAccuracyHeuristicOnGpu::max_destinations_count, uninitialized) {} @@ -537,6 +549,8 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_low_profile_then_high_pr const unsigned boundary_index, const unsigned criterion_index ) { + assert(host_learning_data.single_peaked[criterion_index]); + improve_low_profile( model_index, boundary_index, @@ -545,7 +559,7 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_low_profile_then_high_pr 0 : host_learning_data.low_profile_ranks[model_index][boundary_index - 1][criterion_index], boundary_index == host_learning_data.boundaries_count - 1 ? - host_learning_data.high_profile_ranks[model_index][boundary_index][criterion_index]: + host_learning_data.high_profile_ranks[model_index][boundary_index][host_learning_data.high_profile_rank_indexes[criterion_index]]: host_learning_data.low_profile_ranks[model_index][boundary_index + 1][criterion_index] ); @@ -555,10 +569,10 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_low_profile_then_high_pr criterion_index, boundary_index == host_learning_data.boundaries_count - 1 ? host_learning_data.low_profile_ranks[model_index][boundary_index][criterion_index] : - host_learning_data.high_profile_ranks[model_index][boundary_index + 1][criterion_index], + host_learning_data.high_profile_ranks[model_index][boundary_index + 1][host_learning_data.high_profile_rank_indexes[criterion_index]], boundary_index == 0 ? host_learning_data.values_counts[criterion_index] - 1 : - host_learning_data.high_profile_ranks[model_index][boundary_index - 1][criterion_index] + host_learning_data.high_profile_ranks[model_index][boundary_index - 1][host_learning_data.high_profile_rank_indexes[criterion_index]] ); } @@ -616,6 +630,7 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_low_profile( gpu_learning_data.weights, gpu_learning_data.single_peaked, gpu_learning_data.low_profile_ranks, + gpu_learning_data.high_profile_rank_indexes, gpu_learning_data.high_profile_ranks, model_index, boundary_index, @@ -657,9 +672,10 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_high_profile( const unsigned lowest_destination_rank, const unsigned highest_destination_rank ) { + assert(host_learning_data.single_peaked[criterion_index]); assert(lowest_destination_rank <= highest_destination_rank); if (lowest_destination_rank == highest_destination_rank) { - assert(host_learning_data.high_profile_ranks[model_index][boundary_index][criterion_index] == lowest_destination_rank); + assert(host_learning_data.high_profile_ranks[model_index][boundary_index][host_learning_data.high_profile_rank_indexes[criterion_index]] == lowest_destination_rank); } else { Array1D host_destination_ranks(max_destinations_count, uninitialized); unsigned actual_destinations_count = 0; @@ -686,6 +702,7 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_high_profile( gpu_learning_data.weights, gpu_learning_data.single_peaked, gpu_learning_data.low_profile_ranks, + gpu_learning_data.high_profile_rank_indexes, gpu_learning_data.high_profile_ranks, model_index, boundary_index, @@ -696,6 +713,7 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_high_profile( check_last_cuda_error_sync_stream(cudaStreamDefault); apply_best_move_for_high_profile__kernel<<<1, 1>>>( + gpu_learning_data.high_profile_rank_indexes, ref(gpu_learning_data.high_profile_ranks), model_index, boundary_index, @@ -706,9 +724,11 @@ void ImproveProfilesWithAccuracyHeuristicOnGpu::improve_high_profile( std::uniform_real_distribution(0, 1)(host_learning_data.random_generators[model_index])); check_last_cuda_error_sync_stream(cudaStreamDefault); + assert(0 <= host_learning_data.high_profile_rank_indexes[criterion_index]); + assert(host_learning_data.high_profile_rank_indexes[criterion_index] < host_learning_data.high_profile_ranks.s0()); check_cuda_error(cudaMemcpy( - host_learning_data.high_profile_ranks[model_index][boundary_index].data() + criterion_index, - gpu_learning_data.high_profile_ranks[model_index][boundary_index].data() + criterion_index, + host_learning_data.high_profile_ranks[model_index][boundary_index].data() + host_learning_data.high_profile_rank_indexes[criterion_index], + gpu_learning_data.high_profile_ranks[model_index][boundary_index].data() + host_learning_data.high_profile_rank_indexes[criterion_index], 1 * sizeof(unsigned), cudaMemcpyDeviceToHost)); } diff --git a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.hpp b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.hpp index 46ac2a1a..8186a7be 100644 --- a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.hpp +++ b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/improve-profiles/accuracy-heuristic-on-gpu.hpp @@ -21,7 +21,8 @@ class ImproveProfilesWithAccuracyHeuristicOnGpu : public LearnMrsortByWeightsPro Array1D single_peaked; // [criterion_index] Array2D weights; // [criterion_index][model_index] Array3D low_profile_ranks; // [criterion_index][boundary_index][model_index] - Array3D high_profile_ranks; // [criterion_index][boundary_index][model_index] + Array1D high_profile_rank_indexes; // [criterion_index] + Array3D high_profile_ranks; // [criterion_index][boundary_index][high_profile_rank_indexes[criterion_index]] Array2D desirabilities; // [model_index][desination_index] Array2D destination_ranks; // [model_index][desination_index] diff --git a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/initialize-profiles/probabilistic-maximal-discrimination-power-per-criterion.cpp b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/initialize-profiles/probabilistic-maximal-discrimination-power-per-criterion.cpp index 121bf272..185452a8 100644 --- a/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/initialize-profiles/probabilistic-maximal-discrimination-power-per-criterion.cpp +++ b/lincs/liblincs/learning/mrsort-by-weights-profiles-breed/initialize-profiles/probabilistic-maximal-discrimination-power-per-criterion.cpp @@ -184,10 +184,10 @@ void InitializeProfilesForProbabilisticMaximalDiscriminationPowerPerCriterion::i if (boundary_index == learning_data.boundaries_count - 1) { high_rank = std::max(high_rank, low_rank); } else { - high_rank = std::max(high_rank, learning_data.high_profile_ranks[model_index][boundary_index + 1][criterion_index]); + high_rank = std::max(high_rank, learning_data.high_profile_ranks[model_index][boundary_index + 1][learning_data.high_profile_rank_indexes[criterion_index]]); } - learning_data.high_profile_ranks[model_index][boundary_index][criterion_index] = high_rank; + learning_data.high_profile_ranks[model_index][boundary_index][learning_data.high_profile_rank_indexes[criterion_index]] = high_rank; } } } diff --git a/lincs/liblincs/liblincs-module/learning-classes.cpp b/lincs/liblincs/liblincs-module/learning-classes.cpp index 3d21f570..c1ee6b14 100644 --- a/lincs/liblincs/liblincs-module/learning-classes.cpp +++ b/lincs/liblincs/liblincs-module/learning-classes.cpp @@ -50,7 +50,8 @@ void define_learning_classes(py::module& m) { .def_readonly("model_indexes", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::model_indexes, "Indexed by ``0`` to ``models_count - 1``. Indexes of in-progress models ordered by increasing accuracy.") .def_readonly("accuracies", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::accuracies, "Indexed by ``[model_index]``. Accuracy of each in-progress model.") .def_readonly("low_profile_ranks", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::low_profile_ranks, "Indexed by ``[model_index][boundary_index][criterion_index]``. The current rank of each low profile, for each model and criterion.") - .def_readonly("high_profile_ranks", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::high_profile_ranks, "Indexed by ``[model_index][boundary_index][criterion_index]``. The current rank of each high profile, for each model and criterion.") + .def_readonly("high_profile_rank_indexes", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::high_profile_rank_indexes, "Indexed by ``[criterion_index]``. The index in ``high_profile_ranks``, for each single-peaked criterion.") + .def_readonly("high_profile_ranks", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::high_profile_ranks, "Indexed by ``[model_index][boundary_index][high_profile_rank_indexes[criterion_index]]``. The current rank of each high profile, for each model and single-peaked criterion.") .def_readonly("weights", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::weights, "Indexed by ``[model_index][criterion_index]``. The current MR-Sort weight of each criterion for each model.") .def("get_best_accuracy", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::get_best_accuracy, "Return the accuracy of the best model so far.") .def("get_best_model", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::get_best_model, "Return the best model so far.") diff --git a/lincs/liblincs_module_tests.py b/lincs/liblincs_module_tests.py index 0e833533..9c96dbbd 100644 --- a/lincs/liblincs_module_tests.py +++ b/lincs/liblincs_module_tests.py @@ -1063,9 +1063,13 @@ def test_access_wpb_learning_data(self): self.assertEqual(list(learning_data.single_peaked), [False, True, False, False, True]) + self.assertEqual(len(learning_data.high_profile_rank_indexes), 5) + self.assertEqual(learning_data.high_profile_rank_indexes[1], 0) + self.assertEqual(learning_data.high_profile_rank_indexes[4], 1) + self.assertEqual(len(learning_data.high_profile_ranks), 9) self.assertEqual(len(learning_data.high_profile_ranks[0]), 2) - self.assertEqual(len(learning_data.high_profile_ranks[0][0]), 5) + self.assertEqual(len(learning_data.high_profile_ranks[0][0]), 2) self.assertIsInstance(learning_data.high_profile_ranks[0][0][0], int) self.assertEqual(len(learning_data.weights), 9)