Giter VIP home page Giter VIP logo

convex.jl's Introduction

Convex.jl

Build Status Coverage

Convex.jl is a Julia package for Disciplined Convex Programming (DCP).

Convex.jl can solve linear programs, mixed-integer linear programs, and DCP-compliant convex programs using a variety of solvers, including Mosek, Gurobi, ECOS, SCS, and GLPK, through MathOptInterface.

Convex.jl also supports optimization with complex variables and coefficients.

For usage questions, please contact us via Discourse.

Installation

import Pkg
Pkg.add("Convex")

Quick Example

# Let us first make the Convex.jl module available
using Convex, SCS

# Generate random problem data
m = 4;  n = 5
A = randn(m, n); b = randn(m, 1)

# Create a (column vector) variable of size n x 1.
x = Variable(n)

# The problem is to minimize ||Ax - b||^2 subject to x >= 0
# This can be done by: minimize(objective, constraints)
problem = minimize(sumsquares(A * x - b), [x >= 0])

# Solve the problem by calling solve!
solve!(problem, SCS.Optimizer)

# Check the status of the problem
problem.status # :Optimal, :Infeasible, :Unbounded etc.

# Get the optimal value
problem.optval

Using with JuMP

The master branch of this package (not yet released) contains an experimental JuMP solver. This solver reformulates a nonlinear JuMP model into a conic program using DCP. Note that it currently supports only a limited subset of scalar nonlinear programs, such as those involving log and exp.

julia> model = Model(() -> Convex.Optimizer(Clarabel.Optimizer))
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Convex with Clarabel

julia> @variable(model, x >= 1);

julia> @variable(model, t);

julia> @constraint(model, t >= exp(x))
t - exp(x)  0

julia> @objective(model, Min, t);

julia> optimize!(model)
-------------------------------------------------------------
           Clarabel.jl v0.5.1  -  Clever Acronym
                   (c) Paul Goulart
                University of Oxford, 2022
-------------------------------------------------------------

problem:
  variables     = 3
  constraints   = 5
  nnz(P)        = 0
  nnz(A)        = 5
  cones (total) = 2
    : Nonnegative = 1,  numel = 2
    : Exponential = 1,  numel = 3

settings:
  linear algebra: direct / qdldl, precision: Float64
  max iter = 200, time limit = Inf,  max step = 0.990
  tol_feas = 1.0e-08, tol_gap_abs = 1.0e-08, tol_gap_rel = 1.0e-08,
  static reg : on, ϵ1 = 1.0e-08, ϵ2 = 4.9e-32
  dynamic reg: on, ϵ = 1.0e-13, δ = 2.0e-07
  iter refine: on, reltol = 1.0e-13, abstol = 1.0e-12, 
               max iter = 10, stop ratio = 5.0
  equilibrate: on, min_scale = 1.0e-04, max_scale = 1.0e+04
               max iter = 10

iter    pcost        dcost       gap       pres      dres      k/t        μ       step      
---------------------------------------------------------------------------------------------
  0   0.0000e+00   4.4359e-01  4.44e-01  8.68e-01  8.16e-02  1.00e+00  1.00e+00   ------   
  1   2.2037e+00   2.6563e+00  2.05e-01  7.34e-02  6.03e-03  5.44e-01  1.01e-01  9.33e-01  
  2   2.5276e+00   2.6331e+00  4.17e-02  1.43e-02  1.26e-03  1.27e-01  2.26e-02  7.84e-01  
  3   2.6758e+00   2.7129e+00  1.39e-02  4.09e-03  3.42e-04  4.35e-02  6.00e-03  7.84e-01  
  4   2.7167e+00   2.7178e+00  3.90e-04  1.18e-04  9.82e-06  1.25e-03  1.72e-04  9.80e-01  
  5   2.7182e+00   2.7183e+00  9.60e-06  3.39e-06  2.82e-07  3.15e-05  4.95e-06  9.80e-01  
  6   2.7183e+00   2.7183e+00  1.92e-07  6.74e-08  5.62e-09  6.29e-07  9.84e-08  9.80e-01  
  7   2.7183e+00   2.7183e+00  4.70e-09  1.94e-09  1.61e-10  1.59e-08  2.83e-09  9.80e-01  
---------------------------------------------------------------------------------------------
Terminated with status = solved
solve time =  941μs

julia> value(x), value(t)
(0.9999999919393833, 2.7182818073461403)

More Examples

A number of examples can be found here. The basic usage notebook gives a simple tutorial on problems that can be solved using Convex.jl.

All examples can be downloaded as a zip file from here.

Citing this package

If you use Convex.jl for published work, we encourage you to cite the software using the following BibTeX citation:

@article{convexjl,
 title = {Convex Optimization in {J}ulia},
 author = {Udell, Madeleine and Mohan, Karanveer and Zeng, David and Hong, Jenny and Diamond, Steven and Boyd, Stephen},
 year = {2014},
 journal = {SC14 Workshop on High Performance Technical Computing in Dynamic Languages},
 archivePrefix = "arXiv",
 eprint = {1410.4821},
 primaryClass = "math-oc",
}

convex.jl's People

Contributors

