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 #849 from scottpurdy/master
Browse files Browse the repository at this point in the history
Swtich relational memory to use union pooler
  • Loading branch information
scottpurdy authored Apr 18, 2018
2 parents 163a695 + 7818d45 commit 6a823ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
1 change: 0 additions & 1 deletion htmresearch/algorithms/union_temporal_pooler.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def reset(self):
self.setOverlapDutyCycles(numpy.zeros(self.getNumColumns(), dtype=REAL_DTYPE))
self.setActiveDutyCycles(numpy.zeros(self.getNumColumns(), dtype=REAL_DTYPE))
self.setMinOverlapDutyCycles(numpy.zeros(self.getNumColumns(), dtype=REAL_DTYPE))
self.setMinActiveDutyCycles(numpy.zeros(self.getNumColumns(), dtype=REAL_DTYPE))
self.setBoostFactors(numpy.ones(self.getNumColumns(), dtype=REAL_DTYPE))


Expand Down
38 changes: 23 additions & 15 deletions projects/relational_memory/pooling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import numpy as np

from htmresearch.algorithms.column_pooler import ColumnPooler
from htmresearch.algorithms.union_temporal_pooler import UnionTemporalPooler
from nupic.algorithms.knn_classifier import KNNClassifier


Expand All @@ -36,12 +36,13 @@ def train(pooler, classifier, objs, numPasses):
for _ in xrange(numPasses):
np.random.shuffle(obj)
for feature in obj:
sortedFeature = sorted(set(feature))
pooler.compute(feedforwardInput=sortedFeature,
learn=True,
predictedInput=sortedFeature)
poolerOutput = pooler.getActiveCells()
classifierInput = np.zeros(4096, dtype=np.uint32)
denseFeature = np.zeros((1024,), dtype=np.uint32)
denseFeature[feature] = 1
poolerOutput = pooler.compute(denseFeature,
denseFeature,
learn=True)

classifierInput = np.zeros((1024,), dtype=np.uint32)
classifierInput[poolerOutput] = 1
classifier.learn(classifierInput, label)

Expand All @@ -55,13 +56,13 @@ def test(pooler, classifier, objs):
np.random.shuffle(obj)
classifierGuesses = collections.defaultdict(int)
for feature in obj:
sortedFeature = sorted(set(feature))
pooler.compute(feedforwardInput=sortedFeature,
learn=False,
predictedInput=sortedFeature)
poolerOutput = pooler.getActiveCells()
denseFeature = np.zeros((1024,), dtype=np.uint32)
denseFeature[feature] = 1
poolerOutput = pooler.compute(denseFeature,
denseFeature,
learn=False)

classifierInput = np.zeros(4096, dtype=np.uint32)
classifierInput = np.zeros((1024,), dtype=np.uint32)
classifierInput[poolerOutput] = 1
classifierResult = classifier.infer(classifierInput)

Expand Down Expand Up @@ -89,8 +90,15 @@ def run():
for label in xrange(numObjects)
]

pooler = ColumnPooler(
inputWidth=1024,
pooler = UnionTemporalPooler(
inputDimensions=(1024,),
columnDimensions=(1024,),
potentialRadius=1024,
potentialPct=0.8,
globalInhibition=True,
numActiveColumnsPerInhArea=20.0,
#boostStrength=10.0,
#dutyCyclePeriod=50,
)
classifier = KNNClassifier(k=1, distanceMethod="rawOverlap")

Expand Down

0 comments on commit 6a823ff

Please sign in to comment.