Skip to contents

For a system with costs (an optimization system): generate_cost(sys) returns the R function f(u, p) of the consolidated cost; calculate_cost_gradient(sys) and calculate_cost_hessian(sys) return its symbolic gradient and Hessian with respect to the unknowns, and generate_cost_gradient(sys), generate_cost_hessian(sys) the corresponding R functions. generate_cons(sys) returns the constraint function (the residuals of canonical_constraints()), calculate_constraint_jacobian(sys) its Jacobian and calculate_constraint_hessian(sys) the list of Hessians of its rows, with generate_* counterparts.

Usage

generate_cost(sys, ...)

calculate_cost_gradient(sys, simplify = FALSE)

generate_cost_gradient(sys, simplify = FALSE, ...)

calculate_cost_hessian(sys, sparse = FALSE, simplify = FALSE)

generate_cost_hessian(sys, simplify = FALSE, sparse = FALSE, ...)

generate_cons(sys, ...)

calculate_constraint_jacobian(sys, simplify = FALSE, sparse = FALSE)

generate_constraint_jacobian(sys, simplify = FALSE, sparse = FALSE, ...)

calculate_constraint_hessian(sys, simplify = FALSE, sparse = FALSE)

generate_constraint_hessian(sys, simplify = FALSE, sparse = FALSE, ...)

generate_multiobjective_cost(sys, ...)

calculate_multiobjective_jacobian(sys, simplify = FALSE, sparse = FALSE)

generate_multiobjective_jacobian(sys, simplify = FALSE, sparse = FALSE, ...)

calculate_multiobjective_hessian(sys, simplify = FALSE, sparse = FALSE)

generate_multiobjective_hessian(sys, simplify = FALSE, sparse = FALSE, ...)

Arguments

sys

A complete System with costs.

...

Passed to the code generator.

simplify

Simplify the expressions.

sparse

Unused; matrices are dense.

Value

An R function of (u, p), a list of expressions (gradient), a symbolic matrix (Hessian, Jacobian), or a list of them.

Details

The multiobjective variants keep the costs separate: generate_multiobjective_cost(sys) returns the vector of costs(sys), calculate_multiobjective_jacobian(sys) its Jacobian and calculate_multiobjective_hessian(sys) one Hessian per cost.

Examples

x <- Variable("x"); y <- Variable("y"); a <- Parameter("a")
sys <- complete(System(list(), costs = list((a - x)^2 + 100 * (y - x^2)^2), name = "rosenbrock"))
f <- generate_cost(sys)
f(c(0, 0), 1)
#> [1] 1
calculate_cost_gradient(sys)
#> [[1]]
#> -2*a + x*(400*x^2 - 400*y) + 2*x
#> 
#> [[2]]
#> -200*x^2 + 200*y
#> 
generate_cost_gradient(sys)(c(0, 0), 1)
#> [1] -2  0
generate_cost_hessian(sys)(c(1, 1), 1)
#>      [,1] [,2]
#> [1,]  802 -400
#> [2,] -400  200