ararslan avatar ayush-iitkgp avatar blakejohnson avatar blegat avatar daviddelaat avatar davidlizeng avatar dressel avatar dstahlke avatar ericphanson avatar github-actions[bot] avatar hsnamkoong avatar iainnz avatar jduchi avatar jennyhong avatar karanveerm avatar lrnv avatar madeleineudell avatar mfalt avatar mlubin avatar moehle avatar nan2ge1 avatar odow avatar paulsoderlind avatar peterwittek avatar ranocha avatar riccardomurri avatar rofinn avatar seanemoon avatar tkelman avatar vernwalrahul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

convex.jl's Issues

Cleanup documentation

  • Add advanced section that talks about dual variables, warmstart etc.
  • Fix capitalization inconsistencies etc.

Anything I'm missing?

getindex error in multiply_divide.jl

ERROR: `getindex` has no method matching getindex(::Nothing, ::Int64)
 in conic_form! at /Users/eric/.julia/v0.3/Convex/src/atoms/affine/multiply_divide.jl:75
 in conic_form! at /Users/eric/.julia/v0.3/Convex/src/atoms/affine/multiply_divide.jl:68
 in conic_form! at /Users/eric/.julia/v0.3/Convex/src/atoms/affine/add_subtract.jl:106
 in conic_form! at /Users/eric/.julia/v0.3/Convex/src/constraints/constraints.jl:36
 in conic_form! at /Users/eric/.julia/v0.3/Convex/src/problems.jl:61
 in conic_problem at /Users/eric/.julia/v0.3/Convex/src/problems.jl:73
 in solve! at /Users/eric/.julia/v0.3/Convex/src/solution.jl:23
 in runprob at /Users/eric/repos/juliaportopt/CVXTest.jl:22
 in main at /Users/eric/repos/juliaportopt/CVXTest.jl:42

This happens on Convex.jl master with both Julia 0.3.1 and Julia master (though in master ::Nothing becomes ::Void).

Here is the formulation causing these issues: https://gist.github.com/iamed2/ce0ce8523f080e071bba

mailing list?

Hello all,

Is there a mailing list where I can shoot a lot of stupid questions?

diagm(Variable(n)) feature request

Trying to put a variable vector into a diagonal matrix returns ERROR: diagm has no method matching diagm(::Variable). I can certainly write my own routine for it, but if you all think it's a useful feature to have built in, then I would like to submit it as a feature request. Thanks.

satisfy not defined

julia> x = Variable();

julia> p = satisfy(x <= 0)
ERROR: satisfy not defined

Allow Int32 sizes

Currently Convex.jl assumes sizes and such are Int64s, and so fails on 32 bit machines. eg

Variable(int32(3))

fails. We need to replace all instances of ::Int64 and such with Integer. Doing the same for Float64->FloatingPoint would also probably be a good idea.

No support for equality-only constrained problems

using CVX
x = Variable()
p = minimize(x, x == 1)
solve!(p)

ERROR: type: typeassert: expected Union(Array{T,2},Array{T,1},SparseMatrixCSC{Tv,Ti<:Integer}), got Nothing
 in ecos_solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:104
 in solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:56
 in solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:55

When I add an inequality constraint (e.g. x >= 0), solve!(p) works fine. I believe the problem occurs when we have problems that only have equality constraints (with no inequality constraints).

Can't manually optimize over a constant

p = Problem(:minimize, 0)
ERROR: no method Problem(Symbol,Int64)

julia> p = Problem(:minimize, Constant(0));

julia> solve!(p)
ERROR: type: typeassert: expected Union(Array{T,1},SparseMatrixCSC{Tv,Ti<:Integer},Array{T,2}), got Nothing
 in ecos_solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:104
 in solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:56
 in solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:55

This also means that things like the following code snippet don't work.

julia> p = minimize(0)
ERROR: no method minimize(Int64,)

julia> p = minimize(Constant(0));

julia> solve!(p)
ERROR: type: typeassert: expected Union(Array{T,1},SparseMatrixCSC{Tv,Ti<:Integer},Array{T,2}), got Nothing
 in ecos_solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:104
 in solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:56
 in solve! at /Users/jennyhong/.julia/v0.2/CVX/src/problems/problems.jl:55

Fix maximization bug

test 11 currently fails. This is attributable to the new re-factor in the dev branch that makes problems.jl (more) agnostic to the solver being used. solvers/ecos.jl will probably have to be fixed to handle maximization problems correctly.

Unbounded maximum likelihood

Hello!

I am using convex.jl to test and see if it works on a simple maximum likelihood estimator for logistic regression. It is giving me unbounded results though - I am not sure if it's an issue with my formulation or something else. Would you be able to take a quick look and let me know where I may have made a mistake? Thank you very much in advance!

using DataFrames
using RDatasets
using Convex
using SCS

iris = dataset("datasets", "iris")
iris[:Y] = [species == "versicolor" ? 1.0 : 0.0 for species in iris[:Species]]
X = [ones(size(iris, 1)) iris[:SepalLength] iris[:SepalWidth] iris[:PetalLength] iris[:PetalWidth]]
Y = array(iris[:Y])

