@@ -0,0 +1,2804 @@
+#! /usr/bin/env python%0A# ----------------------------------------------------------------------%0A# Numenta Platform for Intelligent Computing (NuPIC)%0A# Copyright (C) 2013, Numenta, Inc.  Unless you have an agreement%0A# with Numenta, Inc., for a separate license for this software code, the%0A# following terms and conditions apply:%0A#%0A# This program is free software: you can redistribute it and/or modify%0A# it under the terms of the GNU General Public License version 3 as%0A# published by the Free Software Foundation.%0A#%0A# This program is distributed in the hope that it will be useful,%0A# but WITHOUT ANY WARRANTY; without even the implied warranty of%0A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.%0A# See the GNU General Public License for more details.%0A#%0A# You should have received a copy of the GNU General Public License%0A# along with this program.  If not, see http://www.gnu.org/licenses.%0A#%0A# http://numenta.org/licenses/%0A# ----------------------------------------------------------------------%0A%0A# Disable since test code accesses private members in the class to be tested%0A# pylint: disable=W0212%0A%0A#from mock import Mock%0Aimport numpy%0A#import unittest2 as unittest%0A%0Afrom nupic.support.unittesthelpers.algorithm_test_helpers import (%0A  getNumpyRandomGenerator, getSeed )%0Afrom nupic.bindings.math import (SM_01_32_32 as SparseBinaryMatrix,%0A                                 SM32 as SparseMatrix,%0A                                 GetNTAReal)%0A#from nupic.research.spatial_pooler import SpatialPooler%0Afrom nupic.bindings.algorithms import SpatialPooler %0A#import timeit as t%0A%0A%0A%0ArealDType = GetNTAReal()%0A%0Aclass SpatialPoolerTest(object):%0A  %22%22%22Unit Tests for SpatialPooler class.%22%22%22%0A%0A%0A  def testCompute1(self):%0A    %22%22%22Checks that feeding in the same input vector leads to polarized%0A    permanence values: either zeros or ones, but no fractions%22%22%22%0A%0A    inDim = %5B100,10,10%5D%0A    colDim = %5B10, 10, 10%5D%0A%0A%0A#    a= t.timeit()%0A%0A    sp = SpatialPooler(%0A        inputDimensions=inDim,%0A        columnDimensions=colDim,%0A        potentialRadius=3,%0A        potentialPct=0.5,%0A        globalInhibition=False,%0A        localAreaDensity=-1.0,%0A        numActiveColumnsPerInhArea=3,%0A        stimulusThreshold=1,%0A        synPermInactiveDec=0.01,%0A        synPermActiveInc=0.1,%0A        synPermConnected=0.10,%0A        minPctOverlapDutyCycle=0.1,%0A        minPctActiveDutyCycle=0.1,%0A        dutyCyclePeriod=10,%0A        maxBoost=10.0,%0A        seed=getSeed(),%0A        spVerbosity=0)%0A%0A    inputVector = numpy.zeros(inDim)%0A    activeArray = numpy.zeros(colDim)%0A%0A #   b = t.timeit()%0A  #  print %22init: %22, (b-a)%0A%0A    for i in xrange(100):%0A      sp.compute(inputVector, True, activeArray)%0A#      print(%22.%22)%0A%0A   # c = t.timeit()%0A   # print %22compute() 20x : %22, (c-a)%0A%0A%0A%0Aif __name__ == %22__main__%22:%0A  ex = SpatialPoolerTest()%0A  ex.testCompute1()%0A

test case for SP.compute() speed