Skip to content

Commit 0bcabe1

Browse files
author
Jana Pazurikova
committed
Extract the method for setting ss->best
1 parent d13cf7a commit 0bcabe1

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/diffevolution.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,8 @@ void run_diff_evolution(struct subset * const ss) {
7171
minimized_initial = s.population_size;
7272
}
7373

74-
7574
//find the best kappa_data
76-
//TODO extract to separate method, also used in kappa.c:find_the_best_parameters
77-
ss->best = &ss->data[0];
78-
for (i = 0; i < ss->kappa_data_count -1; i++)
79-
if (kd_sort_by_is_better(&ss->data[i], ss->best))
80-
ss->best = &ss->data[i];
75+
set_the_best(ss);
8176

8277
/* Run the optimization for max iterations */
8378
//TODO include iters_max for DE in limits or use one already there (that is used for discard)

src/kappa.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,7 @@ void find_the_best_parameters_for_subset(struct subset * const ss) {
232232
/* Determine the best parameters for computed data */
233233

234234
if(s.params_method == PARAMS_LR_FULL) {
235-
ss->best = &ss->data[0];
236-
for(int i = 0; i < ss->kappa_data_count - 1; i++)
237-
if(kd_sort_by_is_better(&ss->data[i], ss->best))
238-
ss->best = &ss->data[i];
235+
set_the_best(ss);
239236
}
240237
else if (s.params_method == PARAMS_LR_FULL_BRENT){
241238
/* If Brent is used, the maximum is stored in the last item */
@@ -247,3 +244,12 @@ void find_the_best_parameters_for_subset(struct subset * const ss) {
247244

248245
}
249246
}
247+
248+
/* Set the best parameters from subset */
249+
void set_the_best(struct subset * const ss) {
250+
ss->best = &ss->data[0];
251+
for(int i = 0; i < ss->kappa_data_count - 1; i++)
252+
if(kd_sort_by_is_better(&ss->data[i], ss->best))
253+
ss->best = &ss->data[i];
254+
255+
}

src/kappa.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
#include "subset.h"
1313

1414
void find_the_best_parameters_for_subset(struct subset * const ss);
15+
void set_the_best(struct subset * const ss);
1516

1617
#endif /* __KAPPA_H__ */

0 commit comments

Comments
 (0)