{"id":26221454,"url":"https://github.com/non-contradiction/convexjlr","last_synced_at":"2025-04-17T05:14:49.467Z","repository":{"id":56937056,"uuid":"93281471","full_name":"Non-Contradiction/convexjlr","owner":"Non-Contradiction","description":"Disciplined Convex Programming in R using Convex.jl. ","archived":false,"fork":false,"pushed_at":"2018-12-18T23:44:04.000Z","size":1239,"stargazers_count":13,"open_issues_count":2,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-08-09T07:36:34.433Z","etag":null,"topics":["convex","convex-optimization","dcp","optimization","r"],"latest_commit_sha":null,"homepage":"https://non-contradiction.github.io/convexjlr/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Non-Contradiction.png","metadata":{"files":{"readme":"README.Rmd","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-06-04T00:35:47.000Z","updated_at":"2023-07-24T05:26:55.000Z","dependencies_parsed_at":"2022-08-21T01:10:10.018Z","dependency_job_id":null,"html_url":"https://github.com/Non-Contradiction/convexjlr","commit_stats":null,"previous_names":[],"tags_count":4,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Non-Contradiction%2Fconvexjlr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Non-Contradiction%2Fconvexjlr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Non-Contradiction%2Fconvexjlr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Non-Contradiction%2Fconvexjlr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Non-Contradiction","download_url":"https://codeload.github.com/Non-Contradiction/convexjlr/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243249311,"owners_count":20260813,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["convex","convex-optimization","dcp","optimization","r"],"created_at":"2025-03-12T16:20:25.156Z","updated_at":"2025-03-12T16:20:26.159Z","avatar_url":"https://github.com/Non-Contradiction.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: rmarkdown::github_document\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n# Convex Optimization in R by convexjlr\n\n[![Travis-CI Build Status](https://travis-ci.org/Non-Contradiction/convexjlr.svg?branch=master)](https://travis-ci.org/Non-Contradiction/convexjlr)\n[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/Non-Contradiction/convexjlr?branch=master\u0026svg=true)](https://ci.appveyor.com/project/Non-Contradiction/convexjlr)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/convexjlr)](https://cran.r-project.org/package=convexjlr)\n[![](http://cranlogs.r-pkg.org/badges/convexjlr)](https://cran.r-project.org/package=convexjlr)\n[![](https://cranlogs.r-pkg.org/badges/grand-total/convexjlr)](https://cran.r-project.org/package=convexjlr)\n\n```{r, echo = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"README-\"\n)\n\n## set seed for reproducible result\nset.seed(123)\n```\n\n`convexjlr` is an `R` package for *Disciplined Convex Programming (DCP)* by providing\na high level wrapper for Julia package [Convex.jl](https://github.com/JuliaOpt/Convex.jl). \nThe aim is to provide optimization results rapidly and reliably in `R` \nonce you formulate your problem as a convex problem.\n`convexjlr` can solve linear programs, second order cone programs, semidefinite programs, exponential cone programs, mixed-integer linear programs, and some other DCP-compliant convex programs through `Convex.jl`.\n\n## Installation \n\n`convexjlr` is on CRAN now! To use package `convexjlr`, you first have to install Julia\n\u003chttps://julialang.org/\u003e on your computer, and then you can install `convexjlr` just like\nany other R packages.\n\nNote: `convexjlr` used to support multiple ways to connect to `julia`, one way was through package `XRJulia` and the other way was to use package `JuliaCall`. The latter approach was more performant and thus the default approach. \nBut due to the fact that `XRJulia` doesn't support `julia` v0.7 and v1.0 yet, only `JuliaCall` backend is supported currently.\n\nWe hope you use `convexjlr` to solve your own problems.\nIf you would like to share your experience on using `convexjlr` or have any questions about `convexjlr`, \ndon't hesitate to contact me: \u003ccxl508@psu.edu\u003e.\n\n\n## Quick Example\n\nWe will show a short example for `convexjlr` in solving linear regression problem.\nTo use package `convexjlr`, we first need to attach it and do the initial setup:\n\n```{r}\nlibrary(convexjlr)\n## If you wish to use JuliaCall backend for performance\nconvex_setup(backend = \"JuliaCall\")\n```\n\nAnd this is our linear regression function using `convexjlr`:\n\n```{r}\nlinear_regression \u003c- function(x, y){\n    p \u003c- ncol(x)\n    ## n is a scalar, you don't have to use J(.) to send it to Julia.\n    n \u003c- nrow(x) ## n \u003c- J(nrow(x))\n    ## x is a matrix and y is a vector, you have to use J(.) to send them to Julia.\n    x \u003c- J(x)\n    y \u003c- J(y)\n    ## coefficient vector beta and intercept b.\n    beta \u003c- Variable(p)\n    b \u003c- Variable()\n    ## MSE is mean square error.\n    MSE \u003c- Expr(sumsquares(y - x %*% beta - b) / n)\n    ## In linear regression, we want to minimize MSE.\n    p1 \u003c- minimize(MSE)\n    cvx_optim(p1)\n    list(coef = value(beta), intercept = value(b))\n}\n```\n\nIn the function, `x` is the predictor matrix, `y` is the response we have.\nAnd the `linear_regression` function will return the coefficient and intercept solved by `cvx_optim`.\n\nNow we can see a little example using the `linear_regression` function we have just built.\n\n```{r}\nn \u003c- 1000\np \u003c- 5\n## Sigma, the covariance matrix of x, is of AR-1 strcture.\nSigma \u003c- outer(1:p, 1:p, function(i, j) 0.5 ^ abs(i - j))\nx \u003c- matrix(rnorm(n * p), n, p) %*% chol(Sigma)\n## The real coefficient is all zero except the first, second and fourth elements.\nbeta0 \u003c- c(5, 1, 0, 2, 0)\ny \u003c- x %*% beta0 + 0.2 * rnorm(n)\n\nlinear_regression(x, y)$coef\n```\n\n## More Examples\n\nMore examples (including using `convexjlr` for Lasso, logistic regression and Support Vector Machine) can be found in the pakage vignette or on the github page: \u003chttps://github.com/Non-Contradiction/convexjlr\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnon-contradiction%2Fconvexjlr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnon-contradiction%2Fconvexjlr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnon-contradiction%2Fconvexjlr/lists"}