dot-number: Number Legnth

Description Details Active bindings Methods Author(s) Examples

Description

Number Legnth

Number Legnth

Details

R6 class representing a number

Object of this class are created by the '.modello' session object that linkes them with the corresponding numbers in the FORTRAN environment.

Active bindings

v

Sets or gets the number value

dv

Sets or gets the number derivative value

Methods

Public methods


Method new()

Initialise the reference object of class 'number'

Usage
.number$new(name = NULL)
Arguments
name

number name


Method finalize()

Awares of a reference object associated to an existing number is removed

Usage
.number$finalize()

Method name()

Returns the name of the number.

Usage
.number$name()
Returns

Returns the name of the number


Method id()

Returns the id of the number (i.e. its position index in the NUMBERS_ array).

Usage
.number$id()
Returns

Returns the id of the number


Method pop()

Pop (removes) the number from the NUMBERS_ array.

Usage
.number$pop()
Returns

Returns invisible self

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
}

Method is.linked()

Checks that the reference object is linked to a number

Usage
.number$is.linked()
Returns

Retursn TRUE if is linked, FALSE otherwise

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()
}

Method rank()

Returns the rank of the number.

Usage
.number$rank()
Returns

Returns the rank of the number

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
x$rank() # 2
modello.close()
}

Method has.dx()

Returns TRUE if the number has derivative, FALSE otherwise

Usage
.number$has.dx()
Returns

TRUE/FALSE

Examples
\donttest{
modello.init(10, 10, 10, 10)
x1 = number(1)
x1$has.dx() # TRUE
x2 = number(1, dx=FALSE)
x2$has.dx() # FALSE
modello.close()
}

Method collect()

Returns a list representation of the number

Usage
.number$collect()

Method save()

Saves the number in RDS format

Usage
.number$save(file = NULL, ...)
Arguments
file

filename, if null the number name is used

...

additional arguments for the function saveRDS


Method length()

Returns the size of the number

Usage
.number$length()
Returns

Returns the size of the number

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3))
x$length() # 3
modello.close()
}

Method dim()

Returns the shape of the number

Usage
.number$dim()
Returns

Returns the number shape

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9, 3, 3)))
x$dim() # c(3, 3)
modello.close()
}

Method set.v()

Sets the value of the number

Usage
.number$set.v(x)
Arguments
x

number value

Returns

Returns invisible self

Examples
modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()

Method get.v()

Returns the value of a number

Usage
.number$get.v()
Returns

Returns the number value

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()
}

Method set.dv()

Sets the derivative value of the number

Usage
.number$set.dv(x)
Arguments
x

number derivative value

Returns

Returns invisible self

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
}

Method set.slice()

Sets the values of a slice in a number

Usage
.number$set.slice(v, ..., dx = FALSE)
Arguments
v

value to be set

...

indexes along the number dimensions defining the slice

dx

if TRUE the slice is taken from the gradient

Returns

Returns invisible self

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.slice(1, 1:3, 1:3)
x$set.slice(2, 1:3, 1:3, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()
}

Method set.flat_slice()

Sets the values of a slice in a number considering the number flat

Usage
.number$set.flat_slice(v, s, dx = FALSE)
Arguments
v

value to be set

s

indexes defining the slice

dx

if TRUE the slice is taken from the gradient

Returns

Returns invisible self

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.flat_slice(1, 1:9)
x$set.flat_slice(2, 1:9, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()
}

Method get.dv()

Returns the derivative value of a number

Usage
.number$get.dv()
Returns

Returns the number value

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()
}

Method slice()

Create a slice of the number

Usage
.number$slice(...)
Arguments
...

slice indexes

name

outout number name

Returns

Returns a reference object of class 'number' with the slice

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1:2, 1:3)
print(y$v)
modello.close()
}

Method flat_slice()

Create a flat slice of the number

Usage
.number$flat_slice(s)
Arguments
s

flat slice indexes

name

outout number name

Returns

Returns a reference object of class 'number' with the flat slice

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$flat_slice(1:6)
print(y$v)
modello.close()
}

Method contiguous.slice()

Create a contiguous slice of the number. Slice along the leading order (columns).

The number values are not copied but only referred through pointers.

Usage
.number$contiguous.slice(s1, s2 = NULL)
Arguments
s1

intial index of the contiguous slice

s2

final index of the contiguous slice

name

outout number name

Returns

Returns a reference object of class 'number' with the contiguous slice

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1, 2)
print(y$v)
modello.close()
}

Method reshape()

Reshape the number according the the given shape vector.

The number is not copied but reshaped through pointers.

Usage
.number$reshape(shp, name = NULL)
Arguments
shp

shape vector

name

output number name

Returns

Returns a reference object of class 'number' with the reshape

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3, 4, 5, 6))
y = x$reshape(c(3, 2))
print(x)
print(x$v)
print(y)
print(y$v)
modello.close()
}

Method drop.dim()

Reshape the number by dropping the collapsed dimensions.

The number is not copied but reshaped through pointers.

Usage
.number$drop.dim()
Arguments
name

