File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -569,7 +569,12 @@ void Clustering::train_encoded(
569569 if (i > 0 ) {
570570 float prev_obj =
571571 iteration_stats[iteration_stats.size () - 2 ].obj ;
572- if (obj == prev_obj) {
572+
573+ double change = (prev_obj == 0 )
574+ ? std::numeric_limits<double >::max ()
575+ : (prev_obj - obj) / prev_obj;
576+
577+ if (change >= 0 && change <= early_stop_threshold) {
573578 if (verbose) {
574579 printf (" \n Converged at iteration %d: "
575580 " objective did not change\n " ,
Original file line number Diff line number Diff line change @@ -69,6 +69,12 @@ struct ClusteringParameters {
6969 // / Only used when init_method = AFK_MC2.
7070 // / Longer chains give better approximation but are slower.
7171 uint16_t afkmc2_chain_length = 50 ;
72+
73+ // / Early stop threshold, the range is [0, 1].
74+ // / The value of 0 implies a default Faiss behavior,
75+ // / so the training process stops only if an error
76+ // / is unchanged from the previous iteration.
77+ double early_stop_threshold = 0.0 ;
7278};
7379
7480struct ClusteringIterationStats {
You can’t perform that action at this time.
0 commit comments