[R] Optimization of constrained linear least-squares problem
Stefaan Lhermitte
stefaan.lhermitte at biw.kuleuven.be
Thu Mar 17 15:13:25 CET 2005
Dear R-ians,
I want to perform an linear unmixing of image pixels in fractions of
pure endmembers. Therefore I need to perform a constrained linear
least-squares problem that looks like :
min || Cx - d || ² where sum(x) = 1.
I have a 3x3 matrix C, containing the values for endmembers and I have a
3x1 column vector d (for every pixel in the image). In theory my x
values should all be in the (0,1) interval but I don't want to force
them so I can check the validity of my solution. I just want to
calculate the x values. Can anyone help me with this problem? I've been
checking the optim, optimize, constrOptim and nlm help files, burt I
don't understand it very well. Wich function should I use for my
problem? I did a first test using optim:
# Make my C matrix
EM<- c(4.5000,6.0000,10.5000,5.0000,27.0000,20.7500,16.7500,23.6666,38.7500)
C <- array(EM, c(3,3))
# Take an arbitrary d
d<-c(10, 20, 20)
# Define the function
fr <- function(x) {
C[1,]*x=d
C[2,]*x=d
C[3,]*x=d
sum(x)=1}
# Perform the optimization
optim(c(0.25,0.25,0.25),fr)
But it did not work. I got the eror couldn't find function. Can anyone
tell me what functyion I should use for my problem and how should I
program it?
Thanx in advance,
Stef
More information about the R-help
mailing list