This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
enc_profile.py
57 lines (47 loc) · 1.86 KB
/
enc_profile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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 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/
# ----------------------------------------------------------------------
## 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)