Learn R Programming

modello (version 0.1.1)

.graph: R6 class representing a computational graph

Description

R6 class representing a computational graph

R6 class representing a computational graph

Arguments

Methods

Public methods

Method new()

Initialisation method for reference object of class 'graph'

Usage

.graph$new(name)

Arguments

name

graph name

Method finalize()

Awares if a reference object is remove when when stil referring to an existing graph

Usage

.graph$finalize()

Method name()

Returns the graph name

Usage

.graph$name()

Returns

Returns the graph name

Method id()

Returns the graph id (i.e. position within the GRAPHS_ array)

Usage

.graph$id()

Returns

Returns the graph id

Method pop()

Pop (removes) the graph from the GRAPHS_ array.

Usage

.graph$pop()

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
g = graph.open()
graph.close()
g$is.linked() # TRUE
g$pop()
g$is.linked() # FALSE
modello.close()
}

Method is.linked()

Checks that the reference object is linked to a graph

Usage

.graph$is.linked()

Returns

Retursn TRUE if is linked, FALSE otherwise

Examples

\donttest{
modello.init(10, 10, 10, 10)
g = graph.open()
graph.close()
g$is.linked() # TRUE
g$pop()
g$is.linked() # FALSE
modello.close()
}

Method op()

Applies all the operators for the nodes in the graph

Usage

.graph$op()

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
x1 = number(1)
x2 = number(3)
x3 = number(2)
g = graph.open()
y = log((x1 + x3)**x2)
graph.close()
print(y$v)
x1$v = 2
g$op()
print(y$v)
y$dv = 1
g$bw()
print(x1$dv)
print(x2$dv)
print(x3$dv)
modello.close()
}

Method bw.zero()

Resest the derivative values for the nodes in the graph accoriding to the backward differentiation schema.

Usage

.graph$bw.zero()

Returns

Returns invisible self

Method bw()

Applies all the backward differentiation operators for the nodes in the graph

Usage

.graph$bw()

Returns

Returns invisible self

Examples

\donttest{
modello.init(10, 10, 10, 10)
x1 = number(1)
x2 = number(3)
x3 = number(2)
g = graph.open()
y = log((x1 + x3)**x2)
graph.close()
print(y$v)
x1$v = 2
g$op()
print(y$v)
y$dv = 1
g$bw()
print(x1$dv)
print(x2$dv)
print(x3$dv)
modello.close()
}

Method print()

Prints a representation of the graph

Usage

.graph$print()

Method clone()

The objects of this class are cloneable with this method.

Usage

.graph$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Details

This objects are created by the '.modello' session object that links them to the corresponding graph in the FORTRAN environment.

Examples

Run this code
# NOT RUN {
## ------------------------------------------------
## Method `.graph$pop`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
g = graph.open()
graph.close()
g$is.linked() # TRUE
g$pop()
g$is.linked() # FALSE
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.graph$is.linked`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
g = graph.open()
graph.close()
g$is.linked() # TRUE
g$pop()
g$is.linked() # FALSE
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.graph$op`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x1 = number(1)
x2 = number(3)
x3 = number(2)
g = graph.open()
y = log((x1 + x3)**x2)
graph.close()
print(y$v)
x1$v = 2
g$op()
print(y$v)
y$dv = 1
g$bw()
print(x1$dv)
print(x2$dv)
print(x3$dv)
modello.close()
# }
# NOT RUN {
## ------------------------------------------------
## Method `.graph$bw`
## ------------------------------------------------

# }
# NOT RUN {
modello.init(10, 10, 10, 10)
x1 = number(1)
x2 = number(3)
x3 = number(2)
g = graph.open()
y = log((x1 + x3)**x2)
graph.close()
print(y$v)
x1$v = 2
g$op()
print(y$v)
y$dv = 1
g$bw()
print(x1$dv)
print(x2$dv)
print(x3$dv)
modello.close()
# }

Run the code above in your browser using DataLab