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
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 776bcd0
continues change of connections datastructures
andrewmalta13 181b381
create new methods for creating/destroying synapses/segments
andrewmalta13 dca7742
adds new connections methods
andrewmalta13 70aa06d
updates computeActivity
andrewmalta13 a491380
Merge branch 'master' of https://github.com/numenta/nupic into pyTMCo…
andrewmalta13 a8ac0d2
all skipped unit tests except serialization pass
andrewmalta13 b804575
initial implementation on serialization, doesn't pass test yet
andrewmalta13 798eddb
fixes bug in growSynapses, almost exactly the same
andrewmalta13 90c9422
confirmed python implementation is same as cpp version. Needs better …
andrewmalta13 625dcb2
improves permanence >= testing in computeActivity
andrewmalta13 f626baf
serialization tests now pass
andrewmalta13 7b14844
started porting new connections tests and minor changes to connection…
andrewmalta13 8be4b08
fixes read write test
andrewmalta13 e276f87
all connections tests written and passing, moved some stuff around an…
andrewmalta13 383d73e
linting on new tests
andrewmalta13 c6f96be
adds groupByN utility function for use in TM
andrewmalta13 72f8092
group by temporal memory passes all tests
andrewmalta13 a6bd6c3
ports group_by tests and they pass
andrewmalta13 11d8a4f
gets same results as c++ temporal memory after group_by changes
andrewmalta13 7ddd216
updates documentation
andrewmalta13 4c52b08
updates documentation, linting, and some tests
andrewmalta13 c336eef
Merge branch 'master' of https://github.com/numenta/nupic into pyTMCo…
andrewmalta13 df0dfce
lints and updates comments in group_by.py and group_by_tests.py
andrewmalta13 034b258
skip serialization test if capnp is not installed
andrewmalta13 60ebaf7
fixes bug where minIdx could be passed as a float rather than an int
andrewmalta13 c28207e
fixes subtle bug in numSegments that caused integration tests to fail
andrewmalta13 8bedade
fixes and now runs the tm compatibility test
andrewmalta13 c1edbe8
incorporates minor perf suggestions
andrewmalta13 8f5a81a
small misc fixes
andrewmalta13 32d6e26
demonstrate that compatability test works with predictedSegmentDec no…
andrewmalta13 b53403a
small perf changes
andrewmalta13 693c4cc
100 % increase in spped
andrewmalta13 6064fa0
fixes broken connections tests
andrewmalta13 fb12219
changes to groupby
andrewmalta13 596d77b
add getters and setters to be compatible with sanity
andrewmalta13 a5bc7da
perf improvement to segment comparison in compute activity
andrewmalta13 ca9632f
now as fast as current implementation
andrewmalta13 fd26c99
fixes read method in connections + some linting
andrewmalta13 eaaeef4
addresses CR comments
andrewmalta13 b855f1e
lazy group_by and changes to GroupByGenerator
andrewmalta13 b4ef5ef
implements small rework to custom groupby
andrewmalta13 17b0cf7
overhaul to groupby, now 10% faster than current implementation
andrewmalta13 dec7b48
not _ is => is not and fixes groupby comment and passes integration t…
andrewmalta13 bba0c63
addresses comments
andrewmalta13 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.