Added weight perturbation operators to enable implementation of
exact GPROP-III algorithm.
This commit is contained in:
parent
aecd7bdf2b
commit
7863168b69
1 changed files with 30 additions and 1 deletions
|
|
@ -105,7 +105,23 @@ namespace mlp
|
||||||
for (vector::iterator w = weight.begin(); w != weight.end(); ++w)
|
for (vector::iterator w = weight.begin(); w != weight.end(); ++w)
|
||||||
*w = -5.0 + 10.0 / (1.0 + exp(*w / -5.0));
|
*w = -5.0 + 10.0 / (1.0 + exp(*w / -5.0));
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
void perturb_num(double &num, double magnitude) {
|
||||||
|
double scale = max(num, 0.05) * magnitude;
|
||||||
|
double perturbation = scale * (drand48() - 0.5);
|
||||||
|
num += perturbation;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
if ( probability >= 1.0 || drand48() < probability)
|
||||||
|
perturb_num(bias, magnitude);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace std {
|
namespace std {
|
||||||
|
|
@ -164,6 +180,13 @@ namespace mlp {
|
||||||
for(iterator n = begin(); n != end(); ++n)
|
for(iterator n = begin(); n != end(); ++n)
|
||||||
n->desaturate();
|
n->desaturate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void perturb(double magnitude = 0.3, double probability = 1.0)
|
||||||
|
{
|
||||||
|
for(iterator n = begin(); n != end(); ++n)
|
||||||
|
n->perturb();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -306,6 +329,12 @@ namespace mlp {
|
||||||
for(iterator l = begin(); l != end(); ++l)
|
for(iterator l = begin(); l != end(); ++l)
|
||||||
l->desaturate();
|
l->desaturate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void perturb(double magnitude = 0.3, double probability = 1.0)
|
||||||
|
{
|
||||||
|
for(iterator l = begin(); l != end(); ++l)
|
||||||
|
l->perturb();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifndef NO_MLP_VIRTUALS
|
#ifndef NO_MLP_VIRTUALS
|
||||||
|
|
|
||||||
Reference in a new issue