Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Full sync of C++ temporal memory to Python temporal memory #3254

Merged
merged 45 commits into from Aug 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ac037b9
initial changes to connections
andrewmalta13 Jul 27, 2016
776bcd0
continues change of connections datastructures
andrewmalta13 Jul 28, 2016
181b381
create new methods for creating/destroying synapses/segments
andrewmalta13 Jul 28, 2016
dca7742
adds new connections methods
andrewmalta13 Jul 28, 2016
70aa06d
updates computeActivity
andrewmalta13 Jul 28, 2016
a491380
Merge branch 'master' of https://github.com/numenta/nupic into pyTMCo…
andrewmalta13 Jul 29, 2016
a8ac0d2
all skipped unit tests except serialization pass
andrewmalta13 Jul 29, 2016
b804575
initial implementation on serialization, doesn't pass test yet
andrewmalta13 Jul 29, 2016
798eddb
fixes bug in growSynapses, almost exactly the same
andrewmalta13 Aug 1, 2016
90c9422
confirmed python implementation is same as cpp version. Needs better …
andrewmalta13 Aug 2, 2016
625dcb2
improves permanence >= testing in computeActivity
andrewmalta13 Aug 2, 2016
f626baf
serialization tests now pass
andrewmalta13 Aug 3, 2016
7b14844
started porting new connections tests and minor changes to connection…
andrewmalta13 Aug 3, 2016
8be4b08
fixes read write test
andrewmalta13 Aug 3, 2016
e276f87
all connections tests written and passing, moved some stuff around an…
andrewmalta13 Aug 4, 2016
383d73e
linting on new tests
andrewmalta13 Aug 4, 2016
c6f96be
adds groupByN utility function for use in TM
andrewmalta13 Aug 4, 2016
72f8092
group by temporal memory passes all tests
andrewmalta13 Aug 4, 2016
a6bd6c3
ports group_by tests and they pass
andrewmalta13 Aug 5, 2016
11d8a4f
gets same results as c++ temporal memory after group_by changes
andrewmalta13 Aug 5, 2016
7ddd216
updates documentation
andrewmalta13 Aug 8, 2016
4c52b08
updates documentation, linting, and some tests
andrewmalta13 Aug 8, 2016
c336eef
Merge branch 'master' of https://github.com/numenta/nupic into pyTMCo…
andrewmalta13 Aug 8, 2016
df0dfce
lints and updates comments in group_by.py and group_by_tests.py
andrewmalta13 Aug 8, 2016
034b258
skip serialization test if capnp is not installed
andrewmalta13 Aug 8, 2016
60ebaf7
fixes bug where minIdx could be passed as a float rather than an int
andrewmalta13 Aug 8, 2016
c28207e
fixes subtle bug in numSegments that caused integration tests to fail
andrewmalta13 Aug 8, 2016
8bedade
fixes and now runs the tm compatibility test
andrewmalta13 Aug 9, 2016
c1edbe8
incorporates minor perf suggestions
andrewmalta13 Aug 9, 2016
8f5a81a
small misc fixes
andrewmalta13 Aug 9, 2016
32d6e26
demonstrate that compatability test works with predictedSegmentDec no…
andrewmalta13 Aug 9, 2016
b53403a
small perf changes
andrewmalta13 Aug 10, 2016
693c4cc
100 % increase in spped
andrewmalta13 Aug 10, 2016
6064fa0
fixes broken connections tests
andrewmalta13 Aug 10, 2016
fb12219
changes to groupby
andrewmalta13 Aug 11, 2016
596d77b
add getters and setters to be compatible with sanity
andrewmalta13 Aug 11, 2016
a5bc7da
perf improvement to segment comparison in compute activity
andrewmalta13 Aug 11, 2016
ca9632f
now as fast as current implementation
andrewmalta13 Aug 12, 2016
fd26c99
fixes read method in connections + some linting
andrewmalta13 Aug 12, 2016
eaaeef4
addresses CR comments
andrewmalta13 Aug 12, 2016
b855f1e
lazy group_by and changes to GroupByGenerator
andrewmalta13 Aug 13, 2016
b4ef5ef
implements small rework to custom groupby
andrewmalta13 Aug 13, 2016
17b0cf7
overhaul to groupby, now 10% faster than current implementation
andrewmalta13 Aug 15, 2016
dec7b48
not _ is => is not and fixes groupby comment and passes integration t…
andrewmalta13 Aug 15, 2016
bba0c63
addresses comments
andrewmalta13 Aug 15, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
710 changes: 505 additions & 205 deletions src/nupic/research/connections.py

Large diffs are not rendered by default.

446 changes: 237 additions & 209 deletions src/nupic/research/temporal_memory.py

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions src/nupic/support/group_by.py
@@ -0,0 +1,88 @@
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2016, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------

from itertools import groupby


def groupby2(*args):
""" An extension to groupby in itertools. Allows to walk across n sorted lists
with respect to their key functions and yields a tuple of n lists of the
members of the next *smallest* group.

@param args (list) a list of arguments alternating between sorted lists and
their respective key functions. The lists should be
sorted with respect to their key function.

@return (tuple) a n + 1 dimensional tuple, where the first element is the
key of the group and the other n entries are lists of
objects that are a member of the current group that is being
iterated over in the nth list passed in. Note that this
is a generator and a n+1 dimensional tuple is yielded for
every group. If a list has no members in the current
group, None is returned in place of a generator.

Notes: Read up on groupby here:
https://docs.python.org/dev/library/itertools.html#itertools.groupby

"""
generatorList = [] # list of each list's (k, group) tuples

if len(args) % 2 == 1:
raise ValueError("Must have a key function for every list.")

# populate above lists
for i in xrange(0, len(args), 2):
listn = args[i]
fn = args[i + 1]
generatorList.append(groupby(listn, fn))

n = len(generatorList)

advanceList = [True] * n # start by advancing everyone.
nextList = [None] * n
# while all lists aren't exhausted walk through each group in order
while True:
for i in xrange(n):
if advanceList[i]:
try:
nextList[i] = generatorList[i].next()
except StopIteration:
nextList[i] = None

# no more values to process in any of the generators
if all(entry is None for entry in nextList):
break
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: we might as well do all(entry is None for entry in nextList) without the [] to avoid creating a list.


# the minimum key value in the nextList
minKeyVal = min(nextVal[0] for nextVal in nextList
if nextVal is not None)

# populate the tuple to return based on minKeyVal
retGroups = [minKeyVal]
for i in xrange(n):
if nextList[i] is not None and nextList[i][0] == minKeyVal:
retGroups.append(nextList[i][1])
advanceList[i] = True
else:
advanceList[i] = False
retGroups.append(None)

yield tuple(retGroups)
1 change: 1 addition & 0 deletions tests/integration/nupic/engine/network_creation_common.py
Expand Up @@ -80,6 +80,7 @@
"initialPerm": 0.21,
"permanenceInc": 0.1,
"permanenceDec": 0.1,
"predictedSegmentDecrement": .01,
"globalDecay": 0.0,
"maxAge": 0,
"minThreshold": 9,
Expand Down
Expand Up @@ -31,16 +31,7 @@


class TemporalMemoryCompatibilityTest(unittest.TestCase):
"""Temporal Memory compatability tests between different implementations.

TODO: Test with predictedSegmentDecrement set to non-zero. See
https://github.com/numenta/nupic/issues/2999
"""


@unittest.skip("There are slight differences between implementations that"
"prevent this from passing still. See "
"https://github.com/numenta/nupic/issues/2980")
def testTMPyCpp(self):
"""
Test compatibility between C++ and Python TM implementation.
Expand Down