Made it compile under gcc 3.2.2 by adding explicit definitions

of normally derived comparison operators >, >=, and == for the
structure phenotype.  ( adding #include <utility> was not sufficient
to solve the problem)
Also added function gprop_use_datasets() to give more flexibility
in subclassing the datasets used to train the nets.
This commit is contained in:
stevemadere 2004-01-13 20:21:52 +00:00
commit 4662677a5f
2 changed files with 55 additions and 19 deletions

View file

@ -16,6 +16,7 @@ using namespace std;
//-----------------------------------------------------------------------------
unsigned in, out, hidden;
mlp::set train, validate, test;
//-----------------------------------------------------------------------------
// parameters
@ -77,16 +78,17 @@ void arg(int argc, char** argv)
exit(EXIT_SUCCESS);
}
load_file(trn_set, "trn");
load_file(val_set, "val");
load_file(tst_set, "tst");
load_file(train, "trn");
load_file(validate, "val");
load_file(test, "tst");
phenotype::trn_max = trn_set.size();
phenotype::val_max = val_set.size();
phenotype::tst_max = tst_set.size();
phenotype::trn_max = train.size();
phenotype::val_max = validate.size();
phenotype::tst_max = test.size();
in = trn_set.front().input.size();
out = trn_set.front().output.size();
in = train.front().input.size();
out = train.front().output.size();
gprop_use_datasets(&train, &validate, &test);
hidden = hiddenp.value();
}
@ -133,7 +135,7 @@ void ga()
// stop condition
eoGenContinue<Chrom> continuator1(generations.value());
phenotype p; p.val_ok = val_set.size() - 1; p.mse_error = 0;
phenotype p; p.val_ok = validate.size() - 1; p.mse_error = 0;
eoFitContinue<Chrom> continuator2(p);
eoCombinedContinue<Chrom> continuator(continuator1, continuator2);

View file

@ -54,6 +54,23 @@ struct phenotype
{
return a.val_ok < b.val_ok || !(b.val_ok < a.val_ok) && b.mse_error < a.mse_error;
}
friend bool operator==(const phenotype& a, const phenotype& b)
{
return a.val_ok == b.val_ok && b.mse_error == a.mse_error;
}
friend bool operator>=(const phenotype& a, const phenotype& b)
{
return !(a < b);
}
friend bool operator>(const phenotype& a, const phenotype& b)
{
return (!(a == b)) && (!(a < b));
}
friend ostream& operator<<(ostream& os, const phenotype& p)
{
@ -69,6 +86,7 @@ struct phenotype
}
};
unsigned phenotype::trn_max = 0, phenotype::val_max = 0, phenotype::tst_max = 0;
//-----------------------------------------------------------------------------
@ -121,7 +139,21 @@ public:
// global variables
//-----------------------------------------------------------------------------
mlp::set trn_set, val_set, tst_set;
mlp::set *trn_set = 0, *val_set = 0, *tst_set = 0;
void gprop_use_datasets(mlp::set *trn, mlp::set *val, mlp::set *tst) {
trn_set = trn;
val_set = val;
tst_set = tst;
}
void ensure_datasets_initialized() {
if (!trn_set) {
cerr << "trn_set is not initialized. Must call gprop_use_datasets before training\n";
cerr.flush();
abort();
}
}
//-----------------------------------------------------------------------------
// eoChromMutation
@ -133,7 +165,7 @@ public:
bool operator()(Chrom& chrom)
{
mse::net tmp(chrom);
tmp.train(trn_set, 10, 0, 0.001);
tmp.train(*trn_set, 10, 0, 0.001);
return true;
}
};
@ -151,8 +183,9 @@ public:
chrom2.desaturate();
mse::net tmp1(chrom1), tmp2(chrom2);
tmp1.train(trn_set, 100, 0, 0.001);
tmp2.train(trn_set, 100, 0, 0.001);
ensure_datasets_initialized();
tmp1.train(*trn_set, 100, 0, 0.001);
tmp2.train(*trn_set, 100, 0, 0.001);
return true;
}
@ -162,11 +195,11 @@ public:
// eoChromEvaluator
//-----------------------------------------------------------------------------
unsigned correct(const mlp::net& net, const qp::set& set)
unsigned correct(const mlp::net& net, const mlp::set& set)
{
unsigned sum = 0;
for (qp::set::const_iterator s = set.begin(); s != set.end(); ++s)
for (mlp::set::const_iterator s = set.begin(); s != set.end(); ++s)
{
unsigned partial = 0;
@ -185,10 +218,11 @@ unsigned correct(const mlp::net& net, const qp::set& set)
phenotype eoChromEvaluator(const Chrom& chrom)
{
phenotype p;
p.trn_ok = correct(chrom, trn_set);
p.val_ok = correct(chrom, val_set);
p.tst_ok = correct(chrom, tst_set);
p.mse_error = mse::error(chrom, val_set);
ensure_datasets_initialized();
p.trn_ok = correct(chrom, *trn_set);
p.val_ok = correct(chrom, *val_set);
p.tst_ok = correct(chrom, *tst_set);
p.mse_error = mse::error(chrom, *val_set);
return p;
};