Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krab1k committed Jun 9, 2016
1 parent c8a76fb commit 035b544
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 143 deletions.
195 changes: 104 additions & 91 deletions src/diffevolution.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/diffevolution.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern void newuoa_(int* n, int* npt, double* x, double* rhobeg, double* rhoend,
extern void calfun_(int n, double*x, double* f);
void kappa_data_to_double_array(struct kappa_data* trial, double* x);
void double_array_to_kappa_data(double* x, struct kappa_data* trial);
int is_quite_good(struct kappa_data* t);
int is_quite_good(const struct kappa_data * const t);

struct subset * de_ss;
#endif /* __DIFFEVOLUTION_H__ */
34 changes: 19 additions & 15 deletions src/guidedmin.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,45 @@ void run_guided_min(struct subset * const ss) {
printf("GM Generating %d vectors\n", s.gm_size);

/* Set bounds for each parameters in kappa_data */
float *bounds = (float*) malloc((ts.atom_types_count*2+1)*2*sizeof(float));
//compute bounds, 0 means set them to fixed numbers taken from Tomas's full scan, 1 means try to find them with broad search
float *bounds = (float *) malloc((ts.atom_types_count * 2 + 1) * 2 * sizeof (float));

/* Compute bounds, 0 means set them to fixed numbers taken from Tomas's full scan, 1 means try to find them with broad search */
compute_parameters_bounds(bounds, 0);
//generate population

/* Generate population */
fill_ss(ss, s.gm_size);
generate_random_population(ss, bounds, s.gm_size);
de_ss = ss;
//evaluate the fitness function for all points
de_ss = ss;

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

int i = 0;
#pragma omp parallel for num_threads(s.gm_threads) default(shared) private(i)
#pragma omp parallel for num_threads(s.gm_threads) default(shared) private(i)
for (i = 0; i < ss->kappa_data_count; i++) {
calculate_charges(ss, &ss->data[i]);
calculate_statistics(ss, &ss->data[i]);
}

//minimize part of population that has R>0.3
/* Minimize part of population that has R > 0.3 */
int minimized_initial = 0;
if (s.verbosity >= VERBOSE_KAPPA)
printf("GM minimizing population\n");
minimized_initial = minimize_part_of_gm_set(ss, s.gm_iterations_beg);

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

//find the best kappa_data
/* Find the best kappa_data */
set_the_best(ss);

struct kappa_data *so_far_best = (struct kappa_data*)malloc(sizeof(struct kappa_data));
struct kappa_data *so_far_best = (struct kappa_data *) malloc(sizeof(struct kappa_data));
kd_init(so_far_best);

//copy ss->best into so_far_best
/* Copy ss->best into so_far_best */
kd_copy_parameters(ss->best, so_far_best);
calculate_charges(ss, so_far_best);
calculate_statistics(ss, so_far_best);
Expand All @@ -96,15 +100,15 @@ int minimize_part_of_gm_set(struct subset* ss, int min_iterations) {

int quite_good = 0;
int i = 0;
//we minimize all with R2>0.2 && R>0
#pragma omp parallel for num_threads(s.gm_threads) shared(ss, quite_good) private(i)
/* We minimize all with R2 > 0.2 && R > 0 */
#pragma omp parallel for num_threads(s.gm_threads) shared(ss, quite_good) private(i)
for (i = 0; i < ss->kappa_data_count; i++) {
if (ss->data[i].full_stats.R2 > 0.2 && ss->data[i].full_stats.R > 0) {
#pragma omp critical
#pragma omp critical
{
quite_good++;
}
struct kappa_data* m = (struct kappa_data*) malloc (sizeof(struct kappa_data));
struct kappa_data* m = (struct kappa_data *) malloc (sizeof(struct kappa_data));
kd_init(m);
m->parent_subset = ss;
kd_copy_parameters(&ss->data[i], m);
Expand Down
14 changes: 2 additions & 12 deletions src/guidedmin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,7 @@
#include "diffevolution.h"

void run_guided_min(struct subset * const ss);
//void generate_random_population(struct subset* ss, float *bounds, int size);
int minimize_part_of_gm_set(struct subset* ss, int min_iterations);
//void compute_parameters_bounds(float* bounds, int by_atom_type);
//float get_random_float(float low, float high);
//float interpolate_to_different_bounds(float x, float low, float high);
//int sum(int* vector, int size);
//void minimize_locally(struct kappa_data* trial, int max_calls);
//extern void newuoa_(int* n, int* npt, double* x, double* rhobeg, double* rhoend, int* iprint, int* maxfun, double* w);
//extern void calfun_(int n, double*x, double* f);
//void kappa_data_to_double_array(struct kappa_data* trial, double* x);
//void double_array_to_kappa_data(double* x, struct kappa_data* trial);
int minimize_part_of_gm_set(struct subset *ss, int min_iterations);

struct subset * de_ss;
struct subset *de_ss;
#endif /* __GUIDEDMIN_H__ */
6 changes: 3 additions & 3 deletions src/kappa.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,11 @@ void find_the_best_parameters_for_subset(struct subset * const ss) {
}

if (s.params_method == PARAMS_DE) {
//runs a differential evolution algorithm to find the best parameters, ss->best is set after the call
/* Runs a differential evolution algorithm to find the best parameters, ss->best is set after the call */
run_diff_evolution(ss);
}
if (s.params_method == PARAMS_GM) {
//runs a guided minimization algorithm, ss->best is set after the call
/* Runs a guided minimization algorithm, ss->best is set after the call */
run_guided_min(ss);
}

Expand All @@ -245,7 +245,7 @@ void find_the_best_parameters_for_subset(struct subset * const ss) {
ss->best = &ss->data[ss->kappa_data_count - 1];
}
else if (s.params_method == PARAMS_DE || s.params_method == PARAMS_GM) {
//well, nothing, the best structure has been already set
/* well, nothing, the best structure has been already set */
}

}
Expand Down
22 changes: 12 additions & 10 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void s_init(void) {
s.de_threads = 1;
s.limit_de_iters = NO_LIMIT_ITERS;
s.limit_de_time = NO_LIMIT_TIME;
s.polish = -1; //0 off, 1 only result, 2 result + during evolve, 3 result, evolve and some structures in initial population
s.polish = -1; /* 0 off, 1 only result, 2 result + during evolve, 3 result, evolve and some structures in initial population */
s.gm_size = 100;
s.gm_iterations_beg = 1000;
s.gm_iterations_end = 2000;
Expand Down Expand Up @@ -367,7 +367,7 @@ void parse_options(int argc, char **argv) {
case 173:
s.rw = (float) atof(optarg);
break;
//DE settings
/* DE settings */
case 180:
s.population_size = atoi(optarg);
break;
Expand Down Expand Up @@ -411,7 +411,7 @@ void parse_options(int argc, char **argv) {
case 190:
s.polish = atoi(optarg);
break;
//GM settings
/* GM settings */
case 191:
s.gm_size = atoi(optarg);
break;
Expand Down Expand Up @@ -454,7 +454,7 @@ void check_settings(void) {
if(s.mode == MODE_PARAMS) {
if(s.chg_file[0] == '\0')
EXIT_ERROR(ARG_ERROR, "%s", "No .chg file provided.\n");
//if user did not specify the optimization method for parameters calculation, set linear regression
/* If user did not specify the optimization method for parameters calculation, set linear regression */
if (s.params_method == PARAMS_NOT_SET)
s.params_method = PARAMS_LR_FULL;

Expand All @@ -478,12 +478,13 @@ void check_settings(void) {
}
}

if (s.params_method == PARAMS_DE) { //all settings are optional, so check for mistakes and set defaults
if (s.params_method == PARAMS_DE) {
/* All settings are optional, so check for mistakes and set defaults */
if (s.population_size == 0)
s.population_size = 500; //1.2*(ts.atom_types_count*2+1);
s.population_size = 500; /* 1.2 * (ts.atom_types_count * 2 + 1); */
if (s.limit_de_iters == NO_LIMIT_ITERS && s.limit_de_time == NO_LIMIT_TIME)
s.limit_de_iters = 1000;
if (s.mutation_constant < 0) // if not set
if (s.mutation_constant < 0) /* If not set */
s.mutation_constant = 0.75;
if (s.recombination_constant < 0)
s.recombination_constant = 0.7;
Expand All @@ -492,7 +493,8 @@ void check_settings(void) {

}

if (s.params_method == PARAMS_GM) { //all settings are optional, so check for mistakes
if (s.params_method == PARAMS_GM) {
/* All settings are optional, so check for mistakes */
if (s.gm_size < 1)
EXIT_ERROR(ARG_ERROR, "%s", "Size of GM set has to be positive.\n");
if (s.gm_iterations_beg < 1 || s.gm_iterations_end < 1)
Expand All @@ -512,7 +514,8 @@ void check_settings(void) {

if(s.limit_time != NO_LIMIT_TIME && s.limit_time > 36000 * 1000)
EXIT_ERROR(ARG_ERROR, "%s", "Maximum time should not be higher than 1000 hours.\n");
//TODO verify with Tomas if this is the intended behavior

/* TODO verify with Tomas if this is the intended behavior */
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))
EXIT_ERROR(ARG_ERROR, "%s", "Full scan must be used for sort-by other than R, R2 or Spearman.\n");

Expand Down Expand Up @@ -728,7 +731,6 @@ void print_settings(void) {
printf("\t - iterations for set at the beginning %d\n", s.gm_iterations_beg);
printf("\t - iterations for the result at the end %d\n", s.gm_iterations_end);
printf("\t - threads used for minimization %d\n", s.gm_threads);

}
}

Expand Down
18 changes: 9 additions & 9 deletions src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum params_calc_method {
PARAMS_LR_FULL,
PARAMS_LR_FULL_BRENT,
PARAMS_DE,
PARAMS_GM, //guided minimization
PARAMS_GM,
PARAMS_NOT_SET
};

Expand Down Expand Up @@ -80,29 +80,29 @@ struct settings {
enum atom_type_customization at_customization;
enum discarding_mode discard;

//settings regarding PARAMS_LR_FULL* parameters' calculation method
/* Settings regarding PARAMS_LR_FULL* parameters' calculation method */
float kappa_max;
float kappa_set;
float full_scan_precision;

//settings regarding PARAMS_DE optimization method
/* Settings regarding PARAMS_DE optimization method */
int population_size;
float mutation_constant;
int dither; //set mutation constant to random value from [0.5, 1] each iteration
int dither; /* Set mutation constant to random value from [0.5, 1] each iteration */
float recombination_constant;
float fixed_kappa; //fix kappa to given value
int de_threads; //number of threads used to paralellize DE
float fixed_kappa; /* Fix kappa to given value */
int de_threads; /* Number of threads used to paralellize DE */
int limit_de_iters;
time_t limit_de_time;
int polish; //use NEWUOA minimization to polish trial or results
int polish; /* Use NEWUOA minimization to polish trial or results */

//settings regarding PARAMS_GM optimization method
/* Settings regarding PARAMS_GM optimization method */
int gm_size;
int gm_iterations_beg;
int gm_iterations_end;
int gm_threads;

//other settings
/* Other settings */
int random_seed;
enum verbosity_levels verbosity;

Expand Down
4 changes: 2 additions & 2 deletions src/statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ static void set_total_R_w(struct kappa_data * const kd) {
weighted_corr_sum += weight * kd->per_at_stats[i].R;
}

//consider total R
weighted_corr_sum += 3 * (pow(s.rw, kd->full_stats.R2)) * kd->full_stats.R2 - kd->full_stats.RMSD/3;
/* consider total R */
weighted_corr_sum += 3 * (pow(s.rw, kd->full_stats.R2)) * kd->full_stats.R2 - kd->full_stats.RMSD / 3;

/* Normalize the results */
kd->full_stats.R_w = (float) (weighted_corr_sum / (ts.atom_types_count * s.rw + 3 * s.rw));
Expand Down

0 comments on commit 035b544

Please sign in to comment.