Skip to content

Commit ffec815

Browse files
committed
display running average accuracy in addition to instantaneous
1 parent 260f06a commit ffec815

File tree

1 file changed

+51
-17
lines changed

1 file changed

+51
-17
lines changed

src/CameraFrame.py

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,10 @@ def createCapture(self):
447447
else:
448448
self._capture = cv.CaptureFromCAM(-1)
449449

450+
#reset running average accuracy values per Region on new capture
451+
for i in xrange(len(self.regionPanels)):
452+
self.regionPanels[i].resetRunningAverages()
453+
450454
#test if we can get frames from the input; error dialog if not
451455
try:
452456
frame = cv.QueryFrame(self._capture)
@@ -815,6 +819,9 @@ def __init__(self, parent, id, inputSize):
815819
self.regionID = id
816820
self.region = None
817821
self._nextRegionParams = None
822+
self._sumAccPred = 0.0
823+
self._sumAccActive = 0.0
824+
self._meanCount = 0
818825

819826
pad = 0 #default some region 1 params slightly different from rest
820827
if id>1:
@@ -859,8 +866,10 @@ def __init__(self, parent, id, inputSize):
859866
inhiRadText = wx.StaticText(panel, label="Inhibition Radius")
860867
predAccText = wx.StaticText(panel, label="Prediction Accuracy")
861868
activeAccText = wx.StaticText(panel, label="Activation Accuracy")
862-
statusText = wx.StaticText(panel, label="Region Status")
863-
blankText = wx.StaticText(panel, label="")
869+
predMeanAccText = wx.StaticText(panel, label="Prediction Mean Acc")
870+
activeMeanAccText = wx.StaticText(panel, label="Activation Mean Acc")
871+
# statusText = wx.StaticText(panel, label="Region Status")
872+
# blankText = wx.StaticText(panel, label="")
864873

865874
inputPerColText.SetToolTipString("Percent of input bits within locality radius each Column has potential (proximal) synapses for.")
866875
minOverlapText.SetToolTipString("Minimum percent of column's proximal synapses that must be active for the column to be considered by the spatial pooler.")
@@ -874,7 +883,9 @@ def __init__(self, parent, id, inputSize):
874883
inhiRadText.SetToolTipString("Radius, in Columns, of how far inhibition will take effect per Column (most recent time step).")
875884
predAccText.SetToolTipString("Correctly predicted active columns out of total sequence-segment predicted columns (most recent time step).")
876885
activeAccText.SetToolTipString("Correctly predicated active columns out of total active columns (most recent time step).")
877-
statusText.SetToolTipString("Current state of the Region.")
886+
predMeanAccText.SetToolTipString("Correctly predicted active columns out of total sequence-segment predicted columns (running average).")
887+
activeMeanAccText.SetToolTipString("Correctly predicated active columns out of total active columns (running average).")
888+
# statusText.SetToolTipString("Current state of the Region.")
878889

879890
self.inputPerColSpin = wx.SpinCtrl(panel, size=(70,-1), style=wx.SP_ARROW_KEYS)
880891
self.inputPerColSpin.SetValue(15+pad)
@@ -903,8 +914,10 @@ def __init__(self, parent, id, inputSize):
903914
self.inhiRadValText = wx.StaticText(panel, label="?")
904915
self.predAccValText = wx.StaticText(panel, label="0%")
905916
self.activeAccValText = wx.StaticText(panel, label="0%")
906-
self.statusValText = wx.StaticText(panel, label="Not Built")
907-
blankValText = wx.StaticText(panel, label="")
917+
self.predMeanAccValText = wx.StaticText(panel, label="0%")
918+
self.activeMeanAccValText = wx.StaticText(panel, label="0%")
919+
#self.statusValText = wx.StaticText(panel, label="Not Built")
920+
#blankValText = wx.StaticText(panel, label="")
908921

