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:
-rw-r--r--Logger.lua63
-rw-r--r--init.lua1
-rw-r--r--nnx-1.0-1.rockspec1
3 files changed, 65 insertions, 0 deletions
diff --git a/Logger.lua b/Logger.lua
new file mode 100644
index 0000000..326d1d1
--- /dev/null
+++ b/Logger.lua
@@ -0,0 +1,63 @@
+
+local Logger = torch.class('nn.Logger')
+
+function Logger:__init(filename)
+ if filename then
+ self.file = io.open(filename,'w')
+ else
+ self.file = io.stdout
+ print('<Logger> warning: no file name provided, logging to std out')
+ end
+ self.empty = true
+ self.symbols = {}
+ self.figures = {}
+end
+
+function Logger:add(symbols)
+ -- (1) first time ? print symbols' names on first row
+ if self.empty then
+ self.empty = false
+ self.nsymbols = #symbols
+ for k,val in pairs(symbols) do
+ self.file:write(k .. '\t')
+ self.symbols[k] = {}
+ end
+ self.file:write('\n')
+ end
+ -- (2) print all symbols on one row
+ for k,val in pairs(symbols) do
+ if type(val) == 'number' then
+ self.file:write(string.format('%11.4e',val) .. '\t')
+ elseif type(val) == 'string' then
+ self.file:write(val .. '\t')
+ else
+ xlua.error('can only log numbers and strings', 'Logger')
+ end
+ end
+ self.file:write('\n')
+ self.file:flush()
+ -- (3) save symbols in internal table
+ for k,val in pairs(symbols) do
+ table.insert(self.symbols[k], val)
+ end
+end
+
+function Logger:plot(...)
+ if not lab.plot then
+ if not self.warned then
+ print('<Logger> warning: cannot plot with this version of Torch')
+ end
+ return
+ end
+ for name,list in pairs(self.symbols) do
+ local nelts = #list
+ local plot_x = lab.range(1,nelts)
+ local plot_y = torch.Tensor(nelts)
+ for i = 1,nelts do
+ plot_y[i] = list[i]
+ end
+ self.figures[name] = lab.figure(self.figures[name])
+ lab.plot(name, plot_x, plot_y, '-')
+ lab.title(name)
+ end
+end
diff --git a/init.lua b/init.lua
index dd7d777..37b4c4d 100644
--- a/init.lua
+++ b/init.lua
@@ -46,6 +46,7 @@ torch.include('nnx', 'test-omp.lua')
-- tools:
torch.include('nnx', 'ConfusionMatrix.lua')
+torch.include('nnx', 'Logger.lua')
-- OpenMP module:
torch.include('nnx', 'OmpModule.lua')
diff --git a/nnx-1.0-1.rockspec b/nnx-1.0-1.rockspec
index c04137c..636e864 100644
--- a/nnx-1.0-1.rockspec
+++ b/nnx-1.0-1.rockspec
@@ -57,6 +57,7 @@ build = {
install_files(/lua/nnx init.lua)
install_files(/lua/nnx Abs.lua)
install_files(/lua/nnx ConfusionMatrix.lua)
+ install_files(/lua/nnx Logger.lua)
install_files(/lua/nnx HardShrink.lua)
install_files(/lua/nnx Narrow.lua)
install_files(/lua/nnx Power.lua)