Skip to content

Commit

Permalink
SP: use log boosting
Browse files Browse the repository at this point in the history
does not require parameter
  • Loading branch information
breznak committed Jul 4, 2019
1 parent ba4b61d commit 1be7dcd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CommonCompilerConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ else()
set(optimization_flags_cc ${optimization_flags_cc} -pipe -O3)
set(optimization_flags_lt ${optimization_flags_lt} -O3)
if(NOT ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "armv7l")
set(optimization_flags_cc ${optimization_flags_cc} -mtune=generic)
set(optimization_flags_cc ${optimization_flags_cc} -march=native)
endif()
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" AND NOT MINGW)
set(optimization_flags_cc ${optimization_flags_cc} -fuse-ld=gold)
Expand Down
2 changes: 1 addition & 1 deletion src/examples/mnist/MNIST_SP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class MNIST {

public:
UInt verbosity = 1;
const UInt train_dataset_iterations = 2u; //epochs somewhat help, at linear time
const UInt train_dataset_iterations = 1u; //epochs somewhat help, at linear time


void setup() {
Expand Down
3 changes: 2 additions & 1 deletion src/htm/algorithms/SpatialPooler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,8 @@ void applyBoosting_(const UInt i,
const Real boost,
vector<Real>& output) {
if(boost < htm::Epsilon) return; //skip for disabled boosting
output[i] = exp((targetDensity - actualDensity[i]) * boost); //TODO doc this code
//output[i] = exp((targetDensity - actualDensity[i]) * boost); //exponential boosting, default for Numenta
output[i] = log(actualDensity[i]) / log(targetDensity);
}


Expand Down
28 changes: 9 additions & 19 deletions src/test/unit/algorithms/SpatialPoolerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,24 +980,11 @@ TEST(SpatialPoolerTest, testUpdateBoostFactors) {
sp.getBoostFactors(resultBoostFactors1.data());
ASSERT_TRUE(check_vector_eq(trueBoostFactors1, resultBoostFactors1));

Real32 initActiveDutyCycles2[] = {0.1f, 0.3f, 0.02f, 0.04f, 0.7f, 0.12f};
Real32 initBoostFactors2[] = {0, 0, 0, 0, 0, 0};
vector<Real32> trueBoostFactors2 = {3.10599f, 0.42035f, 6.91251f,
5.65949f, 0.00769898f, 2.54297f};
vector<Real32> resultBoostFactors2(6, 0);
sp.setGlobalInhibition(false);
sp.setBoostStrength(10);
sp.setBoostFactors(initBoostFactors2);
sp.setActiveDutyCycles(initActiveDutyCycles2);
sp.updateBoostFactors_();
sp.getBoostFactors(resultBoostFactors2.data());

ASSERT_TRUE(check_vector_eq(trueBoostFactors2, resultBoostFactors2));

Real32 initActiveDutyCycles3[] = {0.1f, 0.3f, 0.02f, 0.04f, 0.7f, 0.12f};
Real initBoostFactors3[] = {0, 0, 0, 0, 0, 0};
vector<Real32> trueBoostFactors3 = {1.25441f, 0.840857f, 1.47207f,
1.41435f, 0.377822f, 1.20523f};
vector<Real32> trueBoostFactors3 = {1.49044f, 0.779321f, 2.53222f,
2.08355f, 0.230873f, 1.37243f};
vector<Real32> resultBoostFactors3(6, 0);
sp.setWrapAround(true);
sp.setGlobalInhibition(false);
Expand All @@ -1011,10 +998,11 @@ TEST(SpatialPoolerTest, testUpdateBoostFactors) {

ASSERT_TRUE(check_vector_eq(trueBoostFactors3, resultBoostFactors3));


Real32 initActiveDutyCycles4[] = {0.1f, 0.3f, 0.02f, 0.04f, 0.7f, 0.12f};
Real32 initBoostFactors4[] = {0, 0, 0, 0, 0, 0};
vector<Real32> trueBoostFactors4 = {1.94773f, 0.263597f, 4.33476f,
3.549f, 0.00482795f, 1.59467f};
vector<Real32> trueBoostFactors4 = {1.2851f, 0.67195f, 2.18334f,
1.79649f, 0.199064f, 1.18334f};
vector<Real32> resultBoostFactors4(6, 0);
sp.setGlobalInhibition(true);
sp.setBoostStrength(10);
Expand Down Expand Up @@ -2103,14 +2091,16 @@ TEST(SpatialPoolerTest, testConstructorVsInitialize) {
TEST(SpatialPoolerTest, ExactOutput) {
// Silver is an SDR that is loaded by direct initalization from a vector.
SDR silver_sdr({ 200 });
SDR_sparse_t data = {23, 71, 113, 118, 129, 172, 178, 182, 185, 190};
SDR_sparse_t data = {
12, 51, 81, 113, 129, 133, 172, 175, 178, 190
};
silver_sdr.setSparse(data);


// Gold tests initalizing an SDR from a manually created string in JSON format.
// hint: you can generate this string using
// silver_sdr.save(std::cout, JSON);
string gold = "{\"dimensions\": [200],\"sparse\": [23,71,113,118,129,172,178,182,185,190]}";
string gold = "{\"dimensions\": [200],\"sparse\": [12, 51, 81, 113, 129, 133, 172, 175, 178, 190]}";
std::stringstream gold_stream( gold );
SDR gold_sdr;
gold_sdr.load( gold_stream, JSON );
Expand Down

0 comments on commit 1be7dcd

Please sign in to comment.