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

Fix Connections segment pruning #601

Merged
merged 41 commits into from
Jun 4, 2020
Merged
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c672f49
Connections::adaptSegment fix segment pruning
breznak Aug 1, 2019
3f4999c
SP & TM use synapse & segment pruning from Connections
breznak Aug 1, 2019
1c3a684
TM.punishPredictedColumn_() is a private method of TM
breznak Aug 1, 2019
c47b7a4
TM:activatePredictedColumns() moved from static
breznak Aug 2, 2019
9ce19f9
TM::burstColumn() made private from static
breznak Aug 2, 2019
d3ba477
TM:growSynapses() made private from static
breznak Aug 2, 2019
4be092b
Connections:destroySynapse fixup, use find
breznak Jul 23, 2019
6f535c4
fix deterministic test results
breznak Aug 2, 2019
b6d04bb
reintroduce lower_bound w deterministic ordering
breznak Aug 2, 2019
b7fa36e
Merge branch 'master_community' into fix_conn_stimulusThreshold
breznak Aug 9, 2019
4a571bb
Merge branch 'master_community' into fix_conn_stimulusThreshold
breznak Aug 10, 2019
36608e5
cleanup createSegment
breznak Aug 10, 2019
f35daf7
assert
breznak Aug 10, 2019
97ec6bf
Connections: remove vector destroySegments_
breznak Aug 10, 2019
24b39be
Connections: fix crash in destroySynapse
breznak Aug 10, 2019
0b53cf7
Connections: removed vector destroyedSynapses_
breznak Aug 10, 2019
f2e16ef
Merge branch 'master_community' into fix_conn_stimulusThreshold
breznak Aug 10, 2019
2d1bd5a
fix exact output results from CI
breznak Aug 10, 2019
a400325
SP cannot call adaptSegment with pruning,
breznak Aug 10, 2019
aaa6385
Merge branch 'master_community' into fix_conn_stimulusThreshold
breznak Sep 17, 2019
c3e0cbb
SP: WIP enable segment pruning
breznak Sep 17, 2019
9691459
Connections: cosmetic cleanup synapsesForSegment()
breznak Jun 3, 2020
3d9d60d
Merge branch 'master_community' into fix_conn_stimulusThreshold
breznak Jun 3, 2020
03e2fc5
Merge branch 'conn_createSyn2' into fix_conn_stimulusThreshold
breznak Jun 3, 2020
b91144d
fix bug in Conn.pruneLRUSegment_()
breznak Jun 3, 2020
46e4ca5
SP: enable segment pruning for Conn.adaptSegment
breznak Jun 3, 2020
b58258c
COnn revert to lower_bound with explicit ordering
breznak Jun 3, 2020
6bc3dc7
Connections: add test for destroySynapse
breznak Jun 3, 2020
bcefa8c
COnnections: add test for createSynapse
breznak Jun 3, 2020
56b6a1f
Connections adaptSegment: improve py binding
breznak Jun 3, 2020
21cd185
COnnections: fix dataForSynapse() after destroyed
breznak Jun 3, 2020
7463e5f
Connections: test for createSynapse
breznak Jun 3, 2020
1d9518b
COnnections.createSynapse : update exiting if higher permanence
breznak Jun 3, 2020
b0d1338
revert changes to SP and deterministic results
breznak Jun 3, 2020
1de0631
bump test values for new changes
breznak Jun 3, 2020
038a292
COnnections: add couple of noexcept
breznak Jun 3, 2020
540f3c4
Connections tests for createSegment()
breznak Jun 3, 2020
bf7ee11
COnnections: test for destroySegment()
breznak Jun 3, 2020
3c67eb5
tests advanced_connections.py drop duplicit tests
breznak Jun 3, 2020
ffb8ee8
Connections dataForSegment throws if segment removed
breznak Jun 3, 2020
690047c
Merge branch 'master_community' into fix_conn_stimulusThreshold
breznak Jun 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
COnnections.createSynapse : update exiting if higher permanence
if the new permanence is higher that the permanence of the old (same)
synapse, update to the higher value.
  • Loading branch information
