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

Commit

Permalink
Merge pull request #3254 from andrewmalta13/pyTMConnections
Browse files Browse the repository at this point in the history
Full sync of C++ temporal memory to Python temporal memory
  • Loading branch information
scottpurdy committed Aug 15, 2016
2 parents bc2fd34 + bba0c63 commit 6dd098d
Show file tree
Hide file tree
Showing 8 changed files with 1,289 additions and 670 deletions.
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

# 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

0 comments on commit 6dd098d

Please sign in to comment.