-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsae_model.lua
63 lines (56 loc) · 1.78 KB
/
sae_model.lua
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
require 'nn'
require './lib/util'
require './lib/SplitSensorType'
require './lib/JoinSensorType'
require './lib/GradientBooster'
function sae_model(subject_id)
local model = nn.Sequential()
local parallel = nn.ParallelTable()
-- seprating gradiometers and magnetometers
model:add(nn.SplitSensorType())
for i = 1, 2 do
-- weight-sharing MLP layers
local mlp = nil
if i == 1 then
-- gradiometers
-- 204 MLPs
mlp = nn.Sequential()
mlp:add(nn.Reshape(1, 204, TM))
mlp:add(nn.SpatialConvolution(1, 32, TM, 1))
mlp:add(nn.SoftSign())
mlp:add(nn.SpatialConvolution(32, 16, 1, 1))
mlp:add(nn.SoftSign())
-- initializing with denosing autoencoders
local ae = torch.load(string.format("model/grad_ae%d.model", subject_id))
mlp:get(2).weight:copy(ae:get(2).weight)
mlp:get(2).bias:copy(ae:get(2).bias)
mlp:get(4).weight:copy(ae:get(4).weight)
mlp:get(4).bias:copy(ae:get(4).bias)
else
-- magnetometers
-- 102 MLPs
mlp = nn.Sequential()
mlp:add(nn.Reshape(1, 102, TM))
mlp:add(nn.SpatialConvolution(1, 32, TM, 1))
mlp:add(nn.SoftSign())
mlp:add(nn.SpatialConvolution(32, 16, 1, 1))
mlp:add(nn.SoftSign())
-- initializing with denosing autoencoders
local ae = torch.load(string.format("model/mag_ae%d.model", subject_id))
mlp:get(2).weight:copy(ae:get(2).weight)
mlp:get(2).bias:copy(ae:get(2).bias)
mlp:get(4).weight:copy(ae:get(4).weight)
mlp:get(4).bias:copy(ae:get(4).bias)
end
parallel:add(mlp)
end
model:add(parallel)
-- joining MLP outputs (16x204 + 16x102)
model:add(nn.JoinSensorType())
-- logistic regression layer
model:add(nn.Reshape(CH * 16, 1, 1))
model:add(nn.SpatialConvolution(CH * 16, 1, 1, 1))
model:add(nn.Sigmoid())
model:add(nn.Reshape(1))
return model
end