Just a general comment, I have not looked at your code. You may want to look at the Debugging R portion of the Introduction to R manual on CRAN. There is also a graphical debugger from the 'debug' package on CRAN. Either one of these will become immensely helpful in situations like this.

Yasin Hajizadeh wrote:
  Hi all
  I would be grateful you can help me with my problem.
I try to run an optimization code . in one line I have runif in order to sample the PDF. I get this error while i run it. Error in runif(1, f$d[[n.of.u.vars + n.of.o.vars + j]][[2]][1], f$d[[n.of.u.vars + : invalid arguments Here is a part of that code: # initialize random numeber generator
  if (seed>0) set.seed(seed)
    # set parameters
  e.abs <- e
  e.rel <- e
  max.value <- f$opt
  eval <- 0
  last.impr <- max.eval;
  nl <- matrix(NA,k,k-1)
  iteration <- 0
    # separate unordered and ordered from continuous variables
  range.u <- vector()
  range.o <- vector()
  n.of.x.vars <- 0
  n.of.o.vars <- 0
  n.of.u.vars <- 0
  for (i in f$d) {
    if (i[[1]]=="u") {
      range.u <- c(range.u, length(i[[2]]))
      n.of.u.vars <- n.of.u.vars + 1
    }
    if (i[[1]]=="o") {
      range.o <- c(range.o, length(i[[2]]))
      n.of.o.vars <- n.of.o.vars + 1
    }
    if (i[[1]]=="x") {
      n.of.x.vars <- n.of.x.vars + 1
    }
  }
   # initialize variables
  max.u <- rep(NA,n.of.u.vars)
  max.o <- rep(NA,n.of.o.vars)
  max.X <- rep(NA,n.of.x.vars)
  max.y <- -Inf
    p.X <- vector()
  p.u <- vector()
  p.o <- vector()
  p <- data.frame(v=numeric(),sd=numeric(),gr=numeric());
# randomly choose the starting population # (but based on the data given in the function definition)
  for (i in 1:k) {
    if (n.of.u.vars>0) {
      U <- vector()
      for (j in 1:n.of.u.vars) {
U <- c(U, sample(range.u[j],1)) }
      U <- t(U)
    }
    else U <- NULL
    if (n.of.o.vars>0) {
      O <- vector()
      for (j in 1:n.of.o.vars) {
O <- c(O, sample(range.o[j],1)) }
      O <- t(O)
    }
    X <- vector()
    for (j in 1:n.of.x.vars) {
      X <- c(X, runif(1,f$d[[n.of.u.vars+n.of.o.vars+j]][[2]][1],
        f$d[[n.of.u.vars+n.of.o.vars+j]][[2]][2]))
    }
    X <- t(X)

Many Thanks Yasin


[[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-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.

Reply via email to