ldei: Weighted Least Distance Programming with equality and...

View source: R/ldei.R

ldeiR Documentation

Weighted Least Distance Programming with equality and inequality constraints.

Description

Solves the following underdetermined inverse problem:

\min(\sum {x_i}^2)

subject to

Ex=f

Gx>=h

uses least distance programming subroutine ldp (FORTRAN) from Linpack

The model has to be UNDERdetermined, i.e. the number of independent equations < number of unknowns.

Usage

ldei(E, F, G = NULL, H = NULL,
     tol = sqrt(.Machine$double.eps), verbose = TRUE,
     lower = NULL, upper = NULL)

Arguments

E

numeric matrix containing the coefficients of the equality constraints Ex=F; if the columns of E have a names attribute, they will be used to label the output.

F

numeric vector containing the right-hand side of the equality constraints.

G

numeric matrix containing the coefficients of the inequality constraints Gx>=H; if the columns of G have a names attribute and the columns of E do not, they will be used to label the output.

H

numeric vector containing the right-hand side of the inequality constraints.

tol

tolerance (for singular value decomposition, equality and inequality constraints).

verbose

logical to print warnings and messages.

upper, lower

vector containing upper and lower bounds on the unknowns. If one value, it is assumed to apply to all unknowns. If a vector, it should have a length equal to the number of unknowns; this vector can contain NA for unbounded variables. The upper and lower bounds are added to the inequality conditions G*x>=H.

Value

a list containing:

X

vector containing the solution of the least distance with equalities and inequalities problem.

unconstrained.solution

vector containing the unconstrained solution of the least distance problem, i.e. ignoring Gx>=h.

residualNorm

scalar, the sum of absolute values of residuals of equalities and violated inequalities; should be zero or very small if the problem is feasible.

solutionNorm

scalar, the value of the quadratic function at the solution, i.e. the value of \sum {w_i*x_i}^2.

IsError

logical, TRUE if an error occurred.

type

the string "ldei", such that how the solution was obtained can be traced.

numiter

the number of iterations.

Note

One of the steps in the ldei algorithm is the creation of an orthogonal basis, constructed by Singular Value Decomposition. As this makes use of random numbers, it may happen - for problems that are difficult to solve - that ldei sometimes finds a solution or fails to find one for the same problem, depending on the random numbers used to create the orthogonal basis. If it is suspected that this is happening, trying a few times may find a solution. (example RigaWeb is such a problem).

Author(s)

Karline Soetaert <karline.soetaert@nioz.nl>.

References

Lawson C.L.and Hanson R.J. 1974. Solving Least Squares Problems, Prentice-Hall

Lawson C.L.and Hanson R.J. 1995. Solving Least Squares Problems. SIAM classics in applied mathematics, Philadelphia. (reprint of book)

See Also

Minkdiet, for a description of the Mink diet example.

lsei, linp

ldp

Examples

#-------------------------------------------------------------------------------
# A simple problem
#-------------------------------------------------------------------------------
# minimise x1^2 + x2^2 + x3^2 + x4^2 + x5^2 + x6^2
# subject to:
#-x1            + x4 + x5      = 0
#    - x2       - x4      + x6 = 0
# x1 + x2 + x3                 > 1
#           x3       + x5 + x6 < 1
# xi > 0

E <- matrix(nrow = 2, byrow = TRUE, data = c(-1, 0, 0, 1, 1, 0,
                                              0,-1, 0, -1, 0, 1))
F <- c(0, 0)
G <- matrix(nrow = 2, byrow = TRUE, data = c(1, 1, 1, 0, 0, 0,
                                             0, 0, -1, 0, -1, -1))
H    <- c(1, -1)
ldei(E, F, G, H)

#-------------------------------------------------------------------------------
# Imposing bounds
#-------------------------------------------------------------------------------

ldei(E, F, G, H, lower = 0.25)
ldei(E, F, G, H, lower = c(0.25, 0.25, 0.25, NA, NA, 0.5))

#-------------------------------------------------------------------------------
# parsimonious (simplest) solution of the mink diet problem
#-------------------------------------------------------------------------------
E <- rbind(Minkdiet$Prey, rep(1, 7))
F <- c(Minkdiet$Mink, 1)

parsimonious <- ldei(E, F, G = diag(7), H = rep(0, 7))
data.frame(food = colnames(Minkdiet$Prey),
           fraction = parsimonious$X)
dotchart(x = as.vector(parsimonious$X),
         labels = colnames(Minkdiet$Prey),
         main = "Diet composition of Mink extimated using ldei",
         xlab = "fraction")
         

limSolve documentation built on Sept. 22, 2023, 1:07 a.m.