Skip to content
Browse files

added dense support

  • Loading branch information...
1 parent a8b8cb9 commit 490c5e2df1ca7f1afbc91b339df553b92d786ea1 @koraykv committed Oct 3, 2012
Showing with 32 additions and 5 deletions.
  1. +2 −2 README.md
  2. +23 −1 data.lua
  3. +7 −2 svmtest.lua
View
4 README.md
@@ -2,8 +2,8 @@ torch-svm
=========
Reimplementation of Leon Bottou's svmsgd and svmasgd.
-Be aware, I would suggest using Leon's stuff (http://leon.bottou.org/projects/sgd)
-This implementation is 2-10 times slower :), but it is in Lua.
+I would suggest using Leon's stuff (http://leon.bottou.org/projects/sgd)
+This implementation is 2-10 times slower :) depending on the sparsity.
```
git clone git://github.com/koraykv/torch-svm.git
View
24 data.lua
@@ -16,8 +16,30 @@ function svm:dataset(fname)
function dataset:setbuffersize(bsize) buffersize = bsize end
function dataset:getbuffersize() return buffersize end
+
+ -- be careful , this is just for experimentation, it will be very very very slooooooow.
+ local dense = false
+ function dataset:dense()
+ dense = true
+ end
+
+ local dx
+ local function todense(ind,x)
+ dx = dx or torch.FloatTensor(maxdim)
+ dx:zero()
+ for i=1,ind:size(1) do
+ dx[ind[i]] = x[i]
+ end
+ return {nil,dx}
+ end
+
setmetatable(dataset,{__index = function(self,ind)
- return data[ind]
+ if dense then
+ local ex = data[ind]
+ return {ex[1],todense(ex[2][1],ex[2][2])}
+ else
+ return data[ind]
+ end
end})
return dataset
View
9 svmtest.lua
@@ -1,9 +1,14 @@
require 'svm'
-dtr=svm:dataset('rcv1.train.bin')
+if #arg == 0 then arg = nil end
+
+dtr=svm:dataset('rcv1.test.bin')
dte=svm:dataset('rcv1.test.bin')
-if #arg == 0 then arg = nil end
+if arg and (arg[1] == 'dense' or arg[2] == 'dense') then
+ dtr:dense()
+ dte:dense()
+end
if not arg or (arg and arg[1] == 'sgd-hinge') then
print('======================================')

0 comments on commit 490c5e2

Please sign in to comment.
Something went wrong with that request. Please try again.