# Solve the NLP using Convex.jl and SCS packages
# reference: http://cvxr.com/cvx/examples/cvxbook/Ch07_statistical_estim/html/logistics.html
n, p = size(X)
beta = Variable(p)
problem = maximize(Y'*X*beta-sum(logsumexp([X*beta zeros(n)]))) # -0.01*norm(beta,1)


scs = SCSSolver()
solve!(problem, scs)

Output:

Setup time: 8.27e-04s
----------------------------------------------------------------------------
 Iter | pri res | dua res | rel gap | pri obj | dua obj | kap/tau | time (s)
----------------------------------------------------------------------------
     0|      inf       inf       nan      -inf       inf       inf  3.44e-03 
    40|      inf       inf       nan      -inf      -inf       inf  5.09e-03 
----------------------------------------------------------------------------
Status: Unbounded

Type error on examples

I am getting a type error on problem specification line using the code in the Quick Example on the Convex.jl web page:

problem = minimize(sum_squares(A * x + b), [x >= 0])
generates this error:
LoadError: TypeError: non-boolean (Convex.EqConstraint) used in boolean context
while loading In[3], in expression starting on line 1

in hash at hashing2.jl:184
in call at C:\Users\bens.julia\v0.4\Convex\src\atoms/affine/add_subtract.jl:82
in + at C:\Users\bens.julia\v0.4\Convex\src\atoms/affine/add_subtract.jl:119

I also get a similar error at this line from the Linear Program example in the basic usage notebook:

p.constraints += [x >= 1; x <= 10; x[2] <= 5; x[1] + x[4] - x[2] <= 10](here the error is at line 117 instead of 119; I also sometimes get errors on line 122 of add_subtract.jl)

[Julia 0.4.0-dev+3442 on Win7x64 with the Convex package loaded today (ver 0.0.4)]

Problem with solution of maximum entropy problem (or request for documentation)

I thought it would be nice to contribute a pair of examples for finding exponential family distributions (http://en.wikipedia.org/wiki/Exponential_family) with a given set of features and expectation values. The first example would consist of maximizing the relative entropy between the target distribution and a base measure under constraints n the expectation values. The second example would be the same thing, but where the maximization occurs on a much lower dimensional dual space (the Langrange multipliers that fix expectation values for a set of chosen features), which presumably is the easier problem. The point of the example would be to show that the two methods yield the same result.

Here is a bit of code that (at least initially), appeared to solve the first part of the problem for the case where the solution should be a Binomial distribution

using Gadfly
using Distributions
using Convex, SCS

#space and probalities
N = 32
X = 0:N
p = Variable(length(X))
probability_contraints = [0 <= p, p <= 1, sum(p) == 1];
#base measure
h = pdf(Binomial(N,1/2))
#feature expectation values
q = .3
μ =N*q
fs = [identity]
η = [μ]
C = hcat([map(f,X) for f in fs]...)'
feature_constraints = C * p == η
#definte optimization problem and solve
problem = maximize(entropy(p)+dot(p,log(h)),probability_contraints...,feature_constraints)
solve!(problem, SCSSolver(verbose=0))
#plot solution
plot(layer(x=X,y=p.value,Geom.point),
     layer(x=X,y=pdf(Binomial(N,q)),Geom.bar),Scale.x_discrete)

example1

However, trying out a larger number of states (N=64) results in:

image

In both cases problem.solution.status is :Optimal. However, from the figure above it is clear that the solution is considerably far from the linear constraint. So, is there a bug (in convergence or constraint enforcement) at larger N values or do I just have the wrong idea about the range of final states that yield :Optimal convergence status? If the later is the case, is there some documentation one sensitivity parameters to ensure one is near the constraint subspace?

P.S.

This is my first time looking into Convex.jl and this whole thing about automatic convexity detection within such a rich modeling language seems very magical. Its great :)

Test with all capable solvers

I have not tested Convex with the following solvers:

  • CPLEX
  • Ipopt
  • Cbc
  • Clp

We should probably make sure nothing goes wrong with these, although I'd assume things would be fine.

Fix Deprecation Warnings on 0.3.0

Started testing on pre-release 0.3.0 on Ubuntu. Two main deprecation warnings:

WARNING: A::Array - x::Number is deprecated, use A .- x instead.
WARNING: Set(a,b...) is deprecated, use Set({a,b...}) instead.

As such, these are easy to fix, but we need to make a few decisions regarding the behavior of + and .+ in CVX. @davidlizeng: Do we allow Vector/Matrix AbstractCvxExpr +- Scalar AbstractCvxExpr in CVX? If we are to be consistent with what Julia is doing, it seems like we shouldn't. What we would do then is throw an error and ask them to use .+ or .-.

Documentation for Convex.jl

Our documentation doesn't do a great job of explaining Convex.jl. We should also have a proper documentation on Read the Docs.

Should constants have a uid?

If they did, we'd have an easier time extending atoms to constants, since many atoms access the uid of their arguments. eg

julia> geo_mean(x,Constant(1))
ERROR: type Constant has no field uid
in geo_mean at /Users/madeleine/.julia/CVX/src/atoms/geo_mean.jl:19

Problems installing on OS X 10.9.4 julia Version 0.4.0-dev+196

I have problem installing CVX

My version info:

julia> versioninfo()
Julia Version 0.4.0-dev+196
Commit 6ca401c* (2014-08-17 18:19 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.3.0)
  CPU: Intel(R) Core(TM) i7 CPU       M 620  @ 2.67GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Nehalem)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

