Skip to content

Commit

Permalink
Expose 'WPB.LearningData.iteration_index' to Python
Browse files Browse the repository at this point in the history
  • Loading branch information
jacquev6 committed Sep 20, 2023
1 parent 62ce86c commit dbc4573
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
3 changes: 3 additions & 0 deletions integration-tests/help-all/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,9 @@ get_best_accuracy( (LearningData)arg1) -> int :
C++ signature :
unsigned int get_best_accuracy(lincs::LearnMrsortByWeightsProfilesBreed::LearningData {lvalue})

lincs.LearnMrsortByWeightsProfilesBreed.LearningData.iteration_index: property
------------------------------------------------------------------------------

lincs.LearnMrsortByWeightsProfilesBreed.LearningData.make: function
-------------------------------------------------------------------

Expand Down
44 changes: 22 additions & 22 deletions integration-tests/verbose/expected-learning-log.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
Best accuracy: 180
Best accuracy: 182
Best accuracy: 189
Best accuracy: 188
Best accuracy: 193
Best accuracy: 194
Best accuracy: 197
Best accuracy: 197
Best accuracy: 193
Best accuracy: 197
Best accuracy: 197
Best accuracy: 197
Best accuracy: 193
Best accuracy: 193
Best accuracy: 194
Best accuracy: 192
Best accuracy: 191
Best accuracy: 194
Best accuracy: 198
Best accuracy: 199
Best accuracy: 198
Final accuracy: 200
Best accuracy (after 1 iterations): 180
Best accuracy (after 2 iterations): 182
Best accuracy (after 3 iterations): 189
Best accuracy (after 4 iterations): 188
Best accuracy (after 5 iterations): 193
Best accuracy (after 6 iterations): 194
Best accuracy (after 7 iterations): 197
Best accuracy (after 8 iterations): 197
Best accuracy (after 9 iterations): 193
Best accuracy (after 10 iterations): 197
Best accuracy (after 11 iterations): 197
Best accuracy (after 12 iterations): 197
Best accuracy (after 13 iterations): 193
Best accuracy (after 14 iterations): 193
Best accuracy (after 15 iterations): 194
Best accuracy (after 16 iterations): 192
Best accuracy (after 17 iterations): 191
Best accuracy (after 18 iterations): 194
Best accuracy (after 19 iterations): 198
Best accuracy (after 20 iterations): 199
Best accuracy (after 21 iterations): 198
Final accuracy (after 22 iterations): 200
4 changes: 2 additions & 2 deletions lincs/command_line_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,10 @@ def __init__(self, learning_data):
self.learning_data = learning_data

def after_iteration(self):
print("Best accuracy:", self.learning_data.get_best_accuracy(), file=sys.stderr)
print(f"Best accuracy (after {self.learning_data.iteration_index + 1} iterations): {self.learning_data.get_best_accuracy()}", file=sys.stderr)

def before_return(self):
print("Final accuracy:", self.learning_data.get_best_accuracy(), file=sys.stderr)
print(f"Final accuracy (after {self.learning_data.iteration_index + 1} iterations): {self.learning_data.get_best_accuracy()}", file=sys.stderr)

observers.append(VerboseObserver(learning_data))

Expand Down
5 changes: 5 additions & 0 deletions lincs/liblincs/liblincs_module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ void set_alternative_category_index(lincs::Alternative& alt, std::optional<unsig
alt.category_index = category_index;
}

unsigned get_learning_data_iteration_index(const lincs::LearnMrsortByWeightsProfilesBreed::LearningData& learning_data) {
return learning_data.iteration_index;
}

} // namespace

template <typename T>
Expand Down Expand Up @@ -410,6 +414,7 @@ BOOST_PYTHON_MODULE(liblincs) {
.def("make", &make_learning_data, bp::return_value_policy<bp::manage_new_object>()).staticmethod("make")
// @todo(Feature, soon) Expose all attributes to allow non-trivial Python strategies and observers
.def("get_best_accuracy", &lincs::LearnMrsortByWeightsProfilesBreed::LearningData::get_best_accuracy)
.add_property("iteration_index", &get_learning_data_iteration_index)
;

struct ProfilesInitializationStrategyWrap : lincs::LearnMrsortByWeightsProfilesBreed::ProfilesInitializationStrategy, bp::wrapper<lincs::LearnMrsortByWeightsProfilesBreed::ProfilesInitializationStrategy> {
Expand Down

0 comments on commit dbc4573

Please sign in to comment.