This class represents an optimization variable.

Variable(rows = NULL, cols = NULL, name = NA_character_, ...)

# S4 method for class 'Variable'
as.character(x)

# S4 method for class 'Variable'
name(x)

# S4 method for class 'Variable'
value(object)

# S4 method for class 'Variable'
grad(object)

# S4 method for class 'Variable'
variables(object)

# S4 method for class 'Variable'
canonicalize(object)

Arguments

rows

The number of rows in the variable.

cols

The number of columns in the variable.

name

(Optional) A character string representing the name of the variable.

...

(Optional) Additional attribute arguments. See Leaf for details.

x, object

A Variable object.

Methods (by generic)

  • name(Variable): The name of the variable.

  • value(Variable): Get the value of the variable.

  • grad(Variable): The sub/super-gradient of the variable represented as a sparse matrix.

  • variables(Variable): Returns itself as a variable.

  • canonicalize(Variable): The canonical form of the variable.

Slots

dim

The dimensions of the variable.

name

(Optional) A character string representing the name of the variable.

Examples

x <- Variable(3, name = "x0") ## 3-int variable
y <- Variable(3, 3, name = "y0") # Matrix variable
as.character(y)
#> [1] "Variable((3, 3), nonneg=FALSE, nonpos=FALSE, pos=FALSE, neg=FALSE, complex=FALSE, imag=FALSE, symmetric=FALSE, diag=FALSE, PSD=FALSE, NSD=FALSE, hermitian=FALSE, boolean=FALSE, integer=FALSE, )"
id(y)
#> [1] 118
is_nonneg(x)
#> [1] FALSE
is_nonpos(x)
#> [1] FALSE
size(y)
#> [1] 9
name(y)
#> [1] "y0"
value(y) <- matrix(1:9, nrow = 3)
value(y)
#>      [,1] [,2] [,3]
#> [1,]    1    4    7
#> [2,]    2    5    8
#> [3,]    3    6    9
grad(y)
#> $`118`
#> 9 x 9 sparse Matrix of class "dgCMatrix"
#>                        
#>  [1,] 1 . . . . . . . .
#>  [2,] . 1 . . . . . . .
#>  [3,] . . 1 . . . . . .
#>  [4,] . . . 1 . . . . .
#>  [5,] . . . . 1 . . . .
#>  [6,] . . . . . 1 . . .
#>  [7,] . . . . . . 1 . .
#>  [8,] . . . . . . . 1 .
#>  [9,] . . . . . . . . 1
#> 
variables(y)
#> [[1]]
#> [1] "Variable((3, 3), nonneg=FALSE, nonpos=FALSE, pos=FALSE, neg=FALSE, complex=FALSE, imag=FALSE, symmetric=FALSE, diag=FALSE, PSD=FALSE, NSD=FALSE, hermitian=FALSE, boolean=FALSE, integer=FALSE, )"
#> 
canonicalize(y)
#> [[1]]
#> [[1]]$type
#> [1] "variable"
#> 
#> [[1]]$dim
#> [1] 3 3
#> 
#> [[1]]$args
#> list()
#> 
#> [[1]]$data
#> [1] 118
#> 
#> [[1]]$class
#> [1] "LinOp"
#> 
#> 
#> [[2]]
#> list()
#>