8 #include "InitUniformRandomWeights.hpp" 12 InitUniformRandomWeights::InitUniformRandomWeights(
char const *name, HyPerCol *hc) {
16 InitUniformRandomWeights::InitUniformRandomWeights() {}
18 InitUniformRandomWeights::~InitUniformRandomWeights() {}
20 int InitUniformRandomWeights::initialize(
char const *name, HyPerCol *hc) {
21 int status = InitRandomWeights::initialize(name, hc);
27 ioParam_wMinInit(ioFlag);
28 ioParam_wMaxInit(ioFlag);
29 ioParam_sparseFraction(ioFlag);
30 ioParam_minNNZ(ioFlag);
34 void InitUniformRandomWeights::ioParam_wMinInit(
enum ParamsIOFlag ioFlag) {
35 parent->parameters()->ioParamValue(ioFlag, name,
"wMinInit", &mWMin, mWMin);
38 void InitUniformRandomWeights::ioParam_wMaxInit(
enum ParamsIOFlag ioFlag) {
39 parent->parameters()->ioParamValue(ioFlag, name,
"wMaxInit", &mWMax, mWMax);
42 void InitUniformRandomWeights::ioParam_sparseFraction(
enum ParamsIOFlag ioFlag) {
43 parent->parameters()->ioParamValue(
44 ioFlag, name,
"sparseFraction", &mSparseFraction, mSparseFraction);
47 void InitUniformRandomWeights::ioParam_minNNZ(
enum ParamsIOFlag ioFlag) {
48 parent->parameters()->ioParamValue(ioFlag, name,
"minNNZ", &mMinNNZ, mMinNNZ);
60 "uniformWeights maximum less than minimum. Changing max = %f to min value of %f\n",
68 p = (double)(mWMax - mWMin) / (1.0 + (double)CL_RANDOM_MAX);
70 float sparseFraction = mSparseFraction * (float)(1.0 + (
double)CL_RANDOM_MAX);
77 const int patchSize = nxp * nyp * nfp;
80 int zeroesLeft = patchSize - mMinNNZ;
87 startIndex = mRandState->randomUInt(patchIndex) % patchSize;
90 for (
int n = 0; n < patchSize; n++) {
91 float data = (mWMin + (float)(p * (
double)mRandState->randomUInt(patchIndex)));
92 if (zeroesLeft > 0 && (
double)mRandState->randomUInt(patchIndex) < (double)sparseFraction) {
96 patchDataStart[(n + startIndex) % patchSize] = data;
int getPatchSizeX() const
int getPatchSizeY() const
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
int getPatchSizeF() const