Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/clementfarabet/lua---nnx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClement Farabet <clement.farabet@gmail.com>2011-09-12 21:29:13 +0400
committerClement Farabet <clement.farabet@gmail.com>2011-09-12 21:29:13 +0400
commit96e51b2e5a58400639132b9a0aa0dd84be5dea09 (patch)
treea13ae3d801c0b23ffb7153405fcf48f292e404bc
parentba0b319f123b85665e4ae4c8ae45b7a63c2fe3c0 (diff)
ConfusionMatri is now agnostic to type (cuda compat)
-rw-r--r--ConfusionMatrix.lua10
1 files changed, 5 insertions, 5 deletions
diff --git a/ConfusionMatrix.lua b/ConfusionMatrix.lua
index ed3f000..b6c841d 100644
--- a/ConfusionMatrix.lua
+++ b/ConfusionMatrix.lua
@@ -6,8 +6,8 @@ function ConfusionMatrix:__init(nclasses, classes)
classes = nclasses
nclasses = #classes
end
- self.mat = lab.zeros(nclasses,nclasses)
- self.valids = lab.zeros(nclasses)
+ self.mat = torch.FloatTensor(nclasses,nclasses):zero()
+ self.valids = torch.FloatTensor(nclasses):zero()
self.nclasses = nclasses
self.totalValid = 0
self.averageValid = 0
@@ -20,13 +20,13 @@ function ConfusionMatrix:add(prediction, target)
self.mat[target][prediction] = self.mat[target][prediction] + 1
elseif type(target) == 'number' then
-- prediction is a vector, then target assumed to be an index
- local prediction_1d = torch.Tensor(prediction):resize(self.nclasses)
+ local prediction_1d = torch.FloatTensor(self.nclasses):copy(prediction)
local _,prediction = lab.max(prediction_1d)
self.mat[target][prediction[1]] = self.mat[target][prediction[1]] + 1
else
-- both prediction and target are vectors
- local prediction_1d = torch.Tensor(prediction):resize(self.nclasses)
- local target_1d = torch.Tensor(target):resize(self.nclasses)
+ local prediction_1d = torch.FloatTensor(self.nclasses):copy(prediction)
+ local target_1d = torch.FloatTensor(self.nclasses):copy(target)
local _,prediction = lab.max(prediction_1d)
local _,target = lab.max(target_1d)
self.mat[target[1]][prediction[1]] = self.mat[target[1]][prediction[1]] + 1