Skip to content
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

Connections: apply synapsesCompetition() in adaptSegment() #584

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
24 changes: 12 additions & 12 deletions src/htm/algorithms/Connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,14 @@ void Connections::destroySynapse(const Synapse synapse) {
}
}

const auto synapseOnSegment =
std::lower_bound(segmentData.synapses.cbegin(), segmentData.synapses.cend(),
synapse,
[&](const Synapse a, const Synapse b) -> bool {
return dataForSynapse(a).id < dataForSynapse(b).id;
});

NTA_ASSERT(synapseOnSegment != segmentData.synapses.end());
const auto synapseOnSegment = std::find(segmentData.synapses.cbegin(),
segmentData.synapses.cend(),
synapse);

NTA_ASSERT(synapseOnSegment != segmentData.synapses.cend());
NTA_ASSERT(*synapseOnSegment == synapse);

segmentData.synapses.erase(synapseOnSegment);

destroyedSynapses_.push_back(synapse);
}

Expand Down Expand Up @@ -348,7 +344,7 @@ bool Connections::compareSegments(const Segment a, const Segment b) const {
// default sort by cell
if (aData.cell == bData.cell)
//fallback to ordinals:
return aData.id < bData.id;
return aData.id < bData.id; //TODO is segment's id/ordinals needed?
else return aData.cell < bData.cell;
}

Expand Down Expand Up @@ -479,6 +475,9 @@ void Connections::adaptSegment(const Segment segment,
}
}

//balance synapses using competition on dendrite
synapseCompetition(segment, 4, 10); //FIXME derive these numbers
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calling synapseCompetition from adaptSegment

  • this works pretty well, with synapse pruning many synapses get removed which leads to a considerable speedup
  • set the min/max parameters somehow smarter
    • I guess those should ideally be around stimulusThreshold ?
    • the tighter the boundary, the more syns get removed, the faster SP (on MNIST) is.
      • but where is the line? What is the disadvantage? I'd think too tight boundary is more prone to noice?

CC @ctrl-z-9000-times


//destroy segment if it has too few synapses left -> will never be able to connect again
if(pruneZeroSynapses and synapses.size() < connectedThreshold_) {
destroySegment(segment);
Expand Down Expand Up @@ -549,7 +548,8 @@ void Connections::synapseCompetition(
const SynapseIdx maximumSynapses)
{
NTA_ASSERT( minimumSynapses <= maximumSynapses);
NTA_ASSERT( maximumSynapses > 0 );
NTA_ASSERT( maximumSynapses >= connectedThreshold );
NTA_ASSERT( minimumSynapses < connectedThreshold );

const auto &segData = dataForSegment( segment );

Expand All @@ -574,7 +574,7 @@ void Connections::synapseCompetition(
// Can't connect more synapses than there are in the potential pool.
desiredConnected = std::min( (SynapseIdx) segData.synapses.size(), desiredConnected);
// The N'th synapse is at index N-1
if( desiredConnected != 0 ) {
if( desiredConnected > 0 ) {
desiredConnected--;
}
// else {
Expand Down
2 changes: 1 addition & 1 deletion src/htm/algorithms/Connections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ class Connections : public Serializable
*/
void synapseCompetition( const Segment segment,
const SynapseIdx minimumSynapses,
const SynapseIdx maximumSynapses);
const SynapseIdx maximumSynapses);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

  • this should have some parametric default values
  • replace (or provide overload) with percentages off the range [stimulusThreshold, maxSynapsesPerSegment]?



/**
Expand Down
2 changes: 1 addition & 1 deletion src/htm/algorithms/SpatialPooler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ Real SpatialPooler::avgConnectedSpanForColumnND_(UInt column) const {
void SpatialPooler::adaptSynapses_(const SDR &input,
const SDR &active) {
for(const auto &column : active.getSparse()) {
connections_.adaptSegment(column, input, synPermActiveInc_, synPermInactiveDec_);
connections_.adaptSegment(column, input, synPermActiveInc_, synPermInactiveDec_, true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SP also does prune synapses (like TM)

  • default to true/or even rm the parameter, when all use true now

connections_.raisePermanencesToThreshold( column, stimulusThreshold_ );
}
}
Expand Down