I followed the indicated steps:

  1. Pkg.clone("https://github.com/cvxgrp/CVX.jl.git") OK
  2. Pkg.clone("https://github.com/karanveerm/ECOS.jl.git") (note that in your the README.md in section Install there should be a typo, Pkg.clone("[email protected]:karanveerm/ECOS.jl.git") does not make sense)

here there is a warning

INFO: Cloning ECOS from https://github.com/karanveerm/ECOS.jl.git
INFO: Computing changes...
WARNING: julia is fixed at 0.4.0-dev+196 conflicting with requirement for DimensionalityReduction: [0.1.0,0.3.0)
INFO: No packages to install, update or remove

now comes the problem:

julia> using CVX
Warning: could not import Base.square into CVX
ERROR: could not open file /Users/pagnani/.julia/CVX/src/macros/macro.jl
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in include at ./boot.jl:245
 in include_from_node1 at ./loading.jl:128
 in reload_path at loading.jl:152
 in _require at loading.jl:67
 in require at loading.jl:51
while loading /Users/pagnani/.julia/CVX/src/CVX.jl, in expression starting on line 42

My wild guess is the interaction with the 0.4 release ...

I am very excited to see how the julia implementation of CVX works.

Support .*

Feature request: define .(::Variable, ::Constant) and .(::Constant, ::Variable)

X = Variable(2,3)
A = rand(2,3)
X.*A # currently not defined

pretty printing

We should display something more useful for the user when they will try to print out a variable or expression. A first attempt is in the display branch. It looks like this:

julia> x = Variable()
Variable(1,1)

julia> 2*x
CvxExpr((1,1),linear)

julia> square(x) <= 4
CvxConstr: CvxExpr((1,1),convex) <= 4

julia> minimize(square(x),[x >=0, min(x,4) >= 2])
Problem: minimize CvxExpr((1,1),convex)
subject to
CvxConstr: CvxExpr((1,1),linear) <= 0
CvxConstr: CvxExpr((1,1),convex) <= -2

Is this misleading? And does it miss any important information?

n-d variables?

CVX seems to support variables indexed over an arbitrary number of dimensions, e.g.,

variable z(100,100,100)

Are there plans to support this in Convex?

current status

Hi, just a quick question. Is this package stable and usable as the matlab cvx? I took 364a quite a while ago and it was taught using cvx. But peronsally I don't use matlab for my daily task. For computations I mainly use python and recently switched to julia. So just wondering if it is able to replace cvx (so that I can uninstall and forget matlab)?

translate to standard conic form

Fill in the functions in conic problem.jl to correctly translate between three different standard cone formats, and from the Problem form into each standard cone form:

  1. ConicProblem, following the standard described here

  2. IneqConicProblem, following the same standard but allowing generalized inequality constraints Gx \leq h, so the indices in the variable cones refer to constraints rather than variables.

  3. ECOSConicProblem, which is described here. (A translation from Problem to ECOSConicProblem is already implemented.)

example of slow model generation

I was playing around with implementing a basic linear SVM in both Convex.jl and JuMP and noticed a pretty significant penalty for model generation in Convex.jl:

using JuMP
using Distributions
using Gurobi
import Convex # namespace conflicts with JuMP.Variable()

function gen_data(n)
    pos = rand(MvNormal([1.0,2.0],1.0),n)
    neg = rand(MvNormal([-1.0,1.0],1.0),n)
    return pos,neg
end

const N = 2
const C = 10
function svm_jump(pos,neg, solver)

    m = Model(solver=solver)

    @defVar(m, w[1:N])
    @defVar(m, b)
    @defVar(m, ξpos[1:size(pos,2)] >= 0)
    @defVar(m, ξneg[1:size(neg,2)] >= 0)

    @setObjective(m, Min, sum{w[i]^2, i = 1:N} + C*sum(ξpos) + C*sum(ξneg))
    @addConstraint(m, posconstr[j=1:size(pos,2)], dot(w,pos[:,j]) - b >= 1 - ξpos[j])
    @addConstraint(m, negconstr[j=1:size(neg,2)], -1*(dot(w,neg[:,j]) - b) >= 1 - ξneg[j])

    status = solve(m)
    @assert status == :Optimal
    return getValue(w[:]), getValue(b)
end

function svm_convex(pos,neg,solver)
    w = Convex.Variable(N)
    b = Convex.Variable()
    ξpos = Convex.Variable(size(pos,2), Convex.Positive())
    ξneg = Convex.Variable(size(neg,2), Convex.Positive())

    problem = Convex.minimize(Convex.sum_squares(w) + C*sum(ξpos) + C*sum(ξneg))
    for j in 1:size(pos,2)
        push!(problem.constraints, dot(w,pos[:,j]) - b >= 1 - ξpos[j])
        #problem.constraints += dot(w,pos[:,j]) - b >= 1 - ξpos[j]
    end
    for j in 1:size(neg,2)
        push!(problem.constraints, -1*(dot(w,neg[:,j]) - b) >= 1-ξneg[j])
        #problem.constraints += -1*(dot(w,neg[:,j]) - b) >= 1-ξneg[j]
    end
    Convex.solve!(problem, solver)
    return Convex.evaluate(w), Convex.evaluate(b)
end

pos,neg = gen_data(10)
# initial compilation
svm_jump(pos,neg, GurobiSolver(OutputFlag=0))
svm_convex(pos,neg, GurobiSolver(OutputFlag=0))

