# Bounding Correlation Coefficients with JuMP

**URL:** https://discourse.julialang.org/t/bounding-correlation-coefficients-with-jump/59589
**Category:** Optimization (Mathematical)
**Tags:** package, jump
**Created:** [April 19, 2021, 10:41am UTC](https://discourse.julialang.org/t/bounding-correlation-coefficients-with-jump/59589 "2021-04-19T10:41:02Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![phantom](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@phantom](https://discourse.julialang.org/u/phantom)
#### Post date: [April 19, 2021, 10:41am UTC](https://discourse.julialang.org/t/bounding-correlation-coefficients-with-jump/59589/1 "2021-04-19T10:41:02Z")

</div>

New to julia and this discussion group so I’m sorry if this is not a typical discussion topic or if I am breaching any norms here. I will do my best to pick up on things as I go.

In “Convex Optimization” by Boyd there is an example of bounding correlation coefficients. (See Convex Optimization p.408 Ex. 8.3) I tried solving this example with Julia using JuMP and the code provided in The Correlation Problem tutorial.

While the optimizer returns the correct minimum value, the maximum value returned is not the lowest upper bound. The code returns a maximum value of 1, whereas the books lists the maximum value as .23. I think the book is correct because Joelle Skaf posted a [solution](http://web.cvxr.com/cvx/examples/cvxbook/Ch08_geometric_probs/html/ex_8_3.html#output) to the same problem solved with Mosek also received .23 as the sup. Just wondering if anyone had any insights as to why the code is not returning the correct upper bound.

This is the code I used. Again aside from changing the parameters and variables, the code was taken directly from the Correlation Problem tutorial on the [Jump website](https://jump.dev/JuMP.jl/stable/tutorials/Semidefinite%20programs/corr_sdp/).

```julia

function example_corr_sdp()
    model = Model(SCS.Optimizer)
    set_silent(model)
    @variable(model, X[1:4, 1:4], PSD)
    # Diagonal is 1s
    @constraint(model, X[1, 1] == 1)
    @constraint(model, X[2, 2] == 1)
    @constraint(model, X[3, 3] == 1)
    @constraint(model, X[4, 4] == 1)
    # Bounds on the known correlations
    @constraint(model, X[1, 2] >= 0.6)
    @constraint(model, X[1, 2] <= 0.9)
    @constraint(model, X[1, 3] >= 0.8)
    @constraint(model, X[1, 3] <= 0.9)
    @constraint(model, X[2, 4] >= 0.5)
    @constraint(model, X[2, 4] <= 0.7)
    @constraint(model, X[3, 4] >= -0.8)
    @constraint(model, X[3, 4] >= -0.4)
    # Find upper bound
    @objective(model, Max, X[1, 4])
    optimize!(model)
    println("An upper bound for X[1, 4] is $(value(X[1, 4]))")
    # Find lower bound
    @objective(model, Min, X[1, 4])
    optimize!(model)
    println("A lower bound for X[1, 4] is $(value(X[1, 4]))")
    return
end

example_corr_sdp()

```

and this is the output I received:

```julia
julia> example_corr_sdp()
An upper bound for X[1, 4] is 0.9999999984486035
A lower bound for X[1, 4] is -0.392820503716742

```

Again the correct upper bound should be around .23. Any thoughts on what I am doing wrong would be very much appreciated. Thank you.

---

<div class="post-metadata">

### Author: ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)
#### Post date: [April 19, 2021, 11:07am UTC](https://discourse.julialang.org/t/bounding-correlation-coefficients-with-jump/59589/2 "2021-04-19T11:07:05Z")

</div>

In this line:

```julia
@constraint(model, X[3, 4] >= -0.4)

```

The `>=` should be `<=`

---

<div class="post-metadata">

### Author: ![phantom](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@phantom](https://discourse.julialang.org/u/phantom)
#### Post date: [April 19, 2021, 7:52pm UTC](https://discourse.julialang.org/t/bounding-correlation-coefficients-with-jump/59589/3 "2021-04-19T19:52:54Z")

</div>

Thank you so much for pointing that out!

With the corrected code i’m getting the following:

```julia
julia> example_corr_sdp()
An upper bound for X[1, 4] is 0.22990770904303592
And X[2, 3] is 0.30474113837332384
A lower bound for X[1, 4] is -0.39281984069804604
And X[2, 3] is 0.32938098165316343

```

The book lists X[2,3] for the upper bound of X[1,4] as .31 as opposed to .30 and Mosek returns .3042. I’m just wondering as a practical rule how many sig figs can we usually go out in terms of accuracy?