output number name

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
print(x)
print(x$v)
y = x$drop.dim()
print(y)
print(y$v)
modello.close()
}

Method bind()

Binds the number to another along the given dimension

Usage
.number$bind(x, k)
Arguments
x

number to bind

k

dimension index

name

name of the output number

Returns

Returns areference object of class 'number'

Examples
\donttest{
modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
y = number(as.matrix(c(4, 5, 6)))
z = x$bind(y, 2)
print(z)
print(z$v)
modello.close()
}

Method op()

Runs the node operator that generated the number

Usage
.number$op()
Returns

Returns invisible self

Examples
\donttest{
modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(1)
x2 = number(2)
x3 = x1 + x2
graph.close()
print(x3$v)
x1$v = 2
x3$op()
print(x3$v)
modello.close()
}

Method bw.zero()

Resest the derivative values for the number node accoriding to the backward differentiation schema.

Usage
.number$bw.zero()
Returns

Returns invisible self

Examples
\donttest{
modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(4)
x2 = number(2)
x3 = x1 ** x2
g = graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()
}

Method bw()

Applies bakward differentiation to the number node

Usage
.number$bw()
Returns

Returns invisible self

Examples
\donttest{
modello.init(10, 10, 10, 10)
x1 = number(4)
x2 = number(2)
g = graph.open()
x3 = x1 ** x2
graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()
}

Method print()

Prints a representation of the number

Usage
.number$print()

Method clone()

The objects of this class are cloneable with this method.

Usage
.number$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Author(s)

Filippo Monari

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
 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
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
## ------------------------------------------------
## Method `.number$pop`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()


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


modello.init(10, 10, 10, 10)
x = number(1)
x$is.linked() # TRUE
x$pop()
x$is.linked() # FALSE
modello.close()


## ------------------------------------------------
## Method `.number$rank`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
x$rank() # 2
modello.close()


## ------------------------------------------------
## Method `.number$has.dx`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x1 = number(1)
x1$has.dx() # TRUE
x2 = number(1, dx=FALSE)
x2$has.dx() # FALSE
modello.close()


## ------------------------------------------------
## Method `.number$length`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3))
x$length() # 3
modello.close()


## ------------------------------------------------
## Method `.number$dim`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9, 3, 3)))
x$dim() # c(3, 3)
modello.close()


## ------------------------------------------------
## Method `.number$set.v`
## ------------------------------------------------

modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()

## ------------------------------------------------
## Method `.number$get.v`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(1)
x$set.v(2)
x$get.v()
modello.close()


## ------------------------------------------------
## Method `.number$set.dv`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()


## ------------------------------------------------
## Method `.number$set.slice`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.slice(1, 1:3, 1:3)
x$set.slice(2, 1:3, 1:3, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()


## ------------------------------------------------
## Method `.number$set.flat_slice`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(matrix(0, 3, 3))
print(x$v)
print(x$dv)
x$set.flat_slice(1, 1:9)
x$set.flat_slice(2, 1:9, dx=TRUE)
print(x$v)
print(x$dv)
modello.close()


## ------------------------------------------------
## Method `.number$get.dv`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(1)
x$set.dv(1)
x$get.dv()
modello.close()


## ------------------------------------------------
## Method `.number$slice`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1:2, 1:3)
print(y$v)
modello.close()


## ------------------------------------------------
## Method `.number$flat_slice`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$flat_slice(1:6)
print(y$v)
modello.close()


## ------------------------------------------------
## Method `.number$contiguous.slice`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(matrix(rnorm(9), 3, 3))
print(x$v)
y = x$slice(1, 2)
print(y$v)
modello.close()


## ------------------------------------------------
## Method `.number$reshape`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(c(1, 2, 3, 4, 5, 6))
y = x$reshape(c(3, 2))
print(x)
print(x$v)
print(y)
print(y$v)
modello.close()


## ------------------------------------------------
## Method `.number$drop.dim`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
print(x)
print(x$v)
y = x$drop.dim()
print(y)
print(y$v)
modello.close()


## ------------------------------------------------
## Method `.number$bind`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x = number(as.matrix(c(1, 2, 3)))
y = number(as.matrix(c(4, 5, 6)))
z = x$bind(y, 2)
print(z)
print(z$v)
modello.close()


## ------------------------------------------------
## Method `.number$op`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(1)
x2 = number(2)
x3 = x1 + x2
graph.close()
print(x3$v)
x1$v = 2
x3$op()
print(x3$v)
modello.close()


## ------------------------------------------------
## Method `.number$bw.zero`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
g = graph.open()
x1 = number(4)
x2 = number(2)
x3 = x1 ** x2
g = graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()


## ------------------------------------------------
## Method `.number$bw`
## ------------------------------------------------


modello.init(10, 10, 10, 10)
x1 = number(4)
x2 = number(2)
g = graph.open()
x3 = x1 ** x2
graph.close()
print(x1$dv)
print(x2$dv)
x3$dv = 1
x3$bw()
print(x1$dv)
print(x2$dv)
x3$bw.zero()
print(x1$dv)
print(x2$dv)
modello.close()

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

Related to dot-number in modello...