[R] having problems with constrOptim

2005-04-09 Thread Tolga Uzuner
Hi,
Am having problems specifying lower and upper constraints in constrOptim...
I have a function(x)-f which takes a 5 vector array
the constraints on the elements of x are:
x[1],x[2],x[3],x[5]0
x[4]-1
x[1],x[2],x[3],x[4],x[5]1
this works:

 x
[1]  0.400  0.200  0.200 -0.050  0.002
 optim(x,f)
$par
[1] 0.28630079 0.13583616 0.18752379 0.02231329 0.08640233
$value
[1] 0.0004999157
$counts
function gradient
230   NA
$convergence
[1] 0
$message
NULL
###
but when I try to specify the constraints, I get this:
###
 
constrOptim(x,f,grad=NULL,ui=rbind(diag(5),-diag(5)),ci=c(0,0,0,-1,0,1,1,1,1,1))
Error in constrOptim(x, f, grad = NULL, ui = rbind(diag(5), -diag(5)),  :
   initial value not feasible

###
What am I doing wrong ? As above, x=c(0.400 ,0.200, 0.200,-0.050 ,0.002)

Many thanks,
Tolga
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] having problems with constrOptim

2005-04-09 Thread Ingmar Visser

 ui %*% theta - ci has to be larger than zero, and it is not:

 ui=rbind(diag(5),-diag(5))
 ui
  [,1] [,2] [,3] [,4] [,5]
 [1,]10000
 [2,]01000
 [3,]00100
 [4,]00010
 [5,]00001
 [6,]   -10000
 [7,]0   -1000
 [8,]00   -100
 [9,]000   -10
[10,]0000   -1
 ci=c(0,0,0,-1,0,1,1,1,1,1)
 ci
 [1]  0  0  0 -1  0  1  1  1  1  1
 x=c(0.400 ,0.200, 0.200,-0.050 ,0.002)
 theta=x
 ui %*% theta - ci
[,1]
 [1,]  0.400
 [2,]  0.200
 [3,]  0.200
 [4,]  0.950
 [5,]  0.002
 [6,] -1.400
 [7,] -1.200
 [8,] -1.200
 [9,] -0.950
[10,] -1.002

try 
 ci
 [1]  0  0  0 -1  0 -1 -1 -1 -1 -1

hth, ingmar

On 4/9/05 12:29 PM, Tolga Uzuner [EMAIL PROTECTED] wrote:

 Hi,
 
 Am having problems specifying lower and upper constraints in constrOptim...
 
 I have a function(x)-f which takes a 5 vector array
 the constraints on the elements of x are:
 x[1],x[2],x[3],x[5]0
 x[4]-1
 x[1],x[2],x[3],x[4],x[5]1
 
 this works:
 
 x
 [1]  0.400  0.200  0.200 -0.050  0.002
 optim(x,f)
 $par
 [1] 0.28630079 0.13583616 0.18752379 0.02231329 0.08640233
 
 $value
 [1] 0.0004999157
 
 $counts
 function gradient
  230   NA
 
 $convergence
 [1] 0
 
 $message
 NULL
 ###
 but when I try to specify the constraints, I get this:
 ###
 
 constrOptim(x,f,grad=NULL,ui=rbind(diag(5),-diag(5)),ci=c(0,0,0,-1,0,1,1,1,1,1
 ))
 Error in constrOptim(x, f, grad = NULL, ui = rbind(diag(5), -diag(5)),  :
 initial value not feasible
 
 ###
 What am I doing wrong ? As above, x=c(0.400 ,0.200, 0.200,-0.050 ,0.002)
 
 Many thanks,
 Tolga
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

-- 
Ingmar Visser
Department of Psychology, University of Amsterdam
Roetersstraat 15, 1018 WB Amsterdam
The Netherlands
http://users.fmg.uva.nl/ivisser/
tel: +31-20-5256735

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


Re: [R] having problems with constrOptim

2005-04-09 Thread Tolga Uzuner
subtle... thanks, that works, appreciate it
Ingmar Visser wrote:
ui %*% theta - ci has to be larger than zero, and it is not:
 

ui=rbind(diag(5),-diag(5))
ui
   

 [,1] [,2] [,3] [,4] [,5]
[1,]10000
[2,]01000
[3,]00100
[4,]00010
[5,]00001
[6,]   -10000
[7,]0   -1000
[8,]00   -100
[9,]000   -10
[10,]0000   -1
 

ci=c(0,0,0,-1,0,1,1,1,1,1)
ci
   

[1]  0  0  0 -1  0  1  1  1  1  1
 

x=c(0.400 ,0.200, 0.200,-0.050 ,0.002)
theta=x
ui %*% theta - ci
   

   [,1]
[1,]  0.400
[2,]  0.200
[3,]  0.200
[4,]  0.950
[5,]  0.002
[6,] -1.400
[7,] -1.200
[8,] -1.200
[9,] -0.950
[10,] -1.002
try 
 

ci
   

[1]  0  0  0 -1  0 -1 -1 -1 -1 -1
hth, ingmar
On 4/9/05 12:29 PM, Tolga Uzuner [EMAIL PROTECTED] wrote:
 

Hi,
Am having problems specifying lower and upper constraints in constrOptim...
I have a function(x)-f which takes a 5 vector array
the constraints on the elements of x are:
x[1],x[2],x[3],x[5]0
x[4]-1
x[1],x[2],x[3],x[4],x[5]1
this works:

   

x
 

[1]  0.400  0.200  0.200 -0.050  0.002
   

optim(x,f)
 

$par
[1] 0.28630079 0.13583616 0.18752379 0.02231329 0.08640233
$value
[1] 0.0004999157
$counts
function gradient
230   NA
$convergence
[1] 0
$message
NULL
###
but when I try to specify the constraints, I get this:
###
   

constrOptim(x,f,grad=NULL,ui=rbind(diag(5),-diag(5)),ci=c(0,0,0,-1,0,1,1,1,1,1
))
Error in constrOptim(x, f, grad = NULL, ui = rbind(diag(5), -diag(5)),  :
   initial value not feasible
   

###
What am I doing wrong ? As above, x=c(0.400 ,0.200, 0.200,-0.050 ,0.002)
Many thanks,
Tolga
__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
   

 

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html