[R] optim(,SANN...)

2009-11-22 Thread lloyd barcza
Hi,

Can anyone please tell me is there a way to view the annealing schedule when 
using SANN is optim. I have tried setting report=1 in the control list, but 
cannot seem to get it to work?

Ant help or suggestions would be appreciated!

Thanks

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] optim(.. ,SANN,..)

2009-11-21 Thread Nikhil Kaza
I think the issue is in the function fr,

?apply
apply returns a vector or array or list of values

So if the inner apply returns a list (this happens when different  
number of elements in y are positive in different rows) then outer  
apply cannot coerce it into the correct format to apply the product
To see this try

set.seed(1)
v- runif(12, -10,10)
fr(v)

Nikhil

On 19 Nov 2009, at 6:05PM, lloyd barcza wrote:

 fr-function(x){y-x*D
 C-apply(t(apply(y,1,function(c){c[c0]})),1,prod)
 R2-R*C
 w-R2[R2P]
 g-sum(w)
 return(g)}


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] optim(.. ,SANN,..)

2009-11-19 Thread lloyd barcza
I have a problem using optim, so I am hoping someone can help me out with it:

Suppose I have the list:

list(D,R,P)
[[1]]
   V1 V2 V3 V4
1   0  1  0  1
2   1  1  0  0
3   1  0  1  0
4   0  0  1  1
5   0  1  0  1
6   1  1  0  0
7   1  0  1  0
8   0  0  1  1
9   1  0  1  0
10  0  0  1  1

[[2]]
 [1]   23   85   12   73   23   24   25   56   78 1200

[[3]]
  V1
1 25
2 80
3 15
4 60
5 56
6 15
7 20
8 70
9 45
10 12000

and the strange function fr which I want to maximise:

fr-function(x){y-x*D
C-apply(t(apply(y,1,function(c){c[c0]})),1,prod)
R2-R*C
w-R2[R2P]
g-sum(w)
return(g)}

v-c(1,1,1,1,1,1,1,1,1,1)

res - optim(v, fr, method=SANN,
  control=list(maxit=200, temp=20,v))

I get the following error:
Error in prod(..., na.rm = na.rm) : invalid 'type' (list) of argument

I'm not sure if its because this function is too disjoint to be opimised using 
SANN or I am not using optim properly. 

Any help or suggestions would be appreciated.

Thanks

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.