From 7863168b69e2abe78cfd31cbc2d2ea912253a2bc Mon Sep 17 00:00:00 2001 From: stevemadere Date: Fri, 23 Apr 2004 16:20:12 +0000 Subject: [PATCH] Added weight perturbation operators to enable implementation of exact GPROP-III algorithm. --- eo/app/gprop/mlp.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/eo/app/gprop/mlp.h b/eo/app/gprop/mlp.h index e0e706a3..544935d7 100644 --- a/eo/app/gprop/mlp.h +++ b/eo/app/gprop/mlp.h @@ -105,7 +105,23 @@ namespace mlp for (vector::iterator w = weight.begin(); w != weight.end(); ++w) *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 { @@ -164,6 +180,13 @@ namespace mlp { for(iterator n = begin(); n != end(); ++n) 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) 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