Adjust code to perform to C++ standard according to gcc-3.4
interpretation... (Have not compiled/checked/changed paradisEO.) That is, the current code compiles with gcc-3.4 and the checks (besides t-MGE1bit) all pass.
This commit is contained in:
parent
faaadf7599
commit
85a326c5e4
35 changed files with 1057 additions and 864 deletions
|
|
@ -48,7 +48,7 @@ namespace std {
|
|||
copy(v.begin(), v.end(), oi);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
istream& operator>>(istream& is, mlp::vector& v)
|
||||
{
|
||||
for (mlp::vector::iterator vi = v.begin() ; vi != v.end() ; vi++) {
|
||||
|
|
@ -63,8 +63,8 @@ namespace mlp
|
|||
//---------------------------------------------------------------------------
|
||||
// useful typedefs
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
const real max_real = MLP_MAXFLOAT;
|
||||
const real min_real = MLP_MINFLOAT;
|
||||
|
||||
|
|
@ -72,38 +72,38 @@ namespace mlp
|
|||
//---------------------------------------------------------------------------
|
||||
// sigmoid
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
real sigmoid(const real& x)
|
||||
{
|
||||
return 1.0 / (1.0 + exp(-x));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// neuron
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
struct neuron
|
||||
{
|
||||
real bias;
|
||||
vector weight;
|
||||
|
||||
|
||||
neuron(const unsigned& num_inputs = 0): weight(num_inputs) {}
|
||||
|
||||
|
||||
void reset()
|
||||
{
|
||||
normal_generator<real> rnd(1.0);
|
||||
bias = rnd();
|
||||
generate(weight.begin(), weight.end(), rnd);
|
||||
}
|
||||
|
||||
|
||||
real operator()(const vector& input) const
|
||||
{
|
||||
return sigmoid(bias + weight * input);
|
||||
}
|
||||
|
||||
unsigned length() const { return weight.size() + 1; }
|
||||
|
||||
|
||||
void normalize()
|
||||
{
|
||||
real n = sqrt(bias * bias + weight * weight);
|
||||
|
|
@ -114,7 +114,7 @@ namespace mlp
|
|||
void desaturate()
|
||||
{
|
||||
bias = -5.0 + 10.0 / (1.0 + exp(bias / -5.0));
|
||||
|
||||
|
||||
for (vector::iterator w = weight.begin(); w != weight.end(); ++w)
|
||||
*w = -5.0 + 10.0 / (1.0 + exp(*w / -5.0));
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ namespace mlp
|
|||
|
||||
void perturb(double magnitude = 0.3, double probability = 1.0)
|
||||
{
|
||||
|
||||
|
||||
for (vector::iterator w = weight.begin(); w != weight.end(); ++w)
|
||||
if ( probability >= 1.0 || drand48() < probability)
|
||||
perturb_num(*w, magnitude);
|
||||
|
|
@ -143,7 +143,7 @@ namespace std {
|
|||
{
|
||||
return os << n.bias << " " << n.weight;
|
||||
}
|
||||
|
||||
|
||||
istream& operator>>(istream& is, mlp::neuron& n)
|
||||
{
|
||||
return is >> n.bias >> n.weight;
|
||||
|
|
@ -152,15 +152,15 @@ namespace std {
|
|||
}
|
||||
|
||||
namespace mlp {
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// layer
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class layer: public std::vector<neuron>
|
||||
{
|
||||
public:
|
||||
layer(const unsigned& num_inputs = 0, const unsigned& num_neurons = 0):
|
||||
layer(const unsigned& num_inputs = 0, const unsigned& num_neurons = 0):
|
||||
std::vector<neuron>(num_neurons, neuron(num_inputs)) {}
|
||||
|
||||
void reset()
|
||||
|
|
@ -169,11 +169,11 @@ namespace mlp {
|
|||
for(iterator n = begin(); n != end(); ++n)
|
||||
n->reset();
|
||||
}
|
||||
|
||||
|
||||
vector operator()(const vector& input) const
|
||||
{
|
||||
vector output(size());
|
||||
|
||||
|
||||
for(unsigned i = 0; i < output.size(); ++i)
|
||||
output[i] = (*this)[i](input);
|
||||
|
||||
|
|
@ -212,7 +212,7 @@ namespace std {
|
|||
copy(l.begin(), l.end(), oi);
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
istream& operator>>(istream& is, mlp::layer& l)
|
||||
{
|
||||
for (mlp::layer::iterator li = l.begin() ; li != l.end() ; li++) {
|
||||
|
|
@ -224,7 +224,7 @@ namespace std {
|
|||
}
|
||||
|
||||
namespace mlp {
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// net
|
||||
|
|
@ -234,7 +234,7 @@ namespace mlp {
|
|||
{
|
||||
public:
|
||||
net(const unsigned& num_inputs = 0,
|
||||
const unsigned& num_outputs = 0,
|
||||
const unsigned& num_outputs = 0,
|
||||
const std::vector<unsigned>& hidden = std::vector<unsigned>())
|
||||
{
|
||||
init(num_inputs,num_outputs,hidden);
|
||||
|
|
@ -272,8 +272,8 @@ namespace mlp {
|
|||
assert(c == '>');
|
||||
}
|
||||
|
||||
void init( unsigned num_inputs,
|
||||
unsigned num_outputs,
|
||||
void init( unsigned num_inputs,
|
||||
unsigned num_outputs,
|
||||
const std::vector<unsigned>& hidden ) {
|
||||
clear();
|
||||
switch(hidden.size())
|
||||
|
|
@ -317,21 +317,21 @@ namespace mlp {
|
|||
|
||||
unsigned num_inputs() const { return front().front().length() - 1; }
|
||||
unsigned num_outputs() const { return back().size(); }
|
||||
unsigned num_hidden_layers() const {
|
||||
signed s = (signed) size() -1;
|
||||
unsigned num_hidden_layers() const {
|
||||
signed s = (signed) size() -1;
|
||||
return (s<0) ? 0 : s ;
|
||||
}
|
||||
|
||||
|
||||
unsigned length()
|
||||
unsigned length()
|
||||
{
|
||||
unsigned sum = 0;
|
||||
|
||||
for(iterator l = begin(); l != end(); ++l)
|
||||
sum += l->length();
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
void normalize()
|
||||
{
|
||||
|
|
@ -356,38 +356,38 @@ namespace mlp {
|
|||
vector net::operator()(const vector& input) const
|
||||
{
|
||||
vector tmp = input;
|
||||
|
||||
|
||||
for(const_iterator l = begin(); l != end(); ++l)
|
||||
tmp = (*l)(tmp);
|
||||
|
||||
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// sample
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
||||
struct sample
|
||||
{
|
||||
vector input, output;
|
||||
|
||||
|
||||
sample(unsigned input_size = 0, unsigned output_size = 0):
|
||||
input(input_size), output(output_size) {}
|
||||
};
|
||||
|
||||
|
||||
istream& operator>>(istream& is, sample& s)
|
||||
{
|
||||
return is >> s.input >> s.output;
|
||||
}
|
||||
|
||||
|
||||
ostream& operator<<(ostream& os, const sample& s)
|
||||
{
|
||||
return os << s.input << " " << s.output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// set
|
||||
//---------------------------------------------------------------------------
|
||||
|
|
@ -395,8 +395,8 @@ namespace mlp {
|
|||
class set: public std::vector<sample>
|
||||
{
|
||||
public:
|
||||
set(unsigned input_size = 0, unsigned output_size = 0,
|
||||
unsigned num_samples = 0):
|
||||
set(unsigned input_size = 0, unsigned output_size = 0,
|
||||
unsigned num_samples = 0):
|
||||
std::vector<sample>(num_samples, sample(input_size, output_size)) {}
|
||||
|
||||
set(istream& is) : std::vector<sample>(0, sample(0, 0)) {
|
||||
|
|
@ -433,9 +433,9 @@ namespace mlp {
|
|||
{
|
||||
real sum = 0;
|
||||
|
||||
for(net::const_reverse_iterator l1 = n1.rbegin(), l2 = n2.rbegin();
|
||||
for(net::const_reverse_iterator l1 = n1.rbegin(), l2 = n2.rbegin();
|
||||
l1 != n1.rend() && l2 != n2.rend(); ++l1, ++l2)
|
||||
for(layer::const_iterator n1 = l1->begin(), n2 = l2->begin();
|
||||
for(layer::const_iterator n1 = l1->begin(), n2 = l2->begin();
|
||||
n1 != l1->end() && n2 != l2->end(); ++n1, ++n2)
|
||||
{
|
||||
real b = n1->bias - n2->bias;
|
||||
|
|
@ -462,6 +462,7 @@ namespace mlp {
|
|||
|
||||
#endif // mlp_h
|
||||
|
||||
// Local Variables:
|
||||
// mode:C++
|
||||
// Local Variables:
|
||||
// mode:C++
|
||||
// c-file-style: "Stroustrup"
|
||||
// End:
|
||||
|
|
|
|||
Reference in a new issue