SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: feasible region [ Reply ]
By: Arne Henningsen on 2014-03-26 06:46
[forum:40940]
There are strange hidden symbols in the code so that I get tens of error messages, e.g.:

> f<-function(pars,x,t,y,s){
+   m <- pars[1]
Error: unexpected input in:
"f<-function(pars,x,t,y,s){
�"

Please put the code in an R script (plain text) file that you can easily create with the R GUI, RStudio, or a simple text editor. Please make sure that you can run the code that is in the file using the command source("myScript.R"). Furthermore, I suggest that you post a strongly simplified version of your model in this forum, as this increases the probability that somebody finds the problem.

RE: feasible region [ Reply ]
By: José María Crespo Garrucho on 2014-03-25 15:14
[forum:40939]

Code.docx (45) downloads
Dear Arne

I have attached the code.

You can use as an example:
x<-2
y<-1
t<-1
s<-0

Thanks in advance.


RE: feasible region [ Reply ]
By: Arne Henningsen on 2014-03-25 13:10
[forum:40938]
Now, I get the error message "object 'f' not found." As I said before, please post a simple and reproducible example that triggers the error message. If you re-post your example, please make sure that you can run the code in a new R session with an empty work space.

RE: feasible region [ Reply ]
By: José María Crespo Garrucho on 2014-03-25 08:18
[forum:40937]
Dear Arne

k can be 1,2,3,....

When I get res, then I change P for res$estimate (P<-res$estimate) and the algorithm follows in the same way.

Thanks Arne.

RE: feasible region [ Reply ]
By: Arne Henningsen on 2014-03-25 07:22
[forum:40936]
Dear José

I get the error message "object 'k' not found." Please simplify the example and make sure that the code that you provide is executable.

/Arne

RE: feasible region [ Reply ]
By: José María Crespo Garrucho on 2014-03-24 21:47
[forum:40935]
Hi

The feasible region in my case is:
E_k (P)=(P[1]/(k+1),P[1]+k)×(P[2]/(k+1),P[2]+k)×(P[3]-k,P[3]+k)×(P[4]/(k+1),P[4]+(1-P[4] )*k/(k+1))

and

P1<-c(runif(1,P[1]/(k+1),P[1]+k), runif(1,P[2]/(k+1),P[2]+k),runif(1,P[3]-k,P[3]+k),runif(1,P[4]/(k+1),P[4]+(1-P[4])*(k/(k+1))))

P1 belongs to E_(P).
I don't know why that error appears.

Greetings

RE: feasible region [ Reply ]
By: José María Crespo Garrucho on 2014-03-24 21:31
[forum:40934]
Hi

This is a litle piece of code:

P<-c(2,1,0.3,0.2)

P1<-c(runif(1,P[1]/k,P[1]+k), runif(1,P[2]/k,P[2]+k),runif(1,P[3]-k,P[3]+k),runif(1,P[4]/k,P[4]+(1-P[4])*(k/(k+5))))


P1 belongs to E_k (P)=(P[1]/(k+1),P[1]+k)×(P[2]/(k+1),P[2]+k)×(P[3]-k,P[3]+k)×(P[4]/(k+1),P[4]+(1-P[4] )*k/(k+5))


res<-maxBFGS(f,start=P1,constraints=list(ineqA=A,ineqB=B),x=x,t1=t,y=y,s1=s)

[1] 2.00000129 1.99996230 0.05661225 0.20000000 # local maximum
[1] 1
[1] 2.00000129 1.99996230 0.05661225 0.20000000 # local maximum
[1] 2
[1] 1.1374370 1.0080673 -0.1877282 0.1000000 # local maximum.
[1] 1

Error in constrOptim2(theta = start, f = logLikFunc, grad = gradOptim, :
initial value not the feasible region


Thanks in advance

RE: feasible region [ Reply ]
By: Arne Henningsen on 2014-03-24 18:38
[forum:40932]
Hi José

Can you please provide a small piece of code that reproduces the error message?

/Arne

RE: feasible region [ Reply ]
By: José María Crespo Garrucho on 2014-03-24 16:11
[forum:40931]
Hi

Thanks for your answer.

More information to solve the problem:

f=f(m,b,c,sigma)

A and B are defined by following according this neighborhood of P:

E_k (P)=(P[1]/(k+1),P[1]+k)×(P[2]/(k+1),P[2]+k)×(P[3]-k,P[3]+k)×(P[4]/(k+1),P[4]+(1-P[4] )*k/(k+1))

and these constraints:
m>b
m>0
b>0
0<sigma<1

> A
[,1] [,2] [,3] [,4]
a1 1 -1 0 0
a2 1 0 0 0
a3 0 1 0 0
a4 0 0 0 1
a5 0 0 0 -1
a6 1 0 0 0
a7 -1 0 0 0
a8 0 1 0 0
a9 0 -1 0 0
a10 0 0 1 0
a11 0 0 -1 0
a12 0 0 0 1
a13 0 0 0 -1

> B
[,1]
[1,] 0.0000000
[2,] 0.0000000
[3,] 0.0000000
[4,] 0.0000000
[5,] 1.0000000
[6,] -P[1]/(k+1)
[7,] P[1]+k
[8,] -P[2]/(k+1)
[9,] P[1]+k
[10,] -P[3]+k
[11,] P[3]+k
[12,] -P[4]/(k+1)
[13,] P[4]+(1-P[4])*k/(k+1)

k=1,2,3,....



P1 is defined as:

P1<-c(runif(1,P[1]/k,P[1]+k), runif(1,P[2]/k,P[2]+k),runif(1,P[3]-k,P[3]+k),runif(1,P[4]/k,P[4]+(1-P[4])*(k/(k+5))))

P1 is a random point in E_k(P) ( I have generated this point to verify this condition)

Thanks in advance.


RE: feasible region [ Reply ]
By: Ott Toomet on 2014-03-24 15:45
[forum:40930]
Hey,
hard to say... I guess you code either A or B wrong... But I cannot say much more unless you tell me what are A, B, and P1.

Errors on our side are possible as well although the code passes a number of tests before being published..

Best,
Ott

feasible region [ Reply ]
By: José María Crespo Garrucho on 2014-03-24 15:27
[forum:40929]
Hi all

I have written this code:

res<-maxBFGS(f,start=P1,constraints=list(ineqA=A,ineqB=B),x=x,t1=t,y=y,s1=s)

and I get the following error:

Error in constrOptim2(theta = start, f = logLikFunc, grad = gradOptim, :
initial value not the feasible region

I an sure that P1 is in the feasible region
What's wrong?
Thanks in advance.

Thanks to:
Vienna University of Economics and Business Powered By FusionForge