Update for gcc-4.3 compatibility

This commit is contained in:
kuepper 2008-03-31 19:11:13 +00:00
commit 0388f95758
11 changed files with 152 additions and 130 deletions

View file

@ -3,7 +3,7 @@
//-----------------------------------------------------------------------------
#include <stdlib.h> // EXIT_SUCCESS EXIT_FAILURE
#include <stdexcept> // exception
#include <stdexcept> // exception
#include <iostream> // cerr cout
#include <fstream> // ifstream
#include <string> // string
@ -35,7 +35,7 @@ eoValueParam<unsigned> hiddenp(0, "hidden", "number of neurons in hidden layer",
//-----------------------------------------------------------------------------
void arg(int argc, char** argv);
void load_file(mlp::set& s, const string& s);
void load_file(mlp::set& s1, const string& s2);
void ga();
//-----------------------------------------------------------------------------
@ -65,7 +65,7 @@ int main(int argc, char** argv)
void arg(int argc, char** argv)
{
eoParser parser(argc, argv);
parser.processParam(pop_size, "genetic operators");
parser.processParam(generations, "genetic operators");
parser.processParam(mut_rate, "genetic operators");
@ -82,7 +82,7 @@ void arg(int argc, char** argv)
load_file(train, "trn");
load_file(validate, "val");
load_file(test, "tst");
phenotype::trn_max = train.size();
phenotype::val_max = validate.size();
phenotype::tst_max = test.size();
@ -104,8 +104,8 @@ void load_file(mlp::set& set, const string& ext)
{
cerr << "can't open file \"" << filename << "\"" << endl;
exit(EXIT_FAILURE);
}
}
ifs >> set;
if (set.size() == 0)
@ -122,18 +122,18 @@ void ga()
// create population
eoInitChrom init;
eoPop<Chrom> pop(pop_size.value(), init);
// evaluate population
eoEvalFuncPtr<Chrom> evaluator(eoChromEvaluator);
apply<Chrom>(evaluator, pop);
// selector
eoStochTournamentSelect<Chrom> select;
// genetic operators
eoChromMutation mutation;
eoChromXover xover;
// stop condition
eoGenContinue<Chrom> continuator1(generations.value());
phenotype p; p.val_ok = validate.size() - 1; p.mse_error = 0;
@ -142,23 +142,23 @@ void ga()
// checkpoint
eoCheckPoint<Chrom> checkpoint(continuator);
// monitor
eoStdoutMonitor monitor;
checkpoint.add(monitor);
// statistics
eoBestFitnessStat<Chrom> stats;
checkpoint.add(stats);
monitor.add(stats);
// genetic algorithm
eoSGA<Chrom> sga(select,
xover, xover_rate.value(),
mutation, mut_rate.value(),
evaluator,
xover, xover_rate.value(),
mutation, mut_rate.value(),
evaluator,
checkpoint);
sga(pop);
cout << "best: " << *max_element(pop.begin(), pop.end()) << endl;
@ -166,6 +166,6 @@ void ga()
//-----------------------------------------------------------------------------
// Local Variables:
// Local Variables:
// mode:C++
// End:

View file

@ -52,12 +52,12 @@ struct phenotype
friend bool operator<(const phenotype& a, const phenotype& b)
{
return a.val_ok < b.val_ok || !(b.val_ok < a.val_ok) && b.mse_error < a.mse_error;
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;
return (a.val_ok == b.val_ok) && (b.mse_error == a.mse_error);
}
friend bool operator>=(const phenotype& a, const phenotype& b)
@ -69,9 +69,9 @@ struct phenotype
{
return (!(a == b)) && (!(a < b));
}
friend std::ostream& operator<<(std::ostream& os, const phenotype& p)
{
return os << p.trn_ok << "/" << p.trn_max << " "
@ -79,7 +79,7 @@ struct phenotype
<< p.tst_ok << "/" << p.tst_max << " "
<< p.mse_error;
}
friend std::istream& operator>>(std::istream& is, phenotype& p)
{
return is; // complete me
@ -111,14 +111,14 @@ public:
std::string className() const { return "Chrom"; }
void printOn (std::ostream& os) const
{
os << std::setprecision(3) << static_cast<genotype>(*this) << " \t"
<< fitness();
void printOn (std::ostream& os) const
{
os << std::setprecision(3) << static_cast<genotype>(*this) << " \t"
<< fitness();
// os << fitness();
}
void readFrom (std::istream& is)
void readFrom (std::istream& is)
{
invalidate(); // complete me
}
@ -201,16 +201,16 @@ public:
int correct(const mlp::net& net, const mlp::set& set)
{
int sum = 0;
for (mlp::set::const_iterator s = set.begin(); s != set.end(); ++s)
{
unsigned partial = 0;
for (unsigned i = 0; i < s->output.size(); ++i)
if (s->output[i] < 0.5 && net(s->input)[i] < 0.5 ||
s->output[i] > 0.5 && net(s->input)[i] > 0.5)
++partial;
if (partial == s->output.size())
++sum;
}
@ -234,6 +234,6 @@ phenotype eoChromEvaluator(const Chrom& chrom)
#endif // gprop_h
// Local Variables:
// mode:C++
// Local Variables:
// mode:C++
// End: