Skip to content

Commit 7ceb4dd

Browse files
author
Jana Pazurikova
committed
Rename some cmd options for parametrization optimization methods
1 parent 5e2641d commit 7ceb4dd

File tree

5 files changed

+70
-76
lines changed

5 files changed

+70
-76
lines changed

src/diffevolution.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ void run_diff_evolution(struct subset * const ss) {
5151
if (s.verbosity >= VERBOSE_KAPPA)
5252
printf("DE Calculating charges and evaluating fitness function for whole population\n");
5353
int i = 0;
54-
#pragma omp parallel for num_threads(s.de_threads) default(shared) private(i)
54+
#pragma omp parallel for num_threads(s.om_threads) default(shared) private(i)
5555
for (i = 0; i < ss->kappa_data_count; i++) {
5656
calculate_charges(ss, &ss->data[i]);
5757
calculate_statistics(ss, &ss->data[i]);
@@ -109,11 +109,11 @@ void run_diff_evolution(struct subset * const ss) {
109109
int condition = 1;
110110
int minimized = 0;
111111

112-
#pragma omp parallel num_threads(s.de_threads) default(shared)
112+
#pragma omp parallel num_threads(s.om_threads) default(shared)
113113
{
114114
while (condition) {
115115
#pragma omp master
116-
condition = (iter < s.limit_de_iters);
116+
condition = (iter < s.om_iters);
117117
{
118118
#pragma omp master
119119
{
@@ -160,7 +160,7 @@ void run_diff_evolution(struct subset * const ss) {
160160
}
161161

162162
/* All other threads do this */
163-
if (s.polish > 1 && is_quite_good(trial) && (s.de_threads == 0 || omp_get_thread_num() != 0))
163+
if (s.polish > 1 && is_quite_good(trial) && (s.om_threads == 0 || omp_get_thread_num() != 0))
164164
{
165165
minimized++;
166166
if (s.verbosity >= VERBOSE_KAPPA)
@@ -211,7 +211,7 @@ void run_diff_evolution(struct subset * const ss) {
211211
calculate_charges(ss, ss->best);
212212
calculate_statistics(ss, ss->best);
213213
if (s.verbosity >= VERBOSE_KAPPA) {
214-
printf("Out of %d iterations, we minimized %d trials.\n", s.limit_de_iters, minimized);
214+
printf("Out of %d iterations, we minimized %d trials.\n", s.om_iters, minimized);
215215
}
216216
kd_destroy(so_far_best);
217217
free(so_far_best);
@@ -261,7 +261,7 @@ int minimize_part_of_population(struct subset * ss, int *good_indices) {
261261
int i = 0;
262262

263263
/* We minimize all with R2>0.2 && R>0 */
264-
#pragma omp parallel for num_threads(s.de_threads) shared(ss, quite_good, good_indices) private(i)
264+
#pragma omp parallel for num_threads(s.om_threads) shared(ss, quite_good, good_indices) private(i)
265265
for (i = 0; i < ss->kappa_data_count; i++) {
266266
if (ss->data[i].full_stats.R2 > 0.2 && ss->data[i].full_stats.R > 0) {
267267
#pragma omp critical

src/eem.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,8 @@ void calculate_charges(struct subset * const ss, struct kappa_data * const kd) {
116116
for(int i = 1; i < ts.molecules_count; i++)
117117
starts[i] = starts[i - 1] + ts.molecules[i - 1].atoms_count;
118118
int nt = s.max_threads;
119-
if (s.params_method == PARAMS_DE)
120-
nt /= s.de_threads;
121-
if (s.params_method == PARAMS_GM)
122-
nt /= s.gm_threads;
119+
if (s.params_method == PARAMS_DE || s.params_method == PARAMS_GM)
120+
nt /= s.om_threads;
123121

124122
int nthreads = ts.molecules_count < nt ? ts.molecules_count : nt;
125123
#pragma omp parallel for num_threads(nthreads)

src/guidedmin.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void run_guided_min(struct subset * const ss) {
3535

3636
/* Create a set of random points in vector space of kappa_data */
3737
if (s.verbosity >= VERBOSE_KAPPA)
38-
printf("GM Generating %d vectors\n", s.gm_size);
38+
printf("GM Generating %d vectors\n", s.population_size);
3939

4040
/* Set bounds for each parameters in kappa_data */
4141
float *bounds = (float *) malloc((ts.atom_types_count * 2 + 1) * 2 * sizeof (float));
@@ -44,16 +44,16 @@ void run_guided_min(struct subset * const ss) {
4444
compute_parameters_bounds(bounds, 0);
4545

4646
/* Generate population */
47-
fill_ss(ss, s.gm_size);
48-
generate_random_population(ss, bounds, s.gm_size);
47+
fill_ss(ss, s.population_size);
48+
generate_random_population(ss, bounds, s.population_size);
4949
de_ss = ss;
5050

5151
/* Evaluate the fitness function for all points */
5252
if (s.verbosity >= VERBOSE_KAPPA)
5353
printf("GM Calculating charges and evaluating fitness function for whole set\n");
5454

5555
int i = 0;
56-
#pragma omp parallel for num_threads(s.gm_threads) default(shared) private(i)
56+
#pragma omp parallel for num_threads(s.om_threads) default(shared) private(i)
5757
for (i = 0; i < ss->kappa_data_count; i++) {
5858
calculate_charges(ss, &ss->data[i]);
5959
calculate_statistics(ss, &ss->data[i]);
@@ -67,7 +67,7 @@ void run_guided_min(struct subset * const ss) {
6767

6868
/* If we minimized zero data, inform user and suggest larger set */
6969
if (minimized_initial == 0) {
70-
EXIT_ERROR(RUN_ERROR, "No vector in set was worth minimizing. Please choose larger set than %d (option --gm-size)\n.", s.gm_size);
70+
EXIT_ERROR(RUN_ERROR, "No vector in set was worth minimizing. Please choose larger set than %d (option --om-pop-size)\n.", s.population_size);
7171
}
7272

7373
/* Find the best kappa_data */
@@ -101,7 +101,7 @@ int minimize_part_of_gm_set(struct subset* ss, int min_iterations) {
101101
int quite_good = 0;
102102
int i = 0;
103103
/* We minimize all with R2 > 0.2 && R > 0 */
104-
#pragma omp parallel for num_threads(s.gm_threads) shared(ss, quite_good) private(i)
104+
#pragma omp parallel for num_threads(s.om_threads) shared(ss, quite_good) private(i)
105105
for (i = 0; i < ss->kappa_data_count; i++) {
106106
if (ss->data[i].full_stats.R2 > 0.2 && ss->data[i].full_stats.R > 0) {
107107
#pragma omp critical

src/settings.c

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,16 @@ static struct option long_options[] = {
5252
{"max-threads", required_argument, 0, 171},
5353
{"list-omitted-molecules", no_argument, 0, 172},
5454
{"extra-precise", no_argument, 0, 173},
55-
{"de-pop-size", required_argument, 0, 180},
55+
{"om-pop-size", required_argument, 0, 180},
5656
{"de-f", required_argument, 0, 181},
5757
{"de-cr", required_argument, 0, 182},
58-
{"de-iters-max", required_argument, 0, 183},
59-
{"de-time-max", required_argument, 0, 184},
58+
{"om-iters-max", required_argument, 0, 183},
6059
{"de-dither", no_argument, 0, 186},
61-
{"de-fix-kappa",required_argument, 0, 188},
62-
{"de-threads",required_argument, 0, 189},
63-
{"de-polish", required_argument, 0, 190},
64-
{"gm-size", required_argument, 0, 191},
60+
{"om-fix-kappa",required_argument, 0, 188},
61+
{"om-threads",required_argument, 0, 189},
62+
{"om-polish", required_argument, 0, 190},
6563
{"gm-iterations-beg", required_argument, 0, 192},
6664
{"gm-iterations-end", required_argument, 0, 193},
67-
{"gm-threads", required_argument, 0, 194},
6865
{NULL, 0, 0, 0}
6966
};
7067

@@ -96,15 +93,13 @@ void s_init(void) {
9693
s.mutation_constant = -1;
9794
s.dither = 0;
9895
s.fixed_kappa = -1;
99-
s.de_threads = 1;
100-
s.limit_de_iters = NO_LIMIT_ITERS;
101-
s.limit_de_time = NO_LIMIT_TIME;
96+
s.om_threads = 1;
97+
s.om_iters = NO_LIMIT_ITERS;
98+
s.om_time = NO_LIMIT_TIME;
10299
s.polish = -1; /* 0 off, 1 only result, 2 result + during evolve, 3 result, evolve and some structures in initial population */
103-
s.gm_size = 100;
104-
s.gm_iterations_beg = 1000;
105-
s.gm_iterations_end = 2000;
106-
s.gm_threads = 1;
107-
s.sort_by = SORT_R2;
100+
s.gm_iterations_beg = 500;
101+
s.gm_iterations_end = 500;
102+
s.sort_by = SORT_NOT_SET;
108103
s.at_customization = AT_CUSTOM_ELEMENT_BOND;
109104
s.discard = DISCARD_OFF;
110105
s.tabu_size = 0.0f;
@@ -149,20 +144,19 @@ static void print_help(void) {
149144
printf(" --kappa VALUE use only one kappa VALUE for parameterization\n");
150145
printf(" --fs-precision VALUE resolution for the full scan (required)\n");
151146
printf(" --kappa-preset PRESET set kappa-max and fs-precision to safe values. Valid choices are: small, protein.\n");
152-
printf("Options specific to mode: params using differential evolution as calculation method\n");
153-
printf(" --de-pop-size VALUE set population size for DE (optional).\n");
154-
printf(" --de-iters-max COUNT set the maximum number of iterations for DE (optional).\n");
155-
printf(" --de-time-max HH:MM:SS set the maximum time for DE in format hours:minutes:seconds (optional).\n");
156-
printf(" --de-threads set number of threads for DE (optional).\n");
147+
printf("Options specific to mode: params using optimization method (differential evolution, guided minimization)\n");
148+
printf(" --om-pop-size VALUE set population size for optimization method (optional).\n");
149+
printf(" --om-iters COUNT set the maximum number of iterations for optimization method (optional).\n");
150+
printf(" --om-threads set number of threads for optimization method (optional).\n");
151+
printf(" --om-polish VALUE apply local minimzation on parameters. Valid choices: 0 (off), 1 (result), 2 (during evolving), 3 (at the initial population). \n");
152+
printf("Options specific to mode: params using differential evolution\n");
157153
printf(" --de-f VALUE set mutation constant for DE (optional).\n");
158154
printf(" --de-cr VALUE set crossover recombination constant for DE (optional).\n");
159155
printf(" --de-dither set the mutation constant to random value from [0.5;1] for ech iteration (optional).\n");
160-
printf(" --de-polish VALUE apply polishing on parameters. Valid choices: 0 (off), 1 (result), 2 (during evolving), 3 (at the beginning). Strongly recommend to keep the default value.\n");
161156
printf(" --de-fix-kappa set kappa to one fixed value (optional).\n");
162-
printf(" --gm-size set number of randomly generated vectors of parameters, those with reasonable stats will be minimized (optional).\n");
157+
printf("Options specific to mode: params using guided minimization\n");
163158
printf(" --gm-iterations-beg set number of minimization iterations for each reasonable vector of parameters (optional).\n");
164159
printf(" --gm-iterations-end set number of minimization itertions for the best to polish the final result (optional).\n");
165-
printf(" --gm-threads set number of threads used for parallel minimization (optional).\n");
166160
printf("Other options:\n");
167161
printf(" --par-out-file FILE output the parameters to the FILE\n");
168162
printf(" -d, --discard METHOD perform discarding with METHOD. Valid choices are: iterative, simple and off. Default is off.\n");
@@ -180,7 +174,7 @@ static void print_help(void) {
180174

181175
printf("neemp -m params --sdf-file molecules.sdf --chg-file charges.chg --kappa-max 1.0 --fs-precision 0.2 --sort-by RMSD.\n\
182176
Compute parameters for the given molecules in file molecules.sdf and ab-initio charges in charges.chg. Set maximum value for kappa to 1.0, step for the full scan to 0.2, no iterative refinement, sort results according to the relative mean square deviation.\n");
183-
printf("neemp -m params -p gm --sdf-file molecules.sdf --chg-file charges.chg --sort-by RMSD_avg --gm-size 250 -gm-iterations-beg 1000 -gm-iterations-end 500 --random-seed 1234 -vv.\n\
177+
printf("neemp -m params -p gm --sdf-file molecules.sdf --chg-file charges.chg --om-pop-size 50 -gm-iterations-beg 1000 -gm-iterations-end 500 --random-seed 1234 -vv.\n\
184178
Compute parameters for the given molecules in file molecules.sdf and ab-initio charges in charges.chg. The chosen optimization method: guided minimization will create 250 vectors (each vector consists of all parameters) and minimized reasonably good ones for 1000 iterations. The best of them will be minimized again, for 500 iterations.\n");
185179

186180
printf("neemp -m charges --sdf-file molecules.sdf --par-file parameters --chg-out-file output.chg\n\
@@ -382,7 +376,7 @@ void parse_options(int argc, char **argv) {
382376
s.recombination_constant = (float) atof(optarg);
383377
break;
384378
case 183:
385-
s.limit_de_iters = atoi(optarg);
379+
s.om_iters = atoi(optarg);
386380
break;
387381
case 184: {
388382
char *part;
@@ -400,7 +394,7 @@ void parse_options(int argc, char **argv) {
400394
if(part != NULL)
401395
secs = atoi(part);
402396

403-
s.limit_de_time = 3600 * hours + 60 * mins + secs;
397+
s.om_time = 3600 * hours + 60 * mins + secs;
404398
break;
405399
}
406400
case 186:
@@ -410,24 +404,18 @@ void parse_options(int argc, char **argv) {
410404
s.fixed_kappa = (float)atof(optarg);
411405
break;
412406
case 189:
413-
s.de_threads = atoi(optarg);
407+
s.om_threads = atoi(optarg);
414408
break;
415409
case 190:
416410
s.polish = atoi(optarg);
417411
break;
418412
/* GM settings */
419-
case 191:
420-
s.gm_size = atoi(optarg);
421-
break;
422413
case 192:
423414
s.gm_iterations_beg = atoi(optarg);
424415
break;
425416
case 193:
426417
s.gm_iterations_end = atoi(optarg);
427418
break;
428-
case 194:
429-
s.gm_threads = atoi(optarg);
430-
break;
431419
case '?':
432420
EXIT_ERROR(ARG_ERROR, "%s", "Try -h/--help.\n");
433421
default:
@@ -449,11 +437,11 @@ void check_settings(void) {
449437
if(s.max_threads < 1)
450438
EXIT_ERROR(ARG_ERROR, "%s", "Maximum number of threads has to be at least 1 (default).\n");
451439

452-
if(s.de_threads < 1)
453-
EXIT_ERROR(ARG_ERROR, "%s", "Maximum number of DE threads has to be at least 1 (default).\n");
440+
if(s.om_threads < 1)
441+
EXIT_ERROR(ARG_ERROR, "%s", "Maximum number of OM threads has to be at least 1 (default).\n");
454442

455-
if(s.max_threads < s.de_threads)
456-
EXIT_ERROR(ARG_ERROR, "%s", "Maximum number of DE threads has to be smaller than maximum number of threads.\n");
443+
if(s.max_threads < s.om_threads)
444+
EXIT_ERROR(ARG_ERROR, "%s", "Maximum number of OM threads has to be smaller than maximum number of threads.\n");
457445

458446
if(s.mode == MODE_PARAMS) {
459447
if(s.chg_file[0] == '\0')
@@ -475,27 +463,28 @@ void check_settings(void) {
475463

476464
if (s.params_method == PARAMS_DE) {
477465
/* All settings are optional, so check for mistakes and set defaults */
478-
if (s.population_size == 0)
479-
s.population_size = 500; /* 1.2 * (ts.atom_types_count * 2 + 1); */
480-
if (s.limit_de_iters == NO_LIMIT_ITERS && s.limit_de_time == NO_LIMIT_TIME)
481-
s.limit_de_iters = 1000;
466+
if (s.population_size <1)
467+
s.population_size = 100; /* 1.2 * (ts.atom_types_count * 2 + 1); */
468+
if (s.om_iters == NO_LIMIT_ITERS && s.om_time == NO_LIMIT_TIME)
469+
s.om_iters = 500;
482470
if (s.mutation_constant < 0) /* If not set */
483471
s.mutation_constant = 0.75;
484472
if (s.recombination_constant < 0)
485473
s.recombination_constant = 0.7;
486474
if (s.polish == -1)
487475
s.polish = 1;
488-
476+
if (s.sort_by == SORT_NOT_SET)
477+
s.sort_by = SORT_RMSD_AVG;
489478
}
490479

491480
if (s.params_method == PARAMS_GM) {
492481
/* All settings are optional, so check for mistakes */
493-
if (s.gm_size < 1)
494-
EXIT_ERROR(ARG_ERROR, "%s", "Size of GM set has to be positive.\n");
482+
if (s.population_size < 1)
483+
s.population_size = 100; /* 1.2 * (ts.atom_types_count * 2 + 1); */
495484
if (s.gm_iterations_beg < 1 || s.gm_iterations_end < 1)
496485
EXIT_ERROR(ARG_ERROR, "%s", "Number of minimization iterations for GM has to be positive.\n");
497-
if (s.gm_threads < 1 || s.gm_threads > s.max_threads)
498-
EXIT_ERROR(ARG_ERROR, "%s", "Number of threads for minimization must be between 1 and maximum number of threads.\n");
486+
if (s.sort_by == SORT_NOT_SET)
487+
s.sort_by = SORT_RMSD_AVG;
499488
}
500489

501490
if (s.random_seed == -1)
@@ -510,6 +499,9 @@ void check_settings(void) {
510499
if(s.limit_time != NO_LIMIT_TIME && s.limit_time > 36000 * 1000)
511500
EXIT_ERROR(ARG_ERROR, "%s", "Maximum time should not be higher than 1000 hours.\n");
512501

502+
if ((s.params_method == PARAMS_LR_FULL || s.params_method == PARAMS_LR_FULL_BRENT) && s.sort_by == SORT_NOT_SET)
503+
s.sort_by = SORT_R2;
504+
513505
/* TODO verify with Tomas if this is the intended behavior */
514506
if(s.params_method == PARAMS_LR_FULL_BRENT /*!s.full_scan_only*/ && (s.sort_by != SORT_R && s.sort_by != SORT_R2 && s.sort_by != SORT_SPEARMAN && s.sort_by != SORT_RW))
515507
EXIT_ERROR(ARG_ERROR, "%s", "Full scan must be used for sort-by other than R, R2 or Spearman.\n");
@@ -600,7 +592,7 @@ void print_settings(void) {
600592
}
601593
printf("\nMaximum number of threads: %d\n", s.max_threads);
602594
if (s.mode == MODE_PARAMS && s.params_method == PARAMS_DE)
603-
printf("Maximum number of threads used for DE: %d\n", s.de_threads);
595+
printf("Maximum number of threads used for DE: %d\n", s.om_threads);
604596
printf("\nVerbosity level: ");
605597
switch(s.verbosity) {
606598
case VERBOSE_MINIMAL:
@@ -644,6 +636,9 @@ void print_settings(void) {
644636
case SORT_D_MAX:
645637
printf("Max D");
646638
break;
639+
case SORT_NOT_SET:
640+
printf("not set");
641+
break;
647642
}
648643

649644
if(s.sort_by == SORT_R || s.sort_by == SORT_R2 || s.sort_by == SORT_RW || s.sort_by == SORT_SPEARMAN)
@@ -702,7 +697,7 @@ void print_settings(void) {
702697
if (s.params_method == PARAMS_DE) {
703698
printf("\n Differential evolution settings:\n");
704699
printf("\t - population size %d\n", s.population_size);
705-
printf("\t - max iterations %d\n", s.limit_de_iters);
700+
printf("\t - max iterations %d\n", s.om_iters);
706701
if (s.polish != 0) {
707702
printf("\t - polishing ");
708703
if (s.polish >= 1)
@@ -725,10 +720,10 @@ void print_settings(void) {
725720

726721
if (s.params_method == PARAMS_GM) {
727722
printf("\nGuided minimization settings:\n");
728-
printf("\t - set size %d\n", s.gm_size);
723+
printf("\t - set size %d\n", s.population_size);
729724
printf("\t - iterations for set at the beginning %d\n", s.gm_iterations_beg);
730725
printf("\t - iterations for the result at the end %d\n", s.gm_iterations_end);
731-
printf("\t - threads used for minimization %d\n", s.gm_threads);
726+
printf("\t - threads used for minimization %d\n", s.om_threads);
732727
}
733728
}
734729

src/settings.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ enum sort_mode {
4040
SORT_RMSD,
4141
SORT_RMSD_AVG,
4242
SORT_D_AVG,
43-
SORT_D_MAX
43+
SORT_D_MAX,
44+
SORT_NOT_SET
4445
};
4546

4647
enum atom_type_customization {
@@ -86,22 +87,22 @@ struct settings {
8687
float kappa_set;
8788
float full_scan_precision;
8889

89-
/* Settings regarding PARAMS_DE optimization method */
90+
/* Settings regarding optimization methods as GM, DE, GA */
9091
int population_size;
92+
float fixed_kappa; /* Fix kappa to given value */
93+
int om_threads; /* Number of threads used to paralellize DE */
94+
int om_iters;
95+
time_t om_time;
96+
int polish; /* Use NEWUOA minimization to polish trial or results */
97+
98+
/* Settings regarding PARAMS_DE method */
9199
float mutation_constant;
92100
int dither; /* Set mutation constant to random value from [0.5, 1] each iteration */
93101
float recombination_constant;
94-
float fixed_kappa; /* Fix kappa to given value */
95-
int de_threads; /* Number of threads used to paralellize DE */
96-
int limit_de_iters;
97-
time_t limit_de_time;
98-
int polish; /* Use NEWUOA minimization to polish trial or results */
99102

100103
/* Settings regarding PARAMS_GM optimization method */
101-
int gm_size;
102104
int gm_iterations_beg;
103105
int gm_iterations_end;
104-
int gm_threads;
105106

106107
/* Other settings */
107108
int random_seed;

0 commit comments

Comments
 (0)