Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathhist.lua
More file actions
Latest commit
120 lines (112 loc) · 3.01 KB
/
Copy pathhist.lua
File metadata and controls
120 lines (112 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
--
-- rudimentary histogram diplay on the command line.
--
-- Author: Marco Scoffier
-- Date :
-- Mod : Oct 21, 2011
-- + made 80 columns default
-- + save index of max bin in h.max not pointer to bin
--
localfunctionhistc__tostring(h, barHeight)
barHeight=barHeightor10
locallastm=h[h.max].nb
localincr=lastm/(barHeight+1)
localm=lastm-incr
localtl=torch.Tensor(#h):fill(0)
localtoph='|'
localtopm=':'
localtopl='.'
localbar='|'
localblank=''
localyaxis='--------:'
localstr='nsamples:'
str=str..
string.format(' min:(bin:%d/#%d/cntr:%2.2f) max:(bin:%d/#%d/cntr:%2.2f)\n',
h.min,h[h.min].nb,h[h.min].val,
h.max,h[h.max].nb,h[h.max].val)
str=str..yaxis
forj=1,#hdo
str=str..'-'
end
str=str..'\n'
fori=1,barHeightdo
-- y axis
ifi%1==0then
str=str..string.format('%1.2e:',m)
end
forj=1,#hdo
iftl[j] ==1then
str=str..bar
elseifh[j].nb<mthen
str=str..blank
else
-- in the bracket
tl[j] =1
-- find 1/3rds
localp= (lastm-h[j].nb) /incr
ifp>0.66then
str=str..toph
elseifp>0.33then
str=str..topm
else
str=str..topl
end
end
end
str=str..'\n'
lastm=m
m=m-incr
end
-- x axis
str=str..yaxis
forj=1,#hdo
if ((j-2) %6==0)then
str=str..'^'
else
str=str..'-'
end
end
str=str..'\ncenters '
forj=1,#hdo
if ((j-2) %6==0)then
ifh[j].val<0then
str=str..'-'
else
str=str..'+'
end
str=str..string.format('%1.2f ',math.abs(h[j].val))
end
end
returnstr
end
-- a simple function that computes the histogram of a tensor
functiongnuplot.histc(...)
-- get args
localargs= {...}
localtensor=args[1] orerror('usage: gnuplot.histc (tensor [, nBins] [, min] [, max]')
localbins=args[2] or80-8
localmin=args[3] ortensor:min()
localmax=args[4] ortensor:max()
localraw=args[5] orfalse
-- compute histogram
localhist=torch.histc(tensor:double(),bins,min,max)
-- return raw histogram (no extra info)
ifrawthenreturnhistend
-- cleanup hist
localcleanhist= {}
cleanhist.raw=hist
local_,mx=torch.max(cleanhist.raw,1)
local_,mn=torch.min(cleanhist.raw,1)
cleanhist.bins=bins
cleanhist.binwidth= (max-min)/bins
fori=1,binsdo
cleanhist[i] = {}
cleanhist[i].val=min+ (i-0.5)*cleanhist.binwidth
cleanhist[i].nb=hist[i]
end
cleanhist.max=mx[1]
cleanhist.min=mn[1]
-- print function
setmetatable(cleanhist, {__tostring=histc__tostring})
returncleanhist
end