Learn R Programming

modello (version 0.1.1)

module.lm: R6 class representing a linear model.

Description

R6 class representing a linear model.

R6 class representing a linear model.

Arguments

Super class

modello::module -> module.lm

Methods

Public 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.

Examples

Run this code
# NOT RUN {
## ------------------------------------------------
## Method `module.lm$op`
## ------------------------------------------------

# }
# NOT RUN {
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()
# }
# NOT RUN {
## ------------------------------------------------
## Method `module.lm$obj`
## ------------------------------------------------

# }
# NOT RUN {
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()
# }
# NOT RUN {
## ------------------------------------------------
## Method `module.lm$pars`
## ------------------------------------------------

# }
# NOT RUN {
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()
# }

Run the code above in your browser using DataLab