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 #1928 from breznak/bench_tools
Browse files Browse the repository at this point in the history
Bench tools
  • Loading branch information
oxtopus committed Apr 21, 2015
2 parents ecbcd00 + 62de044 commit b788fb6
Show file tree
Hide file tree
Showing 4 changed files with 217 additions and 0 deletions.
57 changes: 57 additions & 0 deletions scripts/profiling/enc_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2015, 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 General 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------

## run python -m cProfile --sort cumtime $NUPIC/scripts/profiling/enc_profile.py [nMaxValue nEpochs]

import sys
import numpy
# chose desired Encoder implementations to compare:
from nupic.encoders.scalar import ScalarEncoder
from nupic.encoders.random_distributed_scalar import RandomDistributedScalarEncoder as RDSE


def profileEnc(maxValue, nRuns):
minV=0
maxV=nRuns
# generate input data
data=numpy.random.randint(minV, maxV+1, nRuns)
# instantiate measured encoders
encScalar = ScalarEncoder(w=21, minval=minV, maxval=maxV, resolution=1)
encRDSE = RDSE(resolution=1)

# profile!
for d in data:
encScalar.encode(d)
encRDSE.encode(d)

print "Scalar n=",encScalar.n," RDSE n=",encRDSE.n



if __name__ == "__main__":
maxV=500
epochs=10000
if len(sys.argv) == 3: # 2 args + name
columns=int(sys.argv[1])
epochs=int(sys.argv[2])

profileEnc(maxV, epochs)
File renamed without changes.
93 changes: 93 additions & 0 deletions scripts/profiling/sp_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env python
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2015, 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 General 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------

## run python -m cProfile --sort cumtime $NUPIC/scripts/profiling/sp_profile.py [nColumns nEpochs]

import sys
import numpy
# chose desired SP implementation to compare:
from nupic.research.spatial_pooler import SpatialPooler as PySP
from nupic.bindings.algorithms import SpatialPooler as CppSP


def profileSP(spClass, spDim, nRuns):
"""
profiling performance of SpatialPooler (SP)
using the python cProfile module and ordered by cumulative time,
see how to run on command-line above.
@param spClass implementation of SP (cpp, py, ..)
@param spDim number of columns in SP (in 1D, for 2D see colDim in code)
@param nRuns number of calls of the profiled code (epochs)
"""
# you can change dimensionality here, eg to 2D
inDim = [10000, 1, 1]
colDim = [spDim, 1, 1]


# create SP instance to measure
# changing the params here affects the performance
sp = spClass(
inputDimensions=inDim,
columnDimensions=colDim,
potentialRadius=3,
potentialPct=0.5,
globalInhibition=False,
localAreaDensity=-1.0,
numActiveColumnsPerInhArea=3,
stimulusThreshold=1,
synPermInactiveDec=0.01,
synPermActiveInc=0.1,
synPermConnected=0.10,
minPctOverlapDutyCycle=0.1,
minPctActiveDutyCycle=0.1,
dutyCyclePeriod=10,
maxBoost=10.0,
seed=42,
spVerbosity=0)


# generate input data
dataDim = inDim
dataDim.append(nRuns)
data = numpy.random.randint(0, 2, dataDim).astype('float32')

for i in xrange(nRuns):
# new data every time, this is the worst case performance
# real performance would be better, as the input data would not be completely random
d = data[:,:,:,i]
activeArray = numpy.zeros(colDim)

# the actual function to profile!
sp.compute(d, True, activeArray)



if __name__ == "__main__":
columns=2048
epochs=10000
# read params from command line
if len(sys.argv) == 3: # 2 args + name
columns=int(sys.argv[1])
epochs=int(sys.argv[2])

profileSP(CppSP, columns, epochs)
67 changes: 67 additions & 0 deletions scripts/profiling/tp_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2015, 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 General 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------

## run python -m cProfile --sort cumtime $NUPIC/scripts/profiling/tp_profile.py [nColumns nEpochs]

import sys
import numpy
# chose desired TP implementation to compare:
from nupic.research.TP10X2 import TP10X2 as CppTP
from nupic.research.TP import TP as PyTP


def profileTP(tpClass, tpDim, nRuns):
"""
profiling performance of TemporalPooler (TP)
using the python cProfile module and ordered by cumulative time,
see how to run on command-line above.
@param tpClass implementation of TP (cpp, py, ..)
@param tpDim number of columns in TP
@param nRuns number of calls of the profiled code (epochs)
"""

# create TP instance to measure
tp = tpClass(numberOfCols=tpDim)

# generate input data
data = numpy.random.randint(0, 2, [tpDim, nRuns]).astype('float32')

for i in xrange(nRuns):
# new data every time, this is the worst case performance
# real performance would be better, as the input data would not be completely random
d = data[:,i]

# the actual function to profile!
tp.compute(d, True)



if __name__ == "__main__":
columns=2048
epochs=10000
# read command line params
if len(sys.argv) == 3: # 2 args + name
columns=int(sys.argv[1])
epochs=int(sys.argv[2])

profileTP(CppTP, columns, epochs)

0 comments on commit b788fb6

Please sign in to comment.