Skip to content

Commit a234b04

Browse files
authored
Merge pull request #971 from fcr/location_module
Location module and ApicalTiebreakMemoryCPP
2 parents 4d8bc03 + 1fc6716 commit a234b04

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

py/htm/advanced/algorithms/location_modules.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def __init__(self,
8181
self.activationThreshold = activationThreshold
8282
self.maxSynapsesPerSegment = maxSynapsesPerSegment
8383
self.maxSegmentsPerCell = maxSegmentsPerCell
84+
self.bumpPhases = None # Place holder
8485

8586
self.rng = Random(seed)
8687

@@ -690,7 +691,7 @@ def __init__(self,
690691
self.cellCoordinateOffsets = cellCoordinateOffsets
691692

692693
# Phase is measured as a number in the range [0.0, 1.0)
693-
self.activePhases = np.empty((0,2), dtype="float")
694+
self.bumpPhases = np.empty((0,2), dtype="float")
694695
self.cellsForActivePhases = np.empty(0, dtype="int")
695696
self.phaseDisplacement = np.empty((0,2), dtype="float")
696697

@@ -703,12 +704,12 @@ def reset(self):
703704
Clear the active cells.
704705
"""
705706
super(Superficial2DLocationModule, self).reset()
706-
self.activePhases = np.empty((0,2), dtype="float")
707+
self.bumpPhases = np.empty((0,2), dtype="float")
707708
self.phaseDisplacement = np.empty((0,2), dtype="float")
708709

709710
def _computeActiveCells(self):
710711
# Round each coordinate to the nearest cell.
711-
activeCellCoordinates = np.floor(self.activePhases * self.cellDimensions).astype("int")
712+
activeCellCoordinates = np.floor(self.bumpPhases * self.cellDimensions).astype("int")
712713

713714
# Convert coordinates to cell numbers.
714715
self.cellsForActivePhases = (np.ravel_multi_index(activeCellCoordinates.T, self.cellDimensions))
@@ -718,11 +719,11 @@ def activateRandomLocation(self):
718719
"""
719720
Set the location to a random point.
720721
"""
721-
self.activePhases = np.array([np.random.random(2)])
722+
self.bumpPhases = np.array([np.random.random(2)])
722723
if self.anchoringMethod == "discrete":
723724
# Need to place the phase in the middle of a cell
724-
self.activePhases = np.floor(
725-
self.activePhases * self.cellDimensions)/self.cellDimensions
725+
self.bumpPhases = np.floor(
726+
self.bumpPhases * self.cellDimensions)/self.cellDimensions
726727
self._computeActiveCells()
727728

728729
def _movementComputeDelta(self, displacement):
@@ -735,7 +736,7 @@ def _movementComputeDelta(self, displacement):
735736
phaseDisplacement = (np.matmul(self.rotationMatrix, displacement) * self.phasesPerUnitDistance)
736737

737738
# Shift the active coordinates.
738-
np.add(self.activePhases, phaseDisplacement, out=self.activePhases)
739+
np.add(self.bumpPhases, phaseDisplacement, out=self.bumpPhases)
739740

740741
return phaseDisplacement
741742

@@ -757,7 +758,7 @@ def _sensoryComputeInferenceMode(self, anchorInput):
757758
inactivated = np.setdiff1d(self.activeCells, sensorySupportedCells, assume_unique=True)
758759
inactivatedIndices = np.in1d(self.cellsForActivePhases, inactivated, assume_unique=True).nonzero()[0]
759760
if inactivatedIndices.size > 0:
760-
self.activePhases = np.delete(self.activePhases, inactivatedIndices, axis=0)
761+
self.bumpPhases = np.delete(self.bumpPhases, inactivatedIndices, axis=0)
761762

762763
activated = np.setdiff1d(sensorySupportedCells, self.activeCells, assume_unique=True)
763764

@@ -774,11 +775,11 @@ def _sensoryComputeInferenceMode(self, anchorInput):
774775
for jOffset in self.cellCoordinateOffsets]
775776
)
776777
if "corners" in self.anchoringMethod:
777-
self.activePhases = activatedCoords // self.cellDimensions
778+
self.bumpPhases = activatedCoords // self.cellDimensions
778779

779780
else:
780781
if activatedCoords.size > 0:
781-
self.activePhases = np.append(self.activePhases,activatedCoords // self.cellDimensions, axis=0)
782+
self.bumpPhases = np.append(self.bumpPhases,activatedCoords // self.cellDimensions, axis=0)
782783

783784
self._computeActiveCells()
784785
self.activeSegments = activeSegments

py/htm/advanced/regions/ApicalTMPairRegion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,12 @@ def initialize(self):
411411
"seed": self.seed,
412412
}
413413

414-
if self.implementation == "ApicalTiebreakCPP": # TODO
414+
if self.implementation == "ApicalTiebreakCPP":
415415
params["learnOnOneCell"] = self.learnOnOneCell
416416
params["maxSegmentsPerCell"] = self.maxSegmentsPerCell
417417

418-
cls = ApicalTiebreakPairMemory
418+
import nupic.bindings.algorithms
419+
cls = nupic.bindings.algorithms.ApicalTiebreakPairMemory
419420

420421
elif self.implementation == "ApicalTiebreak":
421422
params["reducedBasalThreshold"] = self.reducedBasalThreshold

py/htm/advanced/regions/ApicalTMSequenceRegion.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,12 @@ def initialize(self):
360360
"seed": self.seed,
361361
}
362362

363-
if self.implementation == "ApicalTiebreakCPP": #TODO
363+
if self.implementation == "ApicalTiebreakCPP":
364364
params["learnOnOneCell"] = self.learnOnOneCell
365365
params["maxSegmentsPerCell"] = self.maxSegmentsPerCell
366366

367-
cls = ApicalTiebreakSequenceMemory
367+
import nupic.bindings.algorithms
368+
cls = nupic.bindings.algorithms.ApicalTiebreakSequenceMemory
368369

369370
elif self.implementation == "ApicalTiebreak":
370371
params["reducedBasalThreshold"] = self.reducedBasalThreshold

0 commit comments

Comments
 (0)