Skip to content

Commit 2b21175

Browse files
committed
SP implement log, exp, none boosting methods
1 parent 3883687 commit 2b21175

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/examples/mnist/MNIST_SP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ class MNIST {
7272

7373
void setup() {
7474

75-
input.initialize({28, 28,1});
76-
columns.initialize({28, 28, 16}); //1D vs 2D no big difference, 2D seems more natural for the problem. Speed-----, Results+++++++++; #columns HIGHEST impact.
75+
input.initialize({28, 28, 1});
76+
columns.initialize({28, 28, 8}); //1D vs 2D no big difference, 2D seems more natural for the problem. Speed-----, Results+++++++++; #columns HIGHEST impact.
7777
sp.initialize(
7878
/* inputDimensions */ input.dimensions,
7979
/* columnDimensions */ columns.dimensions,

src/htm/algorithms/SpatialPooler.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,14 @@ void applyBoosting_(const UInt i,
758758
const vector<Real>& actualDensity,
759759
const Real boost,
760760
vector<Real>& output) {
761-
//output[i] = exp((targetDensity - actualDensity[i]) * boost); //exponential boosting, default for Numenta
762-
output[i] = log(actualDensity[i]) / log(targetDensity);
761+
762+
if(boost == SpatialPooler::BOOSTING_DISABLED) { //boosting disabled, skip
763+
return;
764+
} else if(boost == SpatialPooler::BOOSTING_LOG) {
765+
output[i] = log2(actualDensity[i]) / log2(targetDensity);
766+
} else { //exponential boost
767+
output[i] = exp((targetDensity - actualDensity[i]) * boost);
768+
}
763769
}
764770

765771

src/htm/algorithms/SpatialPooler.hpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ static const int DISABLED = -1; //value denoting a feature is disabled
6363
class SpatialPooler : public Serializable
6464
{
6565
public:
66+
static const constexpr Real BOOSTING_DISABLED = 0.0f;
67+
static const constexpr Real BOOSTING_LOG = -1234.0f;
68+
6669
SpatialPooler();
6770
SpatialPooler(const vector<UInt> inputDimensions, const vector<UInt> columnDimensions,
6871
UInt potentialRadius = 16u, Real potentialPct = 0.5f,
@@ -185,13 +188,21 @@ class SpatialPooler : public Serializable
185188
boost. Shorter values make it potentially more unstable and
186189
likely to oscillate.
187190
188-
@param boostStrength A number greater or equal than 0, used to
189-
control boosting strength.
190-
No boosting is applied if it is set to 0.0, (runs faster due to skipped code).
191-
The strength of boosting increases as a function of boostStrength.
192-
Boosting encourages columns to have similar activeDutyCycles as their
193-
neighbors, which will lead to more efficient use of columns. However,
194-
too much boosting may also lead to instability of SP outputs.
191+
@param boostStrength A number used to control boosting strength coeficient,
192+
and mode of operation based on (reserved) values:
193+
- `== SpatialPooler::BOOSTING_DISABLED`:
194+
No boosting is applied if it is set, (runs faster due to skipped code).
195+
- `== SpatialPooler::BOOSTING_LOG`:
196+
Logarithmic boosting is used.
197+
- `> 0.0`:
198+
Exponential boosting (default in Numenta) selected. `boostStrength` is
199+
used as a multiplacation constant.
200+
The strength of boosting increases as a function of `boostStrength`.
201+
202+
Boosting encourages columns to have similar `activeDutyCycles` (aka. activation
203+
frequencies) as their neighbors, which will lead to more efficient use of columns.
204+
This helps achieving the target sparsity of the output.
205+
However, too much boosting may also lead to instability of SP outputs.
195206
196207
197208
@param seed Seed for our random number generator. If seed is < 0

0 commit comments

Comments
 (0)