909922
fgs.AddMany([(inputPerColText, 0, wx.ALIGN_CENTER_VERTICAL),
910923
(self.inputPerColSpin, 0, wx.ALIGN_CENTER_VERTICAL),
@@ -924,18 +937,16 @@ def __init__(self, parent, id, inputSize):
924937
(self.cellsPerColSpin, 0, wx.ALIGN_CENTER_VERTICAL),
925938
(colYText, 0, wx.ALIGN_CENTER_VERTICAL),
926939
(self.colYSpin, 0, wx.ALIGN_CENTER_VERTICAL),
927-
(blankText, 0, wx.ALIGN_CENTER_VERTICAL),
928-
(blankValText, 0, wx.ALIGN_CENTER_VERTICAL),
929940
(inhiRadText, 0, wx.ALIGN_CENTER_VERTICAL),
930941
(self.inhiRadValText, 0, wx.ALIGN_CENTER_VERTICAL),
931942
(predAccText, 0, wx.ALIGN_CENTER_VERTICAL),
932943
(self.predAccValText, 0, wx.ALIGN_CENTER_VERTICAL),
933-
(statusText, 0, wx.ALIGN_CENTER_VERTICAL),
934-
(self.statusValText, 0, wx.ALIGN_CENTER_VERTICAL),
944+
(predMeanAccText, 0, wx.ALIGN_CENTER_VERTICAL),
945+
(self.predMeanAccValText, 0, wx.ALIGN_CENTER_VERTICAL),
935946
(activeAccText, 0, wx.ALIGN_CENTER_VERTICAL),
936-
(self.activeAccValText, 0, wx.ALIGN_CENTER_VERTICAL)])
937-
938-
#fgs.AddGrowableCol(1, 1)
947+
(self.activeAccValText, 0, wx.ALIGN_CENTER_VERTICAL),
948+
(activeMeanAccText, 0, wx.ALIGN_CENTER_VERTICAL),
949+
(self.activeMeanAccValText, 0, wx.ALIGN_CENTER_VERTICAL)])
939950

940951
hbox.Add(fgs, proportion=1, flag=wx.ALL|wx.EXPAND, border=5)
941952
panel.SetSizer(hbox)
@@ -969,6 +980,18 @@ def __refreshInputSize(self):
969980
self.colXSpin.SetRange(4, self.inputSize[0])
970981
self.colYSpin.SetRange(4, self.inputSize[1])
971982

983+
def resetRunningAverages(self):
984+
""" Reset the running average accuracy values for this Region panel. """
985+
self._sumAccPred = 0.0
986+
self._sumAccActive = 0.0
987+
self._meanCount = 0
988+
989+
if self.region!=None:
990+
nx = len(self.region.columnGrid)
991+
ny = len(self.region.columnGrid[0])
992+
self.predictedCols = numpy.zeros((nx,ny), dtype=numpy.uint8)
993+
self.activeCols = numpy.zeros((nx,ny), dtype=numpy.uint8)
994+
972995
def setNextRegionParams(self, nextRegionParams):
973996
"""
974997
Assign a reference to the next (higher) hierarchical Region's Parameter
@@ -1011,8 +1034,8 @@ def regionOnRun(self, evt=None):
10111034

10121035
#if region previously created, rebuild if params changed
10131036
self.__checkCreateRegion()
1014-
if not isOn:
1015-
self.statusValText.SetLabel("Inactive")
1037+
#if not isOn:
1038+
# self.statusValText.SetLabel("Inactive")
10161039

10171040
#enable next hierarchical Region's onButton only if this one is on
10181041
self.enableNextRegion(isOn)
@@ -1067,11 +1090,12 @@ def __checkCreateRegion(self):
10671090
rebuild = True
10681091

10691092
if rebuild:
1070-
self.statusValText.SetLabel("Initializing...")
1093+
#self.statusValText.SetLabel("Initializing...")
10711094
self.region = Region(self.inputSize, colGridSize, pctInputPerCol, \
10721095
pctMinOverlap, localityRadius, pctLocalActivity, \
10731096
cellsPerCol, segActiveThreshold, newSynapseCount)
1074-
self.statusValText.SetLabel("Active")
1097+
#self.statusValText.SetLabel("Active")
1098+
self.resetRunningAverages()
10751099

10761100
#Recreate the region visualizer if previously open
10771101
if self.regionFrame:
@@ -1096,7 +1120,7 @@ def runRegionOnce(self, inputData):
10961120
if not self.region:
10971121
self.__checkCreateRegion()
10981122

1099-
self.statusValText.SetLabel("Active")
1123+
#self.statusValText.SetLabel("Active")
11001124

11011125
#Update inputs, learning states, and run the Region
11021126
self.region.updateInput(inputData)
@@ -1133,6 +1157,16 @@ def runRegionOnce(self, inputData):
11331157
if numpy.sum(a)>0:
11341158
pctA = (1.0*numpy.sum(a*p)) / numpy.sum(a)
11351159

1160+
self._meanCount += 1
1161+
self._sumAccPred += pctP
1162+
self._sumAccActive += pctA
1163+
1164+
meanPctP = self._sumAccPred / self._meanCount
1165+
meanPctA = self._sumAccActive / self._meanCount
1166+
1167+
self.predMeanAccValText.SetLabel(SIGF.format(meanPctP*100.0)+"%")
1168+
self.activeMeanAccValText.SetLabel(SIGF.format(meanPctA*100.0)+"%")
1169+
11361170
self.predAccValText.SetLabel(SIGF.format(pctP*100.0)+"%")
11371171
self.activeAccValText.SetLabel(SIGF.format(pctA*100.0)+"%")
11381172

0 commit comments

Comments
 (0)