pos,neg = gen_data(2000)
@time w, b = svm_jump(pos,neg, GurobiSolver())
@show w,b
@time w, b = svm_convex(pos,neg, GurobiSolver())
@show w,b

Both give approximately the same answer. For JuMP on my machine, Gurobi solves in 0.09 seconds and the whole thing is done in 0.10 seconds. For Convex.jl, Gurobi solves in 0.11 seconds but the total time is 6.5 seconds.

I know model generation time hasn't been as much of a priority as with JuMP, and Convex.jl has to do more work in principle since it's performing a lot of automatic transformations. Anyway I wanted to share this as a benchmark that could be used to speed up Convex.jl.

CC @IainNZ @joehuchette

Missing kron for convex programming variables

I am trying to write a convex program that includes the constraint

W-kron(eye(dim),rho) <= 0

where W and rho are Semidefinite variables, and dim is an integer. This leads to an error of the form

ERROR: `kron` has no method matching kron(::Array{Float64,2}, ::Variable)

and searching the repository, it seems like indeed kron is not defined for Convex variables.

geo_mean doesn't take constants

julia> geo_mean(x,1)
ERROR: no method geo_mean(Variable, Int64)

julia> geo_mean(x,[1])
ERROR: no method geo_mean(Variable, Array{Int64,1})

this breaks sqrt:

julia> x = Variable()
julia> sqrt(1+2*x)
ERROR: no method geo_mean(CvxExpr, Array{Float64,2})
in sqrt at /Users/madeleine/.julia/CVX/src/atoms/elementwise/sqrt.jl:5

binary knapsack problem fails

From the following binary knapsack problem,

d = Variable(3, :Bin)
obj = [2,3,4]
problem = minimize(dot(obj,d), sum(d) == 1)
solve!(problem)

I get quite a strange error:

ERROR: Positive semidefinite expressions must be square
 in SDPConstraint at /home/mlubin/.julia/v0.3/Convex/src/constraints/sdp_constraints.jl:14
 in conic_form! at /home/mlubin/.julia/v0.3/Convex/src/constraints/signs_and_sets.jl:7
 in conic_form! at /home/mlubin/.julia/v0.3/Convex/src/variable.jl:75
 in conic_form! at /home/mlubin/.julia/v0.3/Convex/src/atoms/affine/multiply_divide.jl:84
 in conic_form! at /home/mlubin/.julia/v0.3/Convex/src/atoms/affine/add_subtract.jl:106
 in conic_form! at /home/mlubin/.julia/v0.3/Convex/src/constraints/constraints.jl:36
 in conic_form! at /home/mlubin/.julia/v0.3/Convex/src/problems.jl:60
 in conic_problem at /home/mlubin/.julia/v0.3/Convex/src/problems.jl:72
 in solve! at /home/mlubin/.julia/v0.3/Convex/src/solution.jl:8
 in solve! at /home/mlubin/.julia/v0.3/Convex/src/solution.jl:63
 in solve! at /home/mlubin/.julia/v0.3/Convex/src/solution.jl:8

Convex.jl tutorials and examples

It will be nice to have ijulia notebook examples where we walk through non-trivial problems, ensure DCP-compliance, solve them etc. We already have a number of these from the talks that we have given, we just need to clean them up. We can always get more from the convex opt textbook.

Solvers

Hey,
Sorry if I have missed something important, but I couldn't figure it out how to introduce my readily available solvers Gurobi and Mosek to Convex. When trying to run the command "using Convex," it asked me to install ECOS. Why should I need it when I have Gurobi and Mosek installed, together with the corresponding Julia packages? Moreover, what is the best way to point to the solver of choice in Convex and/or Julia? I couldn't see it in your examples and/or the paper in arXiv.
Best,

TypeError in constraints on 0.4.0-dev

I've tried to used Convex for the first time, on a 0.4.0-dev+4219 Julia build, and nothing works. Even the simplest examples fail with the following error, probably due to some missing automatic conversion to Bool:

LoadError: TypeError: non-boolean (Convex.EqConstraint) used in boolean context
while loading In[1], in expression starting on line 5

 in hash at hashing.jl:107
 in call at /home/dave/.julia/v0.4/Convex/src/atoms/affine/add_subtract.jl:82
 in + at /home/dave/.julia/v0.4/Convex/src/atoms/affine/add_subtract.jl:117

I've tried with the following example from the BasicUsage page, which works on 0.3.7 release:

using Convex

