diff --git a/eo/app/gprop/gprop.cpp b/eo/app/gprop/gprop.cpp index 10871d21..3b977d5c 100644 --- a/eo/app/gprop/gprop.cpp +++ b/eo/app/gprop/gprop.cpp @@ -1,7 +1,6 @@ //----------------------------------------------------------------------------- // gprop //----------------------------------------------------------------------------- -using namespace std; #include // EXIT_SUCCESS EXIT_FAILURE #include // exception @@ -11,6 +10,8 @@ using namespace std; #include // all usefull eo stuff #include "gprop.h" // Chrom eoChromInit eoChromMutation eoChromXover eoChromEvaluator +using namespace std; + //----------------------------------------------------------------------------- // global variables //----------------------------------------------------------------------------- diff --git a/eo/app/gprop/gprop.h b/eo/app/gprop/gprop.h index 60e3bce6..794fcc4b 100644 --- a/eo/app/gprop/gprop.h +++ b/eo/app/gprop/gprop.h @@ -72,7 +72,7 @@ struct phenotype - friend ostream& operator<<(ostream& os, const phenotype& p) + friend std::ostream& operator<<(std::ostream& os, const phenotype& p) { return os << p.trn_ok << "/" << p.trn_max << " " << p.val_ok << "/" << p.val_max << " " @@ -80,7 +80,7 @@ struct phenotype << p.mse_error; } - friend istream& operator>>(istream& is, phenotype& p) + friend std::istream& operator>>(std::istream& is, phenotype& p) { return is; // complete me } @@ -107,18 +107,18 @@ extern unsigned in, out, hidden; class Chrom: public EO, public genotype { public: - Chrom(): genotype(in, out, vector(hidden < 1 ? 0 : 1, hidden)) {} + Chrom(): genotype(in, out, std::vector(hidden < 1 ? 0 : 1, hidden)) {} - string className() const { return "Chrom"; } + std::string className() const { return "Chrom"; } - void printOn (ostream& os) const + void printOn (std::ostream& os) const { - os << setprecision(3) << static_cast(*this) << " \t" + os << std::setprecision(3) << static_cast(*this) << " \t" << fitness(); // os << fitness(); } - void readFrom (istream& is) + void readFrom (std::istream& is) { invalidate(); // complete me } @@ -152,8 +152,8 @@ void gprop_use_datasets(mlp::set *trn, mlp::set *val, mlp::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(); + std::cerr << "trn_set is not initialized. Must call gprop_use_datasets before training\n"; + std::cerr.flush(); abort(); } } diff --git a/eo/app/gprop/mlp.h b/eo/app/gprop/mlp.h index a674f576..b05f8c24 100644 --- a/eo/app/gprop/mlp.h +++ b/eo/app/gprop/mlp.h @@ -19,7 +19,6 @@ - namespace mlp { using namespace std; @@ -111,7 +110,7 @@ namespace mlp void perturb_num(double &num, double magnitude) { double scale = max(num, 0.05) * magnitude; - double perturbation = scale * (drand48() - 0.5); + double perturbation = scale * (rng.uniform() - 0.5); num += perturbation; } @@ -119,9 +118,9 @@ namespace mlp { for (vector::iterator w = weight.begin(); w != weight.end(); ++w) - if ( probability >= 1.0 || drand48() < probability) + if ( probability >= 1.0 || rng.uniform() < probability) perturb_num(*w, magnitude); - if ( probability >= 1.0 || drand48() < probability) + if ( probability >= 1.0 || rng.uniform() < probability) perturb_num(bias, magnitude); } }; diff --git a/eo/app/gprop/qp.h b/eo/app/gprop/qp.h index e9142562..068d1382 100644 --- a/eo/app/gprop/qp.h +++ b/eo/app/gprop/qp.h @@ -78,7 +78,7 @@ namespace qp } }; - ostream& operator<<(ostream& os, const neuron& n) + std::ostream& operator<<(std::ostream& os, const neuron& n) { return os << *n.n << " " << n.out << " " << n.delta << " " << n.ndelta << " " << n.dbias1 << " " << n.dbias2 << " " @@ -164,7 +164,7 @@ namespace qp else { eta *= backtrack_step; - eta = max(eta, eta_floor); + eta = std::max(eta, eta_floor); momentum = eta * lambda; weight_update(ts.size(), false, eta, momentum); error_ = last_error; @@ -206,15 +206,15 @@ namespace qp ew += n->dxo * n->dweight1; } - me = max(static_cast(sqrt(me)), me_floor); - mw = max(static_cast(sqrt(mw)), mw_floor); + me = std::max(static_cast(sqrt(me)), me_floor); + mw = std::max(static_cast(sqrt(mw)), mw_floor); eta *= (1.0 + 0.5 * ew / ( me * mw)); - eta = max(eta, eta_floor); + eta = std::max(eta, eta_floor); lambda = lambda0 * me / mw; momentum = eta * lambda; #ifdef DEBUG - cout << me << " \t" << mw << " \t" << ew << " \t" - << eta << " \t" << momentum << " \t" << lambda << endl; + std::cout << me << " \t" << mw << " \t" << ew << " \t" + << eta << " \t" << momentum << " \t" << lambda << std::endl; #endif // DEBUG } diff --git a/eo/app/gprop/vecop.h b/eo/app/gprop/vecop.h index 7cd5a609..2654f2b1 100644 --- a/eo/app/gprop/vecop.h +++ b/eo/app/gprop/vecop.h @@ -13,139 +13,139 @@ #include // inner_product //----------------------------------------------------------------------------- -// vector + vector +// std::vector + std::vector //----------------------------------------------------------------------------- -template vector operator+(const vector& v1, const vector& v2) +template std::vector operator+(const std::vector& v1, const std::vector& v2) { - vector tmp = v1; - transform(tmp.begin(), tmp.end(), v2.begin(), tmp.begin(), plus()); + std::vector tmp = v1; + std::transform(tmp.begin(), tmp.end(), v2.begin(), tmp.begin(), std::plus()); return tmp; } -template vector operator-(const vector& v1, const vector& v2) +template std::vector operator-(const std::vector& v1, const std::vector& v2) { - vector tmp = v1; - transform(tmp.begin(), tmp.end(), v2.begin(), tmp.begin(), minus()); + std::vector tmp = v1; + std::transform(tmp.begin(), tmp.end(), v2.begin(), tmp.begin(), std::minus()); return tmp; } -template T operator*(const vector& v1, const vector& v2) +template T operator*(const std::vector& v1, const std::vector& v2) { return inner_product(v1.begin(), v1.end(), v2.begin(), static_cast(0)); } -template T operator/(const vector& v1, const vector& v2) +template T operator/(const std::vector& v1, const std::vector& v2) { return inner_product(v1.begin(), v1.end(), v2.begin(), static_cast(0), - plus(), divides()); + std::plus(), std::divides()); } //----------------------------------------------------------------------------- -// vector += vector +// std::vector += std::vector //----------------------------------------------------------------------------- -template vector& operator+=(vector& v1, const vector& v2) +template std::vector& operator+=(std::vector& v1, const std::vector& v2) { - transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), plus()); + std::transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), std::plus()); return v1; } -template vector& operator-=(vector& v1, const vector& v2) +template std::vector& operator-=(std::vector& v1, const std::vector& v2) { - transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), minus()); + std::transform(v1.begin(), v1.end(), v2.begin(), v1.begin(), std::minus()); return v1; } //----------------------------------------------------------------------------- -// vector + number +// std::vector + number //----------------------------------------------------------------------------- -template vector operator+(const vector& a, const B& b) +template std::vector operator+(const std::vector& a, const B& b) { - vector tmp = a; - transform(tmp.begin(), tmp.end(), tmp.begin(), bind2nd(plus(), b)); + std::vector tmp = a; + std::transform(tmp.begin(), tmp.end(), tmp.begin(), std::bind2nd(std::plus(), b)); return tmp; } -template vector operator-(const vector& a, const B& b) +template std::vector operator-(const std::vector& a, const B& b) { - vector tmp = a; - transform(tmp.begin(), tmp.end(), tmp.begin(), bind2nd(minus(), b)); + std::vector tmp = a; + std::transform(tmp.begin(), tmp.end(), tmp.begin(), std::bind2nd(std::minus(), b)); return tmp; } -template vector operator*(const vector& a, const B& b) +template std::vector operator*(const std::vector& a, const B& b) { - vector tmp = a; - transform(tmp.begin(), tmp.end(), tmp.begin(), bind2nd(multiplies(), b)); + std::vector tmp = a; + std::transform(tmp.begin(), tmp.end(), tmp.begin(), std::bind2nd(std::multiplies(), b)); return tmp; } -template vector operator/(const vector& a, const B& b) +template std::vector operator/(const std::vector& a, const B& b) { - vector tmp = a; - transform(tmp.begin(), tmp.end(), tmp.begin(), bind2nd(divides(), b)); + std::vector tmp = a; + std::transform(tmp.begin(), tmp.end(), tmp.begin(), std::bind2nd(std::divides(), b)); return tmp; } //----------------------------------------------------------------------------- -// number + vector +// number + std::vector //----------------------------------------------------------------------------- -template vector operator+(const B& b, const vector& a) +template std::vector operator+(const B& b, const std::vector& a) { - vector tmp = a; - transform(tmp.begin(), tmp.end(), tmp.begin(), bind2nd(plus(), b)); + std::vector tmp = a; + std::transform(tmp.begin(), tmp.end(), tmp.begin(), std::bind2nd(std::plus(), b)); return tmp; } -template vector operator-(const B& b, const vector& a) +template std::vector operator-(const B& b, const std::vector& a) { - vector tmp(a.size(), b); - transform(tmp.begin(), tmp.end(), a.begin(), tmp.begin(), minus()); + std::vector tmp(a.size(), b); + std::transform(tmp.begin(), tmp.end(), a.begin(), tmp.begin(), std::minus()); return tmp; } -template vector operator*(const B& b, const vector& a) +template std::vector operator*(const B& b, const std::vector& a) { - vector tmp = a; - transform(tmp.begin(), tmp.end(), tmp.begin(), bind2nd(multiplies(), b)); + std::vector tmp = a; + std::transform(tmp.begin(), tmp.end(), tmp.begin(), bind2nd(std::multiplies(), b)); return tmp; } -template vector operator/(const B& b, const vector& a) +template std::vector operator/(const B& b, const std::vector& a) { - vector tmp(a.size(), b); - transform(tmp.begin(), tmp.end(), a.begin(), tmp.begin(), divides()); + std::vector tmp(a.size(), b); + std::transform(tmp.begin(), tmp.end(), a.begin(), tmp.begin(), std::divides()); return tmp; } //----------------------------------------------------------------------------- -// vector += number +// std::vector += number //----------------------------------------------------------------------------- -template vector& operator+=(vector& a, const B& b) +template std::vector& operator+=(std::vector& a, const B& b) { - transform(a.begin(), a.end(), a.begin(), bind2nd(plus(), b)); + std::transform(a.begin(), a.end(), a.begin(), std::bind2nd(std::plus(), b)); return a; } -template vector& operator-=(vector& a, const B& b) +template std::vector& operator-=(std::vector& a, const B& b) { - transform(a.begin(), a.end(), a.begin(), bind2nd(minus(), b)); + std::transform(a.begin(), a.end(), a.begin(), std::bind2nd(std::minus(), b)); return a; } -template vector& operator*=(vector& a, const B& b) +template std::vector& operator*=(std::vector& a, const B& b) { - transform(a.begin(), a.end(), a.begin(), bind2nd(multiplies(), b)); + std::transform(a.begin(), a.end(), a.begin(), std::bind2nd(std::multiplies(), b)); return a; } -template vector& operator/=(vector& a, const B& b) +template std::vector& operator/=(std::vector& a, const B& b) { - transform(a.begin(), a.end(), a.begin(), bind2nd(divides(), b)); + std::transform(a.begin(), a.end(), a.begin(), std::bind2nd(std::divides(), b)); return a; } @@ -153,25 +153,25 @@ template vector& operator/=(vector& a, const B& b) // I/O //----------------------------------------------------------------------------- -template ostream& operator<<(ostream& os, const vector& v) +template std::ostream& operator<<(std::ostream& os, const std::vector& v) { os << '<'; if (v.size()) { - copy(v.begin(), v.end() - 1, ostream_iterator(os, " ")); + std::copy(v.begin(), v.end() - 1, std::ostream_iterator(os, " ")); os << v.back(); } return os << '>'; } -template istream& operator>>(istream& is, vector& v) +template std::istream& operator>>(std::istream& is, std::vector& v) { v.clear(); char c; is >> c; if (!is || c != '<') - is.setstate(ios::failbit); + is.setstate(std::ios::failbit); else { T t; @@ -194,8 +194,8 @@ template istream& operator>>(istream& is, vector& v) // euclidean_distance //----------------------------------------------------------------------------- -template T euclidean_distance(const vector& v1, - const vector& v2) +template T euclidean_distance(const std::vector& v1, + const std::vector& v2) { T sum = 0, tmp;