jump-dev / convex.jl Goto Github PK
View Code? Open in Web Editor NEWA Julia package for disciplined convex programming
Home Page: https://jump.dev/Convex.jl/stable/
License: Other
A Julia package for disciplined convex programming
Home Page: https://jump.dev/Convex.jl/stable/
License: Other
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.
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
horizonatally is misspelled, it should should be horizontally
Our documentation doesn't do a great job of explaining Convex.jl. We should also have a proper documentation on Read the Docs.
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.
Clean up the trailing links:
then:
(Joey: edited for checkboxes)
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?
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?
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.
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)
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 .-
.
Hello all,
Is there a mailing list where I can shoot a lot of stupid questions?
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
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
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:
harder:
hardest:
right now, we warmstart by default, but only from the primal solution, and we don't check the size.
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
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).
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?
julia> x = Variable();
julia> p = satisfy(x <= 0)
ERROR: satisfy not defined
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)
However, trying out a larger number of states (N=64) results in:
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 :)
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
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.
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.
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.
I have not tested Convex with the following solvers:
We should probably make sure nothing goes wrong with these, although I'd assume things would be fine.
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
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)]
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:
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.
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)
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,
Among major atoms I can think of:
(Edited as per comments below)
Are there any important ones that we don't have and I'm missing / atom requests?
There doesn't seem to be a signature getindex(::Variable,::Array{Bool})
. If this isn't for some style reason, I think it is useful.
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
As per Madeleine's email, we should probably make the solver quiet by default, with a verbose
option to actually see the solver iterations.
Anything I'm missing?
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.
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.
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)?
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
When we form CvxExpr
s 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)
@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.
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?
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.
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
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.
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:
ConicProblem, following the standard described here
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.
ECOSConicProblem, which is described here. (A translation from Problem to ECOSConicProblem is already implemented.)
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?
Note that Convex.jl was previously called Convex.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
Feature request: define .(::Variable, ::Constant) and .(::Constant, ::Variable)
X = Variable(2,3)
A = rand(2,3)
X.*A # currently not defined
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.