forked from jump-dev/JuMP.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corr_sdp.jl
46 lines (39 loc) · 1.29 KB
/
corr_sdp.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#############################################################################
# JuMP
# An algebraic modelling langauge for Julia
# See http://github.com/JuliaOpt/JuMP.jl
#############################################################################
# corr_sdp.jl
#
# Given three random variables A,B,C and given bounds on two of the three
# correlation coefficients:
# -0.2 <= ρ_AB <= -0.1
# 0.4 <= ρ_BC <= 0.5
# We can use the following property of the correlations:
# [ 1 ρ_AB ρ_AC ]
# [ ρ_AB 1 ρ_BC ] ≽ 0
# [ ρ_AC ρ_BC 1 ]
# To determine bounds on ρ_AC by solving a SDP
#############################################################################
using JuMP
m = Model()
@defVar(m, X[1:3,1:3], SDP)
# Diagonal is 1s
@addConstraint(m, X[1,1] == 1)
@addConstraint(m, X[2,2] == 1)
@addConstraint(m, X[3,3] == 1)
# Bounds on the known correlations
@addConstraint(m, X[1,2] >= -0.2)
@addConstraint(m, X[1,2] <= -0.1)
@addConstraint(m, X[2,3] >= 0.4)
@addConstraint(m, X[2,3] <= 0.5)
# Find upper bound
@setObjective(m, Max, X[1,3])
solve(m)
println("Maximum value is ", getValue(X)[1,3])
@assert +0.8719 <= getValue(X)[1,3] <= +0.8720
# Find lower bound
@setObjective(m, Min, X[1,3])
solve(m)
println("Minimum value is ", getValue(X)[1,3])
@assert -0.9779 >= getValue(X)[1,3] >= -0.9799