calumroy / HTM

HTM
3 stars 0 forks source link

np_activeCells profiling speed #24

Open calumroy opened 8 years ago

calumroy commented 8 years ago

Related to Issue #5

The updateActiveCells function has now 1bf77dc been extracted into its own calculator class. A few changes where made mainly to stop constantly changing array sizes and make them a fixed size. This will improve speed as arrays are no longer being appended to. It has made the update structure for storing information about which synapses learning ay be perform on more complicated.

Further improvements can be made by also having in addition to a tensor storing the end connections of all cells distal synapses (distalSynapses) another tensor storing the starting position of every cells distal synapse distalSynapsesSegOrigin. This will help improve the updateActiveCells function as now instead of calling the function getBestMatchingSegment to find for a cell the segment that was active the most for a particular timeStep we can just go through the list of active cells for that timeStep and see which distal synapses have an end connection to them. This means only going through the synapses that are active instead of checking all distal synapses for a particular cell. Each active distal synapses can add 1 to the segment from which it originates form and once you have finished checking all active synapses a total score for each segment will have been created. This total score will indicate which segment is the best matching for a particular cell. The function getBestMatchingSegment can then return this segment.

Below is a cProfiling run on the updateActiveCells function for the following parameters. This is the standard np_activeCells calculator class (no distalSynapsesSegOrigin tensor), it uses the following inputs;

timeStep, activeColumns, predictiveCells, activeSeg, distalSynapses

Parameters;

    numRows = 400
    numCols = 40
    cellsPerColumn = 10
    numColumns = numRows * numCols
    maxSegPerCell = 10
    maxSynPerSeg = 10
    minNumSynThreshold = 1
    minScoreThreshold = 1
    newSynPermanence = 0.3
    timeStep = 3
2264896 function calls in 11.559 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
     4001    0.073    0.000    0.190    0.000 np_activeCells.py:284(newRandomPrevActiveSynapses)
     4001    0.029    0.000    0.031    0.000 np_activeCells.py:295(findLeastUsedSeg)
     3943    0.010    0.000    0.027    0.000 np_activeCells.py:313(checkColBursting)
     1981    0.001    0.000    0.003    0.000 np_activeCells.py:329(findActiveCell)
     1962    0.002    0.000    0.004    0.000 np_activeCells.py:340(findLearnCell)
    25602    0.045    0.000    0.047    0.000 np_activeCells.py:349(setActiveCell)
     7944    0.014    0.000    0.015    0.000 np_activeCells.py:361(setLearnCell)
   425663    1.891    0.000    1.891    0.000 np_activeCells.py:373(checkCellActive)
     1962    0.001    0.000    0.001    0.000 np_activeCells.py:383(checkCellLearn)
    40010    0.047    0.000    0.047    0.000 np_activeCells.py:393(checkCellPredicting)
    40010    0.796    0.000    2.682    0.000 np_activeCells.py:403(segmentHighestScore)
   400100    7.749    0.000    7.882    0.000 np_activeCells.py:420(segmentNumSynapsesActive)
    40010    0.259    0.000    8.159    0.000 np_activeCells.py:443(getBestMatchingSegment)
        1    0.116    0.116   10.958   10.958 np_activeCells.py:474(updateActiveCellScores)
        1    0.235    0.235   11.559   11.559 np_activeCells.py:503(updateActiveCells)
    40010    0.083    0.000    0.116    0.000 random.py:293(sample)
    40010    0.022    0.000    0.022    0.000 {hasattr}
   568144    0.041    0.000    0.041    0.000 {len}
    40010    0.004    0.000    0.004    0.000 {method 'add' of 'set' objects}
    33546    0.003    0.000    0.003    0.000 {method 'append' of 'list' objects}
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
    40010    0.004    0.000    0.004    0.000 {method 'random' of '_random.Random' objects}
   505974    0.136    0.000    0.136    0.000 {range}