Skip to content

Commit

Permalink
Merge pull request opencog#10 from ngeiswei/oc-to-sn
Browse files Browse the repository at this point in the history
Merge opencog/moses to singnet/moses
  • Loading branch information
ngeiswei authored May 22, 2020
2 parents cd59a64 + 86bf43c commit 92de724
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion moses/moses/main/moses_exec_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace std;
// Available abbreviations are: O
static const pair<string, string> rand_seed_opt("random-seed", "r");
static const pair<string, string> problem_opt("problem", "H");
static const pair<string, string> nsamples_opt("nsamples", "b");
static const string nsamples_opt("nsamples");
static const pair<string, string> min_rand_input_opt("min-rand-input", "q");
static const pair<string, string> max_rand_input_opt("max-rand-input", "w");
static const pair<string, string> max_evals_opt("max-evals", "m");
Expand Down
2 changes: 1 addition & 1 deletion moses/moses/main/problem-params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ problem_params::add_options(boost::program_options::options_description& desc)
"maj, demo, majority problem\n\n"
"sr, demo, regression of f_n(x) = sum_{k=1,n} x^k\n")

(opt_desc_str(nsamples_opt).c_str(),
(nsamples_opt.c_str(),
po::value<int>(&nsamples)->default_value(-1),
"Number of samples to describe the problem. "
"If nsample is negative, null or larger than the maximum "
Expand Down
7 changes: 3 additions & 4 deletions moses/moses/man/moses.1
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ moses \- meta-optimizing semantic evolutionary search solver
.IR algo ]
.RB [ \-B
.IR knob_effort ]
.RB [ \-b
.IR nsamples ]
.RB [ \-\-nsamples ]
.RB [ \-C1 ]
.RB [ \-c
.IR result_count ]
Expand Down Expand Up @@ -481,7 +480,7 @@ For boolean problems, this is the same as flipping the output
value. This option can only be used once, and, if used, it should
specify a column containing an integer or floating-point value.
.TP
.BI \-b\ num \fR,\ \fB\-\-nsamples= num
.BI \-\-nsamples= num
The number of samples to be taken from the input file. Valid values
run between 1 and the number of rows in the data file; other values
are ignored. If this option is absent, then all data rows are used.
Expand Down Expand Up @@ -1249,7 +1248,7 @@ combo program specified with the \fB-y\fR flag. That is, the goal of
the run is to deduce and learn the specified combo program.

When specifying combo programs with continuous variables in them, be
sure to use the \fB\-q\fR, \fB\-w\fR and \fB\-b\fR flags to specify
sure to use \fB\-q\fR, \fB\-w\fR and \fB\-\-nsample\fR to specify
a range of input values to be sampled. In order to determine the fitness
of any candidate, it must be compared to the specified combo
program. The comparison is done at a variety of different input
Expand Down
25 changes: 17 additions & 8 deletions moses/moses/optimization/hill-climbing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/

#include <math.h> // for sqrtf, cbrtf
#include <algorithm>

#include <boost/algorithm/minmax_element.hpp>

Expand Down Expand Up @@ -165,6 +166,7 @@ void hill_climbing::operator()(deme_t& deme,

number_of_new_instances =
crossover(deme, current_number_of_instances,
number_of_new_instances,
prev_start, prev_size, prev_center);

already_xover = true;
Expand Down Expand Up @@ -532,11 +534,12 @@ size_t hill_climbing::n_new_instances(size_t distance, unsigned max_evals,
// disabled and it leads to some massive slow down because then most
// of the computational power is spent on successive representation
// building
#define MINIMUM_DEME_SIZE 100
#define MINIMUM_DEME_SIZE 100UL

// If fraction is small, just use up the rest of the cycles.
// If fraction is small, just use up the rest of the cycles up to
// MINIMUM_DEME_SIZE.
if (number_of_new_instances < MINIMUM_DEME_SIZE)
number_of_new_instances = nleft;
number_of_new_instances = std::min(nleft, MINIMUM_DEME_SIZE);

if (nleft < number_of_new_instances)
number_of_new_instances = nleft;
Expand Down Expand Up @@ -691,23 +694,29 @@ size_t hill_climbing::cross_top_three(deme_t& deme,
}

size_t hill_climbing::crossover(deme_t& deme, size_t deme_size,
size_t max_number_of_new_instances,
size_t sample_start, size_t sample_size,
const instance& base) {
// Do not make more than the budget
size_t num_to_make = std::min(max_number_of_new_instances,
(size_t)hc_params.crossover_pop_size);

// These cross-over (in the genetic sense) the
// top-scoring one, two and three instances,respectively.
size_t number_of_new_instances =
cross_top_one(deme, deme_size, hc_params.crossover_pop_size / 3,
cross_top_one(deme, deme_size,
// Add the remainder so that it all sums up to
// num_to_make in the end.
num_to_make / 3 + num_to_make % 3,
sample_start, sample_size, base);

number_of_new_instances +=
cross_top_two(deme, deme_size + number_of_new_instances,
hc_params.crossover_pop_size / 3,
sample_start, sample_size, base);
num_to_make / 3, sample_start, sample_size, base);

number_of_new_instances +=
cross_top_three(deme, deme_size + number_of_new_instances,
hc_params.crossover_pop_size / 3,
sample_start, sample_size, base);
num_to_make / 3, sample_start, sample_size, base);

return number_of_new_instances;
}
Expand Down
5 changes: 4 additions & 1 deletion moses/moses/optimization/hill-climbing.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,11 @@ struct hill_climbing : optimizer_base
size_t sample_size,
const instance& base);

// chain the 3 crossovers methods above and return the number of new instances
// Chain the 3 crossovers methods above and return the number of
// new instances. The number of new instances should be lower or
// equal to max_number_of_new_instance.
size_t crossover(deme_t& deme, size_t deme_size,
size_t max_number_of_new_instance,
size_t sample_start, size_t sample_size,
const instance& base);

Expand Down
2 changes: 1 addition & 1 deletion tests/moses/AntUTest.cxxtest
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public:
ant_bscore bscorer;

// See the diary for the complexity ratio.
double complexity_ratio = 0.16;
double complexity_ratio = 0.08;
bscorer.set_complexity_coef(complexity_ratio);
behave_cscore cscorer(bscorer);

Expand Down

0 comments on commit 92de724

Please sign in to comment.