Re: [R] Testing optimization solvers with equality constraints
Sorry, missed the top line of code. library (barsurf) __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Testing optimization solvers with equality constraints
For a start, there's two local minima. Add to that floating point errors. And possible assumptions by the package authors. begin code f <- function (x, y, sign) { unsign.z <- sqrt (1 - x^2 - y^2) 2 * (x^2 - sign * y * unsign.z) } north.f <- function (x, y) f (x, y, +1) south.f <- function (x, y) f (x, y, -1) N <- 100 p0 <- par (mfrow = c (1, 2) ) plotf_cfield (north.f, c (-1.1, 1.1), main="north", ncontours=10, n=N, raster=TRUE, hcv=TRUE) plotf_cfield (south.f, c (-1.1, 1.1), main="south", ncontours=10, n=N, raster=TRUE, hcv=TRUE) par (p0) end code Please ignore R warnings. I'm planning to reinvent this package soon. And also, it wasn't designed for circular heatmaps. On Sat, May 22, 2021 at 8:02 PM Hans W wrote: > > Yes. "*on* the unit sphere" means on the surface, as you can guess > from the equality constraint. And 'auglag()' does find the minimum, so > no need for a special approach. > > I was/am interested in why all these other good solvers get stuck, > i.e., do not move away from the starting point. And how to avoid this > in general, not only for this specific example. > > > On Sat, 22 May 2021 at 09:44, Abby Spurdle wrote: > > > > Sorry, this might sound like a poor question: > > But by "on the unit sphere", do you mean on the ***surface*** of the sphere? > > In which case, can't the surface of a sphere be projected onto a pair > > of circles? > > Where the cost function is reformulated as a function of two (rather > > than three) variables. > > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Pipe precedence
R 4.1.0 was released this week with a new pipe operator and a new anonymous function shorthand (\(x) x^2). The pipe operator is not quite as flexible as the magrittr pipe, but it is faster (not that the magrittr pipe is noticably slow) and built-in. On May 22, 2021 8:07:27 PM PDT, Caitlin Gibbons wrote: >I didn’t know R had a new pipe operator, but I have seen “|>” (without >quotes) used in the Elixir language though. Are there now two? “%>%” >from the magrittr package and “|>” which is built-in? > >> On May 22, 2021, at 5:26 PM, Jeff Newmiller > wrote: >> >> What is the precedence of the new |> pipe operator? I don't see it >mentioned in ?Syntax, nor does it come up when I search the R Language >Definition document. >> -- >> Sent from my phone. Please excuse my brevity. >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Pipe precedence
This is part of the R-4.1.0 release which came out a few days ago. See 1. https://stat.ethz.ch/pipermail/r-announce/2021/000670.html 2. https://www.jumpingrivers.com/blog/new-features-r410-pipe-anonymous-functions/ 3. https://community.rstudio.com/t/psa-r-4-1-0-release-requires-rstudio-preview/105209 Eric On Sun, May 23, 2021 at 6:07 AM Caitlin Gibbons wrote: > I didn’t know R had a new pipe operator, but I have seen “|>” (without > quotes) used in the Elixir language though. Are there now two? “%>%” from > the magrittr package and “|>” which is built-in? > > > On May 22, 2021, at 5:26 PM, Jeff Newmiller > wrote: > > > > What is the precedence of the new |> pipe operator? I don't see it > mentioned in ?Syntax, nor does it come up when I search the R Language > Definition document. > > -- > > Sent from my phone. Please excuse my brevity. > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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 -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Pipe precedence
I didn’t know R had a new pipe operator, but I have seen “|>” (without quotes) used in the Elixir language though. Are there now two? “%>%” from the magrittr package and “|>” which is built-in? > On May 22, 2021, at 5:26 PM, Jeff Newmiller wrote: > > What is the precedence of the new |> pipe operator? I don't see it mentioned > in ?Syntax, nor does it come up when I search the R Language Definition > document. > -- > Sent from my phone. Please excuse my brevity. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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] Pipe precedence
What is the precedence of the new |> pipe operator? I don't see it mentioned in ?Syntax, nor does it come up when I search the R Language Definition document. -- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Help in modifying code to extract data from url
Several authors hav addressed this problem with names that resemble "rbindfill". In my machine I find four instances: ??rbindfill Help pages: ffbase::ffdfrbind.fill rbind for ffdf where missing columns are added if not available in one of the ffdf objects plyr::rbind.fill Combine data.frames by row, filling in missing columns. plyr::rbind.fill.matrix Bind matrices by row, and fill missing columns with NA. rockchalk::rbindFill Stack together data frames -- David. On 5/20/21 2:19 AM, Jim Lemon wrote: Hi Bhaskar, If you are using read.table or similar, see the "fill=" argument. Jim On Thu, May 20, 2021 at 9:54 AM Bhaskar Mitra wrote: Hello Everyone, I am trying to extract data from a url. The codes work well when the data structure is as follows: X Y 1 2 1 5 1 6 1 7 3 4 However, the code fails when the data structure has no number under the 2nd column (shown below).I get the following error: "Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 242, 241" X Y 1 2 1 1 1 7 3 4 Can anyone please help me in how I can modify the codes ( shown below) to adjust for the above mentioned condition in the data structure. library(rjson) url <- "abcd.com" json_data <- fromJSON(file= url) d3 <- lapply(json_data[[2]], function(x) c(x["data"])) d3 <- do.call(rbind, d3) X_Dataframe = as.data.frame(unlist(d3[[1]])) b <- do.call("cbind", split(X_Dataframe, rep(c(1, 2), length.out = nrow(X_Dataframe regards, bhaskar [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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 -- To UNSUBSCRIBE and more, see 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] Ubuntu hirsute unable to receive the key to add the repository
Hi Victor, This issue has been raised in earlier entries in this list. I have not dug into it myself but the following link was posted as being helpful. https://askubuntu.com/questions/1286545/what-commands-exactly-should-replace-the-deprecated-apt-key/1307181#1307181 HTH, Eric On Sat, May 22, 2021 at 12:47 PM Victor wrote: > I followed the procedure indicated in https://cran.mirror.garr.it/CRAN/ > step by step to install R under ubuntu 21.04 hirsute but the apt-key > command failed: > > vr@ubuntu:~$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys > E298A3A825C0D65DFD57CBB651716619E084DAB9 > Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d > instead (see apt-key(8)). > Executing: /tmp/apt-key-gpghome.gHJAZ9lYF3/gpg.1.sh --keyserver > keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 > gpg: ricezione dal server di chiavi non riuscita: Server indicated a > failure > > Please help to solve this problem. > > Ciao > > Vittorio > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Help in modifying code to extract data from url
The source being a URL is not important. The important things are - what the structure of the JSON data is - what the MEANING of the JSON data is - what that meaning says about what SHOULD appear in the data from in these cases. Arguably this isn't even an R question at all. It's a question about your data. Since you have replaced the actual URL with a dummy (example.com is the traditional never-to-be-in-use host name), we cannot even guess these things by looking at the data ourselves. On Thu, 20 May 2021 at 11:54, Bhaskar Mitra wrote: > Hello Everyone, > > I am trying to extract data from a url. The codes work well when the > data structure is as follows: > > X Y > 1 2 > 1 5 > 1 6 > 1 7 > 3 4 > > However, the code fails when the data structure has no number > under the 2nd column (shown below).I get the following error: > > "Error in data.frame(..., check.names = FALSE) : > arguments imply differing number of rows: 242, 241" > > > X Y > 1 2 > 1 > 1 > 1 7 > 3 4 > > Can anyone please help me in how I can modify the codes ( shown below) to > adjust for the above mentioned condition > in the data structure. > > library(rjson) > > url <- "abcd.com" > json_data <- fromJSON(file= url) > d3 <- lapply(json_data[[2]], function(x) c(x["data"])) > d3 <- do.call(rbind, d3) > X_Dataframe = as.data.frame(unlist(d3[[1]])) > b <- do.call("cbind", split(X_Dataframe, rep(c(1, 2), length.out = > nrow(X_Dataframe > > > regards, > bhaskar > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Ubuntu hirsute unable to receive the key to add the repository
I followed the procedure indicated in https://cran.mirror.garr.it/CRAN/ step by step to� install R under ubuntu 21.04 hirsute but� the apt-key command failed: vr@ubuntu:~$ apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). Executing: /tmp/apt-key-gpghome.gHJAZ9lYF3/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9 gpg: ricezione dal server di chiavi non riuscita: Server indicated a failure Please help to solve this problem. Ciao Vittorio [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Testing optimization solvers with equality constraints
Yes. "*on* the unit sphere" means on the surface, as you can guess from the equality constraint. And 'auglag()' does find the minimum, so no need for a special approach. I was/am interested in why all these other good solvers get stuck, i.e., do not move away from the starting point. And how to avoid this in general, not only for this specific example. On Sat, 22 May 2021 at 09:44, Abby Spurdle wrote: > > Sorry, this might sound like a poor question: > But by "on the unit sphere", do you mean on the ***surface*** of the sphere? > In which case, can't the surface of a sphere be projected onto a pair > of circles? > Where the cost function is reformulated as a function of two (rather > than three) variables. > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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] Testing optimization solvers with equality constraints
Sorry, this might sound like a poor question: But by "on the unit sphere", do you mean on the ***surface*** of the sphere? In which case, can't the surface of a sphere be projected onto a pair of circles? Where the cost function is reformulated as a function of two (rather than three) variables. On Sat, May 22, 2021 at 3:01 AM Hans W wrote: > > Just by chance I came across the following example of minimizing > a simple function > > (x,y,z) --> 2 (x^2 - y z) > > on the unit sphere, the only constraint present. > I tried it with two starting points, x1 = (1,0,0) and x2 = (0,0,1). > > #-- Problem definition in R > f = function(x) 2 * (x[1]^2 - x[2]*x[3]) # (x,y,z) |-> 2(x^2 -yz) > g = function(x) c(4*x[1], 2*x[3], 2*x[2]) # its gradient > > x0 = c(1, 0, 0); x1 = c(0, 0, 1)# starting points > xmin = c(0, 1/sqrt(2), 1/sqrt(2)) # true minimum -1 > > heq = function(x) 1-x[1]^2-x[2]^2-x[3]^2 # staying on the sphere > conf = function(x) {# constraint function > fun = x[1]^2 + x[2]^2 + x[3]^2 - 1 > return(list(ceq = fun, c = NULL)) > } > > I tried all the nonlinear optimization solvers in R packages that > allow for equality constraints: 'auglag()' in alabama, 'solnl()' in > NlcOptim, 'auglag()' in nloptr, 'solnp()' in Rsolnp, or even 'donlp2()' > from the Rdonlp2 package (on R-Forge). > > None of them worked from both starting points: > > # alabama > alabama::auglag(x0, fn = f, gr = g, heq = heq) # right (inaccurate) > alabama::auglag(x1, fn = f, gr = g, heq = heq) # wrong > > # NlcOptim > NlcOptim::solnl(x0, objfun = f, confun = conf) # wrong > NlcOptim::solnl(x1, objfun = f, confun = conf) # right > > # nloptr > nloptr::auglag(x0, fn = f, heq = heq) # wrong > # nloptr::auglag(x1, fn = f, heq = heq) # not returning > > # Rsolnp > Rsolnp::solnp(x0, fun = f, eqfun = heq) # wrong > Rsolnp::solnp(x1, fun = f, eqfun = heq) # wrong > > # Rdonlp2 > Rdonlp2::donlp2(x0, fn = f, nlin = list(heq), # wrong >nlin.lower = 0, nlin.upper = 0) > Rdonlp2::donlp2(x1, fn = f, nlin = list(heq), # right >nlin.lower = 0, nlin.upper = 0) # (fast and exact) > > The problem with starting point x0 appears to be that the gradient at > that point, projected onto the unit sphere, is zero. Only alabama is > able to handle this somehow. > > I do not know what problem most solvers have with starting point x1. > The fact that Rdonlp2 is the fastest and most accurate is no surprise. > > If anyone with more experience with one or more of these packages can > give a hint of what I made wrong, or how to change calling the solver > to make it run correctly, please let me know. > > Thanks -- HW > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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 -- To UNSUBSCRIBE and more, see 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.