8 #include "GaussianRandom.hpp" 12 GaussianRandom::GaussianRandom(
int count) {
14 initializeFromCount((
unsigned int)count);
17 GaussianRandom::GaussianRandom(
const PVLayerLoc *locptr,
bool isExtended) {
19 initializeFromLoc(locptr, isExtended);
22 GaussianRandom::GaussianRandom() { initialize_base(); }
24 int GaussianRandom::initialize_base() {
return PV_SUCCESS; }
26 int GaussianRandom::initializeGaussian() {
27 int status = PV_SUCCESS;
28 heldValues.assign(rngArray.size(), {
false, 0.0});
32 int GaussianRandom::initializeFromCount(
unsigned int count) {
33 int status = Random::initializeFromCount(count);
34 if (status == PV_SUCCESS) {
35 status = initializeGaussian();
40 int GaussianRandom::initializeFromLoc(
const PVLayerLoc *locptr,
bool isExtended) {
41 int status = Random::initializeFromLoc(locptr, isExtended);
42 if (status == PV_SUCCESS) {
43 status = initializeGaussian();
48 float GaussianRandom::gaussianDist(
int localIndex) {
51 if (bmdata.hasHeldValue) {
57 x1 = 2.0f * uniformRandom(localIndex) - 1.0f;
58 x2 = 2.0f * uniformRandom(localIndex) - 1.0f;
59 w = x1 * x1 + x2 * x2;
62 w = sqrtf((-2.0f * logf(w)) / w);
64 bmdata.heldValue = x2 * w;
66 bmdata.hasHeldValue = !bmdata.hasHeldValue;
71 GaussianRandom::~GaussianRandom() {}