Functions

Functions

The Functions module provides types that represent decision variables and functions of these decision variables that possess a certain structure, such as being affine or quadratic in the decision variables.

Various operators are overloaded to make it easy to construct such functions.

Example

julia> x, y = Variable.(1 : 2)
2-element Array{Parametron.Functions.Variable,1}:
 Parametron.Functions.Variable(1)
 Parametron.Functions.Variable(2)

julia> fun = 3 * (x + y) + 4
3 * x1 + 3 * x2 + 4

julia> typeof(fun)
Parametron.Functions.AffineFunction{Int64}

julia> fun.linear
2-element Array{Parametron.Functions.LinearTerm{Int64},1}:

 3 * x1
 3 * x2

julia> fun.constant
Base.RefValue{Int64}(4)

The Functions module also provides in-place versions of certain common operations, e.g., add!, subtract!, and vecdot!, which may be used to evaluate operations performed on the functions into a preallocated destination without any heap allocations.

source

Types

struct Variable

Represents a single decision variable.

source
struct LinearTerm{T}

Represents a scalar linear term, i.e. a decision variable scaled by a coefficient.

source
struct QuadraticTerm{T}

Represents a scalar quadratic term, i.e. the product of two decision variables scaled by a coefficient.

source
struct AffineFunction{T}

A scalar affine function represented by a sum of LinearTerms and a constant.

AffineFunction overloads the call operator, which can be used to evalute the function given values for the decision variables. The call operator takes an AbstractDict{Variable, T} collection, which associates values with variables.

Example

julia> x, y = Variable.(1 : 2);

julia> affinefun = 2 * x + 3 * y + 4
2 * x1 + 3 * x2 + 4

julia> vals = Dict(x => 4, y => -3);

julia> affinefun(vals)
3
source
struct QuadraticFunction{T}

A scalar quadratic function represented by a sum of QuadraticTerms and an AffineFunction.

QuadraticFunction overloads the call operator, which can be used to evalute the function given values for the decision variables. The call operator takes an AbstractDict{Variable, T} collection, which associates values with variables.

Examples

julia> x, y = Variable.(1 : 2);

julia> quadraticfun = 2 * x^2 + 3 * x * y - 2 * y + 4
2 * x1 * x1 + 3 * x1 * x2 + -2 * x2 + 4

julia> vals = Dict(x => 4, y => -3);

julia> quadraticfun(vals)
6
source

Exported functions

Re-express a term or function in a canonical form.

source
canonicalize(term)

Re-express the QuadraticTerm term so that the index of term.rowvar is less than or equal to that of term.colvar.

Example

julia> x, y = Variable.(1 : 2);

julia> term = 3 * y * x
3 * x2 * x1

julia> canonicalize(term)
3 * x1 * x2
source
canonicalize(f)

Return a canonicalized version of f::AffineFunction, namely with linear terms sorted by variable index and with terms corresponding to the same variable combined.

Example

julia> x, y = Variable.(1 : 2);

julia> f = y + x - 2 * y + 3
1 * x2 + 1 * x1 + -2 * x2 + 3

julia> canonicalize(f)
1 * x1 + -1 * x2 + 3
source
canonicalize(f)

Return a canonicalized version of f::QuadraticFunction. See canonicalize(f::QuadraticTerm) and canonicalize(f::AffineFunction) for more details. Quadratic terms are ordered lexicographically by (term.rowvar, term.colvar).

Example

julia> x, y = Variable.(1 : 2);

julia> f = x * y + y * x + y + y + x - y
1 * x1 * x2 + 1 * x2 * x1 + 1 * x2 + 1 * x2 + 1 * x1 + -1 * x2 + 0

julia> canonicalize(f)
2 * x1 * x2 + 1 * x1 + 1 * x2 + 0
source

In-place version of canonicalize.

source
prune_zero(f; kwargs...)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:299.

prune_zero(f; kwargs...)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:415.

Prune terms with (approximately) zero coefficients.

source
prune_zero!(f; atol)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:295.

prune_zero!(f; atol)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:410.

In-place version of prune_zero.

source

In-place math functions (unexported)

Add x to f, modifying f.

add!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:452.

add!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:453.

add!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:454.

add!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:455.

add!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:457.

add!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:458.

add!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:459.

add!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:461.

source

Subtract x from f, modifying f.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:474.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:475.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:476.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:478.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:487.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:488.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:489.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:490.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:491.

subtract!(f, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:493.

subtract!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:502.

source

Multiply x by y and add the result to dest.

muladd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:516.

muladd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:524.

muladd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:527.

muladd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:535.

muladd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:538.

muladd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:546.

muladd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:549.

source

Take the dot product of vectors x and y, storing the result in dest.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:713.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:716.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:718.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:720.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:722.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:724.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:726.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:728.

vecdot!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:730.

source

Add vector x to vector y, storing the result in dest.

vecadd!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:754.

source

Subtract vector y from vector x, storing the result in dest.

vecsubtract!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:754.

source

Compute the matrix-vector product A * x, storing the result in y.

matvecmul!(y, A, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:779.

matvecmul!(y, A, x)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:804.

matvecmul!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:828.

source

Compute the bilinear form transpose(x) * A * y, storing the result in dest.

bilinearmul!(dest, Q, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:845.

source

Scale a vector by a number and store the result in dest.

scale!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:877.

scale!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:888.

scale!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:899.

scale!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:910.

scale!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:918.

scale!(dest, x, y)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:923.

source

Vertically concatenate a number of vectors, storing the result in y.

vcat!(y, args)

defined at /home/travis/build/tkoolen/Parametron.jl/src/functions.jl:989.

source