module.lm: R6 class representing a linear model.

Description Super class Methods Author(s) Examples

Description

R6 class representing a linear model.

R6 class representing a linear model.

Super class

modello::module -> module.lm

Methods

Public methods

Inherited methods

Method new()

The initialisation method sets the weights (W), the bais (B) matrices, the objective function (obj), as well as the name of the module. The calculation performed is the following ans = W.op(X) + B

Usage
module.lm$new(tx, nin, nout, obj = mse, b = TRUE)
Arguments
tx

if TRUE it traspose the input matrix

nin

number of column of the input matrix

nout

number of outputs

obj

objective function to adopt

b

if TRUE the intercept term is included

Returns

Returns the total number of parameters


Method op()

Performs: ans = W.op(X) + B

Usage
module.lm$op(X)
Arguments
X

input matrix, reference object of class 'number'

Returns

Returns a reference object of class 'number'

Examples
\donttest{
modello.init(10, 10, 10, 10)
X = number(as.matrix(rnorm(10)), dx=FALSE)
mdl = module.lm$new(1, 1, 1, b=FALSE)
print(X$v)
Yh = mdl$op(X)
print(Yh)
print(Yh$v)
modello.close()
}

Method obj()

Calculates the objective function.

Usage
module.lm$obj(y, X)
Arguments
y

target values, reference object of class 'number'

X

input matrix, reference object of class 'number'

Returns

Returns a reference object of class 'number'

Examples
\donttest{
modello.init(10, 10, 10, 10)
X = number(as.matrix(rnorm(10)), dx=FALSE)
y = number(as.matrix(rnorm(10)), dx=FALSE)
mdl = module.lm$new(1, 1, 1, b=FALSE)
g = graph.open()
J = mdl$obj(y, X)
graph.close()
J$dv = 1
g$bw()
print(lapply(mdl$pars(), function(x)x$dv))
modello.close()
}

Method pars()

Returns the parameters of the module as list with entries: W = weight matrix, and B = bias matrix

Usage
module.lm$pars()
Returns

Returns a flat list with the parametrs of the module

Examples
\donttest{
modello.init(10, 10, 10, 10)
mdl = module.lm$new(1, 1, 1, b=FALSE)
print(mdl$pars())
print(lapply(mdl$pars(), function(x)x$v))
print(lapply(mdl$pars(), function(x)x$dv))
modello.close()
}

Method clone()

The objects of this class are cloneable with this method.

Usage
module.lm$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Author(s)

Filippo Monari

Examples

 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
## ------------------------------------------------
## Method `module.lm$op`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
X = number(as.matrix(rnorm(10)), dx=FALSE)
mdl = module.lm$new(1, 1, 1, b=FALSE)
print(X$v)
Yh = mdl$op(X)
print(Yh)
print(Yh$v)
modello.close()


## ------------------------------------------------
## Method `module.lm$obj`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
X = number(as.matrix(rnorm(10)), dx=FALSE)
y = number(as.matrix(rnorm(10)), dx=FALSE)
mdl = module.lm$new(1, 1, 1, b=FALSE)
g = graph.open()
J = mdl$obj(y, X)
graph.close()
J$dv = 1
g$bw()
print(lapply(mdl$pars(), function(x)x$dv))
modello.close()


## ------------------------------------------------
## Method `module.lm$pars`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
mdl = module.lm$new(1, 1, 1, b=FALSE)
print(mdl$pars())
print(lapply(mdl$pars(), function(x)x$v))
print(lapply(mdl$pars(), function(x)x$dv))
modello.close()

modello documentation built on Feb. 2, 2021, 9:06 a.m.

Related to module.lm in modello...