-
Notifications
You must be signed in to change notification settings - Fork 74
SDR replaces VectorHelpers #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e2fa54e
70cdb1a
f651b42
858d1f3
3391f78
4d793ab
c2bcb04
6d68136
bdb7ffd
83d0e9c
9cfd73d
6371aa2
eb016bc
1f430b2
11a6190
d4cf24d
dc7fb3c
436c600
96302f9
e303d36
a76cd0e
53dd7ac
4cf4c05
6c2106d
0469db8
b331253
6818ef0
24350fe
182a7af
355f73f
7e7bd2a
9866a36
d12bff8
e30add5
bed3bdf
9a9575d
f2d1a0d
2b1cf93
2823d4e
3ca10e4
a9912f3
ffeb5a6
d37daf9
954013e
4a850b9
0243edc
a324d30
a738702
7643e34
cb1ce21
3de7990
409c9d4
2604dd0
a1d9a14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,6 @@ | |
|
||
#include <nupic/algorithms/SpatialPooler.hpp> | ||
#include <nupic/utils/Topology.hpp> | ||
#include <nupic/utils/VectorHelpers.hpp> | ||
|
||
using namespace std; | ||
using namespace nupic; | ||
|
@@ -450,18 +449,17 @@ void SpatialPooler::initialize( | |
inhibitionRadius_ = 0; | ||
|
||
connections_.initialize(numColumns_, synPermConnected_); | ||
for (Size i = 0; i < numColumns_; ++i) { | ||
connections_.createSegment( (CellIdx)i ); | ||
|
||
// Note: initMapPotential_ & initPermanence_ return dense arrays. | ||
vector<UInt> potential = initMapPotential_((UInt)i, wrapAround_); | ||
vector<Real> perm = initPermanence_(potential, initConnectedPct_); | ||
for(UInt presyn = 0; presyn < numInputs_; presyn++) { | ||
if( potential[presyn] ) | ||
connections_.createSynapse( (Segment)i, presyn, perm[presyn] ); | ||
for (Size column = 0; column < numColumns_; column++) { | ||
connections_.createSegment( static_cast<CellIdx>(column) ); | ||
|
||
SDR potential({numInputs_}); | ||
initMapPotential_(static_cast<UInt>(column), wrapAround_, potential); | ||
const vector<Real> perm = initPermanence_(potential, initConnectedPct_); | ||
for(const auto presyn : potential.getSparse()) { | ||
connections_.createSynapse( static_cast<Segment>(column), presyn, perm[presyn] ); | ||
} | ||
|
||
connections_.raisePermanencesToThreshold( (Segment)i, stimulusThreshold_ ); | ||
connections_.raisePermanencesToThreshold( static_cast<Segment>(column), stimulusThreshold_ ); | ||
} | ||
|
||
updateInhibitionRadius_(); | ||
|
@@ -505,6 +503,7 @@ void SpatialPooler::compute(const SDR &input, const bool learn, SDR &active) { | |
|
||
void SpatialPooler::boostOverlaps_(const vector<SynapseIdx> &overlaps, //TODO use Eigen sparse vector here | ||
vector<Real> &boosted) const { | ||
NTA_ASSERT(overlaps.size() == numColumns_); | ||
for (UInt i = 0; i < numColumns_; i++) { | ||
boosted[i] = overlaps[i] * boostFactors_[i]; | ||
} | ||
|
@@ -530,8 +529,10 @@ UInt SpatialPooler::initMapColumn_(UInt column) const { | |
} | ||
|
||
|
||
vector<UInt> SpatialPooler::initMapPotential_(UInt column, bool wrapAround) { | ||
NTA_ASSERT(column < numColumns_); | ||
void SpatialPooler::initMapPotential_(UInt column, bool wrapAround, SDR& potential) { | ||
NTA_CHECK(potential.size == numInputs_); | ||
NTA_CHECK(column < numColumns_); | ||
|
||
const UInt centerInput = initMapColumn_(column); | ||
|
||
vector<UInt> columnInputs; | ||
|
@@ -547,9 +548,9 @@ vector<UInt> SpatialPooler::initMapPotential_(UInt column, bool wrapAround) { | |
} | ||
|
||
const UInt numPotential = (UInt)round(columnInputs.size() * potentialPct_); | ||
const auto selectedInputs = rng_.sample<UInt>(columnInputs, numPotential); | ||
const vector<UInt> potential = VectorHelpers::sparseToBinary<UInt>(selectedInputs, numInputs_); | ||
return potential; | ||
auto selectedInputs = rng_.sample<UInt>(columnInputs, numPotential); | ||
std::sort(selectedInputs.begin(), selectedInputs.end()); | ||
potential.setSparse(selectedInputs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not sorted! This is the bug causing the Because the potential pool is not sorted, the initial Permanences are randomly generated differently than before. This also fails in debug mode where there is an |
||
} | ||
|
||
|
||
|
@@ -563,14 +564,9 @@ Real SpatialPooler::initPermNonConnected_() { | |
} | ||
|
||
|
||
vector<Real> SpatialPooler::initPermanence_(const vector<UInt> &potential, //TODO make potential sparse | ||
Real connectedPct) { | ||
const vector<Real> SpatialPooler::initPermanence_(const SDR &potential, const Real connectedPct) { | ||
vector<Real> perm(numInputs_, 0); | ||
for (UInt i = 0; i < numInputs_; i++) { | ||
if (potential[i] < 1) { | ||
continue; | ||
} | ||
|
||
for (const auto i : potential.getSparse()) { | ||
if (rng_.getReal64() <= connectedPct) { | ||
perm[i] = initPermConnected_(); | ||
} else { | ||
|
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.