breznak committed Jun 3, 2020
commit 1d9518b2fe318bdca1f6c0a9a93263c6778ae148
5 changes: 5 additions & 0 deletions bindings/py/tests/algorithms/connections_test.py
Original file line number Diff line number Diff line change
@@ -197,6 +197,11 @@ def testCreateSynapse(self):
self.assertEqual(co.numSynapses(), 2, "Duplicate synapse, number should not increase")
self.assertEqual(pytest.approx(co.permanenceForSynapse(syn1)), 0.52, "update keeps the larger value")

#4.b higher permanence -> update
syn5 = co.createSynapse(seg, NUM_CELLS-1, 0.99) #all the same just permanence is a higher val
self.assertEqual( syn1, syn5, "just updating existing syn")
self.assertEqual(co.numSynapses(), 2, "Duplicate synapse, number should not increase")
self.assertEqual(pytest.approx(co.permanenceForSynapse(syn1)), 0.99, "updated to the larger permanence value")



12 changes: 11 additions & 1 deletion src/htm/algorithms/Connections.cpp
Original file line number Diff line number Diff line change
@@ -139,7 +139,17 @@ Synapse Connections::createSynapse(Segment segment,
for (const Synapse& syn : synapsesForSegment(segment)) {
const CellIdx existingPresynapticCell = dataForSynapse(syn).presynapticCell; //TODO 1; add way to get all presynaptic cells for segment (fast)
if (presynapticCell == existingPresynapticCell) {
return syn; //synapse (connecting to this presyn cell) already exists on the segment; don't create a new one, exit early and return the existing
//synapse (connecting to this presyn cell) already exists on the segment; don't create a new one, exit early and return the existing
NTA_ASSERT(synapseExists_(syn));
//TODO what is the strategy on creating a new synapse, while the same already exists (on the same segment, presynapticCell) ??
//1. just keep the older (former default)
//2. throw an error (ideally, user should not createSynapse() but rather updateSynapsePermanence())
//3. create a duplicit new synapse -- NO. This is the only choice that is incorrect! HTM works on binary synapses, duplicates would break that.
//4. update to the max of the permanences (default)
Copy link
Member Author

Choose a reason for hiding this comment

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

documented and changed the default strategy for createSynapse() if such synapse already exists. All four alternatives discussed above,

  • former default: leave as is;
  • now: update permanence if the new perm would be larger.

Copy link
Member Author

Choose a reason for hiding this comment

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

...impact is not really seen in our unit-tests as none trigger this "duplicit synapse created" branch.


auto& synData = synapses_[syn];
if(permanence > synData.permanence) updateSynapsePermanence(syn, permanence);
return syn;
}
} //else: the new synapse is not duplicit, so keep creating it.

6 changes: 4 additions & 2 deletions src/htm/algorithms/Connections.hpp
Original file line number Diff line number Diff line change
@@ -267,9 +267,10 @@ class Connections : public Serializable
*
* @param segment Segment to create synapse on.
* @param presynapticCell Cell to synapse on.
* @param permanence Initial permanence of new synapse.
* @param permanence Initial permanence of new synapse. If calling "create" on an existing synapse (same segment, presynapticCell),
* then we either keep the old one, or update the old one to have higher permanence (from the new call).
*
* @return Created synapse. //TODO consider changing to void, or explain what's returned
* @return Created synapse - index to the newly created synapse. Use `dataForSynapse(returnedValue)` to work with it.
*/
Synapse createSynapse(const Segment segment,
const CellIdx presynapticCell,
@@ -286,6 +287,7 @@ class Connections : public Serializable
* Destroys synapse.
*
* @param synapse Synapse to destroy.
* @throws if synapse does not exist (ie already removed)
*/
void destroySynapse(const Synapse synapse);