diff options
author | soumith <soumith@gmail.com> | 2016-01-23 13:48:19 +0300 |
---|---|---|
committer | soumith <soumith@gmail.com> | 2016-01-23 13:48:19 +0300 |
commit | ae195f33d16ed45ef83f4ed1bff65d3943c20303 (patch) | |
tree | d5b16830552876a8f6d7f70cda4531e22cf77d26 | |
parent | 1de7773569382f3d6fea449d42d335a806d16f72 (diff) |
lua52 fix for math.log10
-rw-r--r-- | ConfusionMatrix.lua | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/ConfusionMatrix.lua b/ConfusionMatrix.lua index 8a892c2..2809fbe 100644 --- a/ConfusionMatrix.lua +++ b/ConfusionMatrix.lua @@ -38,7 +38,7 @@ function ConfusionMatrix:_add(p, t) assert(t and type(t) == 'number') -- non-positive values are considered missing -- and therefore ignored - if t > 0 then + if t > 0 then self.mat[t][p] = self.mat[t][p] + 1 end end @@ -83,7 +83,7 @@ function ConfusionMatrix:batchAdd(predictions, targets) else error("predictions has invalid number of dimensions") end - + self._target:resize(targets:size()):copy(targets) if targets:dim() == 1 then -- targets is a vector of classes @@ -100,7 +100,7 @@ function ConfusionMatrix:batchAdd(predictions, targets) else error("targets has invalid number of dimensions") end - + --loop over each pair of indices for i = 1,preds:size(1) do self:_add(preds[i], targs[i]) @@ -188,13 +188,21 @@ function ConfusionMatrix:farFrr() return self._classFrrs, self._classFars, returnFrrs, returnFars end +local function log10(n) + if math.log10 then + return math.log10(n) + else + return math.log(n) / math.log(10) + end +end + function ConfusionMatrix:__tostring__() self:updateValids() local str = {'ConfusionMatrix:\n'} local nclasses = self.nclasses table.insert(str, '[') local maxCnt = self.mat:max() - local nDigits = math.max(8, 1 + math.ceil(math.log10(maxCnt))) + local nDigits = math.max(8, 1 + math.ceil(log10(maxCnt))) for t = 1,nclasses do local pclass = self.valids[t] * 100 pclass = string.format('%2.3f', pclass) @@ -305,7 +313,7 @@ function ConfusionMatrix:render(sortmode, display, block, legendwidth) win1:setcolor{r=0,g=0,b=0} win1:rectangle((#render)[2],(i-1)*block,legendwidth,block) win1:fill() - + -- % win1:setfont(qt.QFont{serif=false, size=fontsize}) local gscale = freqs[order[i]]/freqs:max()*0.9+0.1 --3/4 |