Skip to content

Commit 0036713

Browse files
authored
Add files via upload
1 parent 2bd5ff8 commit 0036713

4 files changed

Lines changed: 46 additions & 16 deletions

File tree

nQuantCpp/DblGNGGAQuantizer.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ namespace GrowingNeuralGas
219219
}
220220

221221
double rotateLR(double u, double v) {
222-
auto theta = randrange(0.0, 2.0 * M_PI);
222+
auto theta = randrange(0.0, 2 * M_PI);
223223
auto result = u * cos(theta) - v * sin(theta);
224224
if (result <= minLR || result >= maxLR) {
225225
auto range = maxLR - minLR;
@@ -241,9 +241,25 @@ namespace GrowingNeuralGas
241241
return child;
242242
}
243243

244+
const double MUTATION_STDDEV_RATIO = 0.15;
244245
double boxMuller(double value, double minValue, double maxValue) {
245-
auto r1 = randrange(minValue, maxValue);
246-
return sqrt(-2 * log(value)) * cos(2 * M_PI * r1);
246+
auto u1 = randrange(0.0, 1.0);
247+
auto u2 = randrange(0.0, 1.0);
248+
249+
if (u1 < 1e-9)
250+
u1 = 1e-9;
251+
252+
auto pureBoxMuller = sqrt(-2 * log(u1))* cos(2 * M_PI * u2);
253+
auto stddev = (maxValue - minValue) * MUTATION_STDDEV_RATIO;
254+
255+
auto result = value + pureBoxMuller * stddev;
256+
if (result < minValue) {
257+
result = minValue;
258+
}
259+
else if (result > maxValue) {
260+
result = maxValue;
261+
}
262+
return result;
247263
}
248264

249265
bool DblGNGGAQuantizer::dominates(const DblGNGGAQuantizer* right) {

nQuantCpp/DblGNGQuantizer.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ namespace GrowingNeuralGas
3131
{0.299f, 0.587f, 0.114f},
3232
{-0.14713f, -0.28886f, 0.436f},
3333
{0.615f, -0.51499f, -0.10001f}
34-
};
35-
36-
unordered_map<int, vector<unsigned short> > closestMap;
37-
unordered_map<int, unsigned short> nearestMap;
34+
};
3835

3936
DblGNGQuantizer::DblGNGQuantizer() : startingPoints(2)
4037
, learningRate(0.002)
@@ -820,11 +817,9 @@ namespace GrowingNeuralGas
820817
}
821818

822819
void DblGNGQuantizer::setParams(double learningRate, int startingPoints) {
823-
#pragma omp critical(QuantizerParamLock)
824-
{
825-
this->learningRate = learningRate;
826-
this->startingPoints = startingPoints;
827-
clear();
828-
}
820+
this->learningRate = learningRate;
821+
this->startingPoints = startingPoints;
822+
closestMap.clear();
823+
nearestMap.clear();
829824
}
830825
}

nQuantCpp/DblGNGQuantizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ namespace GrowingNeuralGas
9797
vector<shared_ptr<GNGNode>> uniqueSamples;
9898
vector<shared_ptr<GNGNode>> stdDevSamples;
9999
unordered_map<uint32_t, int> histogram;
100+
101+
unordered_map<int, vector<unsigned short> > closestMap;
102+
unordered_map<int, unsigned short> nearestMap;
100103

101104
void insertNewNodeWeighted(unordered_map<shared_ptr<GNGNode>, vector<shared_ptr<GNGNode>>, SharedPtrHash>& assignments);
102105
void updateNodeWeightsAdaptive(unordered_map<shared_ptr<GNGNode>, vector<shared_ptr<GNGNode>>, SharedPtrHash>& assignments,

nQuantCpp/PnnLABGAQuantizer.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,9 +256,25 @@ namespace PnnLABQuant
256256
return child;
257257
}
258258

259-
static double boxMuller(double value) {
260-
auto r1 = randrange(minRatio, maxRatio);
261-
return sqrt(-2 * log(value)) * cos(2 * M_PI * r1);
259+
const double MUTATION_STDDEV_RATIO = 0.15;
260+
double boxMuller(double value) {
261+
auto u1 = randrange(0.0, 1.0);
262+
auto u2 = randrange(0.0, 1.0);
263+
264+
if (u1 < 1e-9)
265+
u1 = 1e-9;
266+
267+
auto pureBoxMuller = sqrt(-2 * log(u1)) * cos(2 * M_PI * u2);
268+
auto stddev = (maxRatio - minRatio) * MUTATION_STDDEV_RATIO;
269+
270+
auto result = value + pureBoxMuller * stddev;
271+
if (result < minRatio) {
272+
result = minRatio;
273+
}
274+
else if (result > maxRatio) {
275+
result = maxRatio;
276+
}
277+
return result;
262278
}
263279

264280
bool PnnLABGAQuantizer::dominates(const PnnLABGAQuantizer* right) {

0 commit comments

Comments
 (0)