/// update - Recompute Value from Bias and Links. Return true when node /// preference changes. bool update(const Node nodes[]) { // Compute the weighted sum of inputs. float Sum = Bias; for (LinkVector::iterator I = Links.begin(), E = Links.end(); I != E; ++I) Sum += I->first * nodes[I->second].Value; // The weighted sum is going to be in the range [-2;2]. Ideally, we should // simply set Value = sign(Sum), but we will add a dead zone around 0 for // two reasons: // 1. It avoids arbitrary bias when all links are 0 as is possible during // initial iterations. // 2. It helps tame rounding errors when the links nominally sum to 0. const float Thres = 1e-4f; bool Before = preferReg(); if (Sum < -Thres) Value = -1; else if (Sum > Thres) Value = 1; else Value = 0; return Before != preferReg(); }