dot-graph: R6 class representing a computational graph

Description Details Methods Examples

Description

R6 class representing a computational graph

R6 class representing a computational graph

Details

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

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.

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
## ------------------------------------------------
## Method `.graph$pop`
## ------------------------------------------------


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


## ------------------------------------------------
## Method `.graph$is.linked`
## ------------------------------------------------


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


## ------------------------------------------------
## Method `.graph$op`
## ------------------------------------------------


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 `.graph$bw`
## ------------------------------------------------


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()

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

Related to dot-graph in modello...