sparse_project: Successive projections with sparsely defined restrictions

View source: R/spa.R

sparse_projectR Documentation

Successive projections with sparsely defined restrictions

Description

Compute a vector, closest to x satisfying a set of linear (in)equality restrictions.

Usage

sparse_project(
  x,
  A,
  b,
  neq = length(b),
  w = rep(1, length(x)),
  eps = 0.01,
  maxiter = 1000L,
  ...
)

Arguments

x

[numeric] Vector to optimize, starting point.

A

[data.frame] Coeffiencient matrix in [row,column,coefficient] format.

b

[numeric] Constant vector of the system Ax≤q b

neq

[integer] Number of equalities

w

[numeric] weight vector of same length of x

eps

maximally allowed tolerance

maxiter

maximally allowed number of iterations.

...

extra parameters passed to sparse_constraints

Value

A list with the following entries:

  • x: the adjusted vector

  • status: Exit status:

    • 0: success

    • 1: could not allocate enough memory (space for approximately 2(m+n) doubles is necessary).

    • 2: divergence detected (set of restrictions may be contradictory)

    • 3: maximum number of iterations reached

  • eps: The tolerance achieved after optimizing (see Details).

  • iterations: The number of iterations performed.

  • duration: the time it took to compute the adjusted vector

  • objective: The (weighted) Euclidean distance between the initial and the adjusted vector

Details

The tolerance eps is defined as the maximum absolute value of the difference vector \boldsymbol{Ax}-\boldsymbol{b} for equalities. For inequalities, the difference vector is set to zero when it's value is lesser than zero (i.e. when the restriction is satisfied). The algorithm iterates until either the tolerance is met, the number of allowed iterations is exceeded or divergence is detected.

See Also

project, sparse_constraints

Examples


# the system 
# x + y = 10
# -x <= 0   # ==> x > 0
# -y <= 0   # ==> y > 0
# Defined in the row-column-coefficient form:

A <- data.frame(
    row = c(1,1,2,3)
  , col = c(1,2,1,2)
  , coef= c(1,1,-1,-1)
)
b <- c(10,0,0)

sparse_project(x=c(4,5),A=A,b=b)


lintools documentation built on Jan. 17, 2023, 1:06 a.m.