-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathModel.lua
44 lines (34 loc) · 1.35 KB
/
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
-- Model.lua
-- Abstract class
if false then
m = ModelCONCRETE_CLASS(X, ...) -- other parameters may include y, s, nClasses
optimalTheta, fitInfo = m:fit(fittingOptions) -- fittingOptions depends on CONCRETE_CLASS
predictions, predictionInfo = m:predict(newX, optimalTheta)
end
require 'torch'
-------------------------------------------------------------------------------
-- CONSTRUCTION
-------------------------------------------------------------------------------
local Model = torch.class('Model')
function Model:__init()
-- subclass will supply its own initialization
end
-------------------------------------------------------------------------------
-- PUBLIC METHODS
-------------------------------------------------------------------------------
-- return optimalTheta and perhaps statistics and convergence info
-- ARGS
-- fittingOptions : table, dependent on concrete subclass
-- RETURNS
-- optimalTheta : 1D Tensor of flat parameters
-- fitInfo : table, dependent on concrete subclass
function Model:fit(fittingOptions)
return self:runFit(fittingOptions)
end
-- return predictions and perhaps some other info
-- ARGS
-- newX : 2D Tensor, each row is an observation
-- theta : 1D Tensor of parameters (often the optimalTheta returned by method fit()
function Model:predict(newX, theta)
return self:runPredict(newX, theta)
end