X = Variable(2, 2)
y = Variable()
p = minimize(sum(X) + y, 2 * X <= 1, X' + y >= 1, X >= 0, y >= 0)
solve!(p)

More versioninfo():

julia> versioninfo()
Julia Version 0.4.0-dev+4219
Commit ae23430* (2015-04-13 05:26 UTC)
Platform Info:
  System: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz
  WORD_SIZE: 64
  BLAS: libopenblas (NO_AFFINITY SANDYBRIDGE)
  LAPACK: liblapack.so.3
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Testing different solvers

@ulfworsoe has been working on implementing the conic interface in Mosek, including support for SDPs.
Could the tests in Convex.jl be made parametric on the solver? Currently it seems to be a bit messy to plug in a new solver to test its capabilities.

Installing ECOS

Dear experts,
I'm having problems installing CVX as described in the README.md file. It seems that there are problems downloading the ECOS.jl project. The output I get from julia is:

julia> Pkg.clone("[email protected]:karanveerm/ECOS.jl.git")
INFO: Cloning ECOS from [email protected]:karanveerm/ECOS.jl.git
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
ERROR: unlink: no such file or directory (ENOENT)
in unlink at fs.jl:96
in rm at file.jl:56
in clone at pkg/entry.jl:151
in clone at pkg/entry.jl:173
in anonymous at pkg/dir.jl:28
in cd at file.jl:20
in cd at pkg/dir.jl:28
in clone at pkg.jl:30

julia>

Thanks,

Einar Otnes

Using SCS and Convex.jl

I have never been able to call SCS using Convex.jl, I always get:

ERROR: solve! has no method matching solve!(::Problem, ::SCSSolver)

For example, using the code verbatim from jump-dev/SCS.jl#24 I get that error. I'm pretty sure the packages I'm using are up to date, because I run this first:

julia> Pkg.update()
INFO: Updating METADATA...
INFO: Cloning cache of SCS from git://github.com/JuliaOpt/SCS.jl.git
INFO: Updating cache of Compat...
INFO: Updating cache of SHA...
INFO: Updating cache of Convex...
INFO: Updating cache of BinDeps...
INFO: Updating cache of URIParser...
INFO: Updating cache of MathProgBase...
INFO: Updating cache of JSON...
INFO: Updating cache of Homebrew...
INFO: Updating SCS...
INFO: Computing changes...
INFO: Upgrading BinDeps: v0.3.7 => v0.3.11
INFO: Upgrading Compat: v0.2.7 => v0.4.2
INFO: Upgrading Convex: v0.0.1 => v0.0.4
INFO: Upgrading Homebrew: v0.1.13 => v0.1.14
INFO: Upgrading JSON: v0.4.0 => v0.4.3
INFO: Upgrading MathProgBase: v0.3.8 => v0.3.11
INFO: Upgrading SHA: v0.0.3 => v0.0.4
INFO: Upgrading URIParser: v0.0.3 => v0.0.5
INFO: Removing ECOS v0.4.1
INFO: Building Homebrew
remote: Counting objects: 22643, done.
remote: Compressing objects: 100% (6711/6711), done.
remote: Total 22643 (delta 17368), reused 21124 (delta 15871), pack-reused 0
Receiving objects: 100% (22643/22643), 6.03 MiB | 1.23 MiB/s, done.
Resolving deltas: 100% (17368/17368), completed with 933 local objects.
From https://github.com/Homebrew/homebrew
   35b453a..7731e73  master     -> origin/master
HEAD is now at 7731e73 ruby_requirement: add/fix default_formula.
remote: Counting objects: 156, done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 156 (delta 32), reused 30 (delta 30), pack-reused 112
Receiving objects: 100% (156/156), 34.07 KiB | 0 bytes/s, done.
Resolving deltas: 100% (78/78), done.
From https://github.com/staticfloat/homebrew-juliadeps
   9c64dd6..eb0a89f  master     -> origin/master
   1815f94..59e3711  staging    -> origin/staging
HEAD is now at eb0a89f Merge pull request #42 from staticfloat/staging

So what am I doing wrong? I'm on Julia 0.3.4 by the way.

clean up tests

what is the difference between test and test2? if there is none, they should be merged; if there is a difference, the naming scheme should reflect it. perhaps test_lp?

`optimize!` has no method matching optimize!(::ECOSMathProgModel)

https://github.com/cvxgrp/CVX.jl/blob/master/src/solution.jl#L14

When I run I get:

WARNING: The MathProgSolverInterface.jl file is DEPRECATED in favor of the SolverInterface/ directory. Do not point your packages directly to this file.
Loading data...done.
Formulating problem...done.
Solving...ERROR: `optimize!` has no method matching optimize!(::ECOSMathProgModel)
 in solve! at /home/eric.davies/.julia/v0.4/CVX/src/solution.jl:14
 in tradeoffFormulationFunction at /home/eric.davies/Downloads/cvxTest.jl:38
 in main at /home/eric.davies/Downloads/cvxTest.jl:48
 in include at ./boot.jl:246
 in include_from_node1 at loading.jl:128
 in process_options at ./client.jl:285
 in _start at ./client.jl:354
 in _start_3B_3594 at /home/eric.davies/repos/julia/usr/bin/../lib/julia/sys.so
while loading /home/eric.davies/Downloads/cvxTest.jl, in expression starting on line 52

It looks like importall MathProgBase also imports SolverInterface which does have the optimize! method. Perhaps changing most instances of MathProgBase to SolverInterface is all that is needed?

This happens on Julia 0.4.0-dev+540 as well as Julia 0.3.0. I installed CVX and ECOS via the instructions in README.md.

NonConvex

I just started trying to extend Convex.jl to solve sigmoidal programs (which are not convex) by calling a sigmoidal programming solver I built. I'd like to be able to automatically detect sigmoidal programs and treat them appropriately. I've built some machinery to do this here, but somehow the monotonicity function I've written doesn't seem to be accessible; I get the error from the fallback function in Convex.jl. Any idea why?

~/.julia/v0.3/SigmoidalProgramming (model)ᐅ julia test/test_model.jl
ERROR: monotonicity not implemented for sigmoid.
in error at error.jl:21
in vexity at /Users/madeleine/.julia/v0.3/Convex/src/expressions.jl:47
in vexity at /Users/madeleine/.julia/v0.3/Convex/src/expressions.jl:50
in solve_sp! at /Users/madeleine/.julia/v0.3/SigmoidalProgramming/src/model.jl:68
in include at boot.jl:245
in include_from_node1 at loading.jl:128
in process_options at client.jl:285
in _start at client.jl:354
while loading /Users/madeleine/.julia/v0.3/SigmoidalProgramming/test/test_model.jl, in expression starting on line 14

linear matrix combination

I would like to form a linear matrix combination of the form x1A1 + ... + xnAn, by doing:

dot([A1, ..., An], Variable(n))

However when I try to do this I get the error:
ERROR: isless has no method matching isless(::Array{Float64,2}, ::Int64)

Run ECOS in quiet mode

As per Madeleine's email, we should probably make the solver quiet by default, with a verbose option to actually see the solver iterations.

warmstarting

Suppose a user wants to solve the same problem over and over again, varying one parameter, without changing the structure of the problem. For example, the user might want to compute a full regularization path. In this case, it would be nice to be able to do some kinds of warmstarting: both on the solving and on the parsing. There are many complexities here, and many difficult and easy things we could do to make this kind of workflow faster.

easy:

  • warmstart from the previous solution if the size of the solution is correct. it might be easiest to warmstart the primal and dual solution if we cache the full solution object returned by the solver; or even cache the entire MathProgModel we formed when we last solved the problem. then we could just check that the sizes of the parameters of the problem we've made (c, A, b) match the sizes of the corresponding parameters in the MathProgModel.

harder:

  • if no structural changes are made, then we should be able to form the new problem data c, A, b by slotting the constants in the problem into the right slots --- without reparsing the problem. in other words, we could just cache the matrix stuffing map and reuse it, so long as nothing structural changed. then we'd just update the c, A, and b fields in the model, rather than forming an entirely new model.

hardest:

  • listen for when changes are made to problem structure after having solved the problem. if no changes have been made, then warmstart.

right now, we warmstart by default, but only from the primal solution, and we don't check the size.

Implement missing atoms

Among major atoms I can think of:

(Edited as per comments below)

  • log det
  • lambda max
  • lambda min
  • huber

Are there any important ones that we don't have and I'm missing / atom requests?

Use dual values from ECOS.jl

Yo,
I'm not sure if you want it, but ECOS.jl now gives you the duals through the mathprogbase interface (I've tagged this as ECOS.jl v0.3.0).
Testing may reveal errors because I wouldn't describe our current MPB conic interface tests comprehensive, but I'm pretty happy its correct for LPs and at least simple SOCPs.

Segmentation fault: 11

Hi there,

I am using a variation of the example logistic regression code with Convex.jl. The code seems to work for the first time I run in Julia, but if I try running the exact same code again in the Julia kernel, the terminal would quit out of Julia with a segmentation fault as below:

signal (11): Segmentation fault: 11
broadcast! at broadcast.jl:220
broadcast at broadcast.jl:234
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
+ at /Users/zhuo/.julia/v0.3/Convex/src/conic_form.jl:26
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
conic_form! at /Users/zhuo/.julia/v0.3/Convex/src/atoms/affine/add_subtract.jl:110
conic_form! at /Users/zhuo/.julia/v0.3/Convex/src/constraints/constraints.jl:79
conic_form! at /Users/zhuo/.julia/v0.3/Convex/src/atoms/exp_cone/logsumexp.jl:52
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
conic_form! at /Users/zhuo/.julia/v0.3/Convex/src/atoms/affine/add_subtract.jl:46
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
conic_form! at /Users/zhuo/.julia/v0.3/Convex/src/atoms/affine/add_subtract.jl:106
conic_form! at /Users/zhuo/.julia/v0.3/Convex/src/constraints/constraints.jl:36
conic_form! at /Users/zhuo/.julia/v0.3/Convex/src/problems.jl:60
conic_problem at /Users/zhuo/.julia/v0.3/Convex/src/problems.jl:72
solve! at /Users/zhuo/.julia/v0.3/Convex/src/solution.jl:13
julia_solve!;20593 at  (unknown line)
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
solve_convex at /Users/zhuo/documents/Julia/logit_func.jl:43
jlcall___solve_convex#175__;21122 at  (unknown line)
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/gf.c:1416
julia_solve_convex;21121 at  (unknown line)
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/interpreter.c:59
eval at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/interpreter.c:207
jl_toplevel_eval_flex at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/toplevel.c:494
jl_parse_eval_all at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/toplevel.c:542
jl_load at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/toplevel.c:579
include at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
include_from_node1 at /Applications/Julia-0.3.0.app/Contents/Resources/julia/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/interpreter.c:59
eval at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/interpreter.c:207
jl_toplevel_eval_flex at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/toplevel.c:494
jl_f_top_eval at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/builtins.c:396
eval_user_input at REPL.jl:54
jlcall_eval_user_input;19884 at  (unknown line)
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/./julia.h:980
anonymous at task.jl:96
jl_apply at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/task.c:427
julia_trampoline at /Users/vagrant/tmp/julia-packaging/osx10.7+/julia-release-0.3/src/init.c:1007
Segmentation fault: 11

The code I used was the following:

using DataFrames
using RDatasets
using Convex
using SCS

# we'll use iris data
# predict whether the iris species is versicolor using the sepal length and width and petal length and width
iris = dataset("datasets", "iris")
## outcome variable: +1 for versicolor, -1 otherwise
iris[:Y] = [species == "versicolor" ? 1.0 : -1.0 for species in iris[:Species]]
Y = array(iris[:Y])
## create data matrix with one column for each feature (first column corresponds to offset)
X = [ones(size(iris, 1)) iris[:SepalLength] iris[:SepalWidth] iris[:PetalLength] iris[:PetalWidth]];


function solve_convex(X, Y; paramGamma = 0)
    # # Solve the NLP using Convex.jl and SCS packages
    n, p = size(X)
        beta = Variable(p)
        mu = Variable()
        nu = Variable(n)
        problem = maximize(-logistic_loss(-Y.*(X*beta)) + paramGamma*mu + sum(nu))
        for (i = 1:n)
            problem.constraints += mu + nu[i] <= -2
            problem.constraints += nu[i] <= 0
        end
        problem.constraints += mu <= 0

    scs = SCSSolver((verbose=0))
    solve!(problem, scs)
    return(beta.value)

end

solve_convex(X, Y; paramGamma = 3)

Have you encountered such crashing out of Julia before?

QCQP problem setup: constraint violated or incorrect problem setup

Quadratically constrained quadratic programming problem discussed in this julia-opt group question.

When tried with Convex.jl, results in an unconstrained minimum and no warnings about constraint violation. Recently (probably after some commits around Nov 14 via Pkg.update()) the behavior changed and all NaN are returned. Full code to reproduce in this gist.

Is something not right about the problem formulation within the Convex.jl conventions or is it a bug?

Finish migration to JuliaOpt

Clean up the trailing links:

  • travis
  • coveralls
  • readthedocs
  • juliacon
  • john miles white

then:

  • annouce on julia-users
  • announce on julia-opt

(Joey: edited for checkboxes)

Incorrect behavior for .evaluate() on concatenate expressions

When we form CvxExprs via concatenation (i.e. hcat or vertcat), the expression's .evaluate() returns an array of anonymous functions (which are the the atom's argument's .evaluate() functions)

For example

julia> x = Variable();

julia> y = Variable();

julia> e = hcat(x, y);

julia> e.evaluate()
1x2 Array{Function,2}:
 (anonymous function)  (anonymous function)

julia> f = vertcat(x, y);

julia> f.evaluate()
2-element Array{Function,1}:
 (anonymous function)
 (anonymous function)

operator_norm vs norm

Hi

I am doing a problem (2.3 from EE364B exercises) where I am trying to approximate B as a combination of A_i's. The approximation is in the operator norm. i.e. max singular value.

Here is the code.

using Convex

srand(0)
n, p, q = 5, 3, 6
A = {randn(p, q) for _ in 1:n}
B = randn(p, q)

function diff(x)
    d = B
    for i in 1:n
        d -= x[i] * A[i]
    end
    return d
end

################### CVX 
xcvx = Variable(n)
problem = minimize(operator_norm(diff(xcvx)))
solve!(problem)

println("Status : ", problem.status)
println("Value : ", problem.optval)
u, d, v = svd(diff(xcvx.value))
println("X: ", xcvx.value, norm(diff(xcvx.value)), d[1])
fst = problem.optval

I am having to say operator_norm in stead of norm. If I say norm, cvx is minimizing something else. I think it should be consistent with underlying Julia where norm of a matrix is the operator norm by default.

excessive warnings?

the following expression gives the warning WARNING: x + y is deprecated if sizes do not match. Use x .+ y instead. It shouldn't, because 2*x and 1 are scalar.

using CVX
x = Variable()
2*x + 1

Crashing due to DCP non-compliance

The following non-DCP compliant code correctly throws the warnings. However, if the user proceeds to call solve!, we crash out since multiplication atom assumes one of its arguments will be a Constant.

We should either throw an error, instead of just a warning, or actually allow the user to solve the non-dcp problem. @davidlizeng

julia> using Convex; x=Variable(); y=Variable();
julia> p=minimize(x*y)
WARNING: Expression not DCP compliant
Problem:
minimize AbstractExpr with
head: *
size: (1, 1)
sign: NoSign()
vexity: NotDcp()

subject to

current status: not yet solved

julia> solve!(p)
ERROR: `getindex` has no method matching getindex(::Nothing, ::Int64)
 in conic_form! at /Users/karanveer/.julia/v0.3/Convex/src/atoms/affine/multiply_divide.jl:75
 in conic_form! at /Users/karanveer/.julia/v0.3/Convex/src/atoms/affine/add_subtract.jl:106
 in conic_form! at /Users/karanveer/.julia/v0.3/Convex/src/constraints/constraints.jl:36
 in conic_form! at /Users/karanveer/.julia/v0.3/Convex/src/problems.jl:61
 in conic_problem at /Users/karanveer/.julia/v0.3/Convex/src/problems.jl:73
 in solve! at /Users/karanveer/.julia/v0.3/Convex/src/solution.jl:23 (repeats